Set VISUAL
to emacsclient -c
(or some other variation without -n
).
The option -n
causes emacsclient
to return as soon as it's contacted the running Emacs instance to tell it to edit the file. The program calling the editor (here, zsh, but this applies equally to any other program that invokes $VISUAL
) knows that you've finished editing because the program that it invoked has exited, which, with -n
, happens essentially immediately.
You need to arrange for the program invoked through VISUAL
to exit when you've finished editing, i.e. when you close the buffer in Emacs. That's exactly what emacsclient
without -n
does: it contacts the running Emacs instance to tell it to open the file, then sits around until Emacs replies to tell emacsclient that the editing session is finished. The normal way to finish an editing session is to press C-x #
(server-edit
). This notifies emacsclient and closes the buffer, as well as the frame when it was opened by emacsclient -c
. Closing the buffer also notifies the emacsclient process that the session is finished, but you get a warning prompt (“Buffer … still has clients, kill it?”), which you can disable by overriding the function server-kill-buffer-query-function
(RMS thinks it's dangerous). In a frame opened by emacsclient -c
, pressing C-x C-c
(save-buffers-kill-terminal
) saves the file, closes it and closes the frame.
-n
will also prevent emacsclient from working as an editor for git. – cg433n Jul 08 '15 at 22:07-n
flag have? – Squidly Jul 09 '15 at 09:45emacs myfile &
(or the Windows equivalent), putting the Emacs process in the brackground. With emacsclient, I could runemacsclient myfile &
, but that leaves anemacsclient
process whose sole job is to wait, then exit. Instead I runemacsclient -n myfile
, so the emacsclient process goes away by itself. This is so common I have a shell alias for it:alias e='emacsclient -n'
– Gilles 'SO- stop being evil' Jul 09 '15 at 10:04emacsclient
in the terminal, which is why I couldn't see the point of-n
. Thanks – Squidly Jul 09 '15 at 12:06