Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use emacs --batch mode in agda-mode setup #5901

Closed
catern opened this issue May 12, 2022 · 9 comments · Fixed by #5908 or #5919
Closed

Use emacs --batch mode in agda-mode setup #5901

catern opened this issue May 12, 2022 · 9 comments · Fixed by #5908 or #5919
Assignees
Labels
agda-mode Issues relating to the Emacs agda2-mode ux: emacs Issues relating to the Emacs agda2-mode ux: installation Getting Agda set up on your machine
Milestone

Comments

@catern
Copy link

catern commented May 12, 2022

agda-mode setup should just run "emacs --batch" and have Emacs write the results of the query to stdout, instead of using a temporary file. Besides greatly simplifying the current askEmacs function, it would also work properly when running "agda-mode setup" without a terminal, which currently doesn't work.

(I would just make this patch myself but I can't figure out how to get agda building inside a Nix development shell)

@andreasabel
Copy link
Member

The relevant code snippet is this:

agda/src/agda-mode/Main.hs

Lines 163 to 177 in 257a324

askEmacs :: String -> IO String
askEmacs query = do
tempDir <- getTemporaryDirectory
bracket (openTempFile tempDir "askEmacs")
(removeFile . fst) $ \(file, h) -> do
hClose h
exit <- rawSystemWithDiagnostics "emacs"
[ "--no-desktop", "-nw", "--no-splash"
-- Andreas, 2014-01-11: ^ try a leaner startup of emacs
-- Andreas, 2018-09-08: -nw instead of --no-window-system as some emacses do not support the long version
, "--eval"
, "(with-temp-file " ++ escape file ++ " "
++ query ++ ")"
, "--kill"
]

Documentation of emacs --batch here: https://www.emacswiki.org/emacs/BatchMode

@andreasabel
Copy link
Member

@catern, how does this work?

$ emacs --batch --eval "(expand-file-name user-init-file)"
Wrong type argument: stringp, nil

Maybe emacs in batch mode does not know about user-init-file?
Bingo!:

$ emacs --batch --eval="(print user-init-file)" 

nil

So, I suppose this does not work... Closing...

@andreasabel andreasabel added status: invalid Not a bug (not in changelog) ux: emacs Issues relating to the Emacs agda2-mode ux: installation Getting Agda set up on your machine labels May 14, 2022
@catern
Copy link
Author

catern commented May 14, 2022

Ah, that's true. If you pass --user='' to set init-file-user to an empty string then Emacs will load the init file normally:

emacs --user='' --batch --eval  '(princ (expand-file-name user-init-file))'

prints /home/catern/.emacs.d/init.el to stdout for me (no newline)

@andreasabel
Copy link
Member

On my system, this prints extra garbage:

$ emacs --user='' --batch --eval '(print (expand-file-name user-init-file))' 2> /dev/null
#[nil "\300C\207"
      [t]
      1]

"/Users/abel/.emacs"

However, what currently is done in agda-mode works correctly:

$ emacs --user='' --batch --eval '(with-temp-file "foo.txt" (insert (expand-file-name user-init-file)))' 2> /dev/null
#[nil "\300C\207"
      [t]
      1]
$ cat foo.txt 
/Users/abel/.emacs

@catern
Copy link
Author

catern commented May 15, 2022

Hm, that's weird, but it's definitely something that it's important to be tolerant of - a user's init file could do anything, including printing random stuff to standard-output. So I guess sticking with the temp-file is best.

It's still good to switch to --batch even though it doesn't simplify the implementation, because it allows agda-mode setup to be run without a terminal - e.g. M-& agda-mode setup inside Emacs, or ssh localhost agda-mode setup, will start working. (Also it avoids the momentary flicker of Emacs starting up)

@andreasabel
Copy link
Member

I switch to --batch in

Please test!

@nad
Copy link
Contributor

nad commented May 24, 2022

Please test!

The new code triggers a warning for me:

Warning (initialization): An error occurred while loading ‘[…]/.emacs’:

My current .emacs does not work properly together with --no-site-file. If we have to run the users' .emacs files, then I don't think we should use --no-site-file. However, the old code did not load .emacs, right?

An alternative might be to ensure that Emacs is run inside a terminal, but I don't know how to do that in a platform-independent way.

@nad nad reopened this May 24, 2022
andreasabel added a commit that referenced this issue May 25, 2022
@nad reports errors with --no-site-file for agda-mode setup.
@andreasabel
Copy link
Member

However, the old code did not load .emacs, right?

Well, I think it did: https://github.com/agda/agda/pull/5908/files#r881547737

But we can of course load the site file. Please test again:

@nad
Copy link
Contributor

nad commented May 25, 2022

I manually ran code similar to what is in your pull request, and that seems to have worked.

andreasabel added a commit that referenced this issue May 27, 2022
@nad reports errors with --no-site-file for agda-mode setup.
marcinjangrzybowski added a commit to marcinjangrzybowski/agda that referenced this issue May 30, 2022
…acs leg.

WIP

[ Makefile ] goal continue-cubical-test;  update cubical submodule

Fix typo in CHANGELOG (agda#5905)

[ workflows ] fix stack/Win (ICU again) (agda#5909)

Stack was updated to MSYS2 2022-05-03 upstream.
This solved the keyring problem, but we need to reset the cache.

Provenance of where modules in Internal syntax.

Qualify some prelude functions in .ghci

Running stack repl failed due to these functions not being in scope

[ debug ] bump some verbosity levels

Fix agda#5901: use --batch when installing agda-mode for emacs

[ doc ] User-manual: installation: add agda to apt-get install

Replaces PR agda#5896 by @RosieBaish, thanks for the contribution.

User-manual: small improvements to section on `postulate` (agda#5916)

* [ doc ] User-manual: trick how to postulate sth in an expression
* [ doc ] remove silly `let open POSTULATE` trick again

[ cubical ] cosmetics: generalize iApplyVars

[ cosmetics ] turn absV (local def) into global def

[ cosmetics ] rewrite some TelView functions

Fixed agda#5920.

Re agda#5924: add LANGUAGE TypeOperators to pacify GHC 9.4

Re agda#5901: setup agda-mode: don't --no-site-file with --user

@nad reports errors with --no-site-file for agda-mode setup.

[ user-manual ] +example repeat for Streams, link copatterns->coinduction

Finish @RemcoSchrijver's PR agda#5918

[ re agda#5923 ] Don't apply rewrite rule instead of generating dummy terms when variables are not bound after matching

whitespacefix

wip

wip

wip
@andreasabel andreasabel added this to the 2.6.3 milestone Oct 24, 2022
@asr asr changed the title Use emacs --batch mode in agda-mode setup Use emacs --batch mode in agda-mode setup Jan 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agda-mode Issues relating to the Emacs agda2-mode ux: emacs Issues relating to the Emacs agda2-mode ux: installation Getting Agda set up on your machine
Projects
None yet
3 participants