You are not logged in.
I have Emacs setup to start as system unit and a alias for "emacsclient": alias emacs="emacsclient -nc -a 'helix'". In the Wiki, it says:
If you start emacs as a daemon, you may want to set the VISUAL and EDITOR environment variables to emacsclient so that programs that start an editor use emacsclient instead of starting a new full instance of the editor. Programs that use an external editor include email programs (for editing the message), Git (for editing the commit message), and less (the v command for editing the displayed file). Do not use the -n (--nowait) option to emacsclient, since programs typically expect editing to be finished when the editor exits.
The wording confuses me a little bit (I'm not a native speaker). I shouldn't use "--nowait" if my terminal "expects" the editing to be finished? Or when I launch "emacs" from within another text editor, e.g. Neovim?
I usually have my editors launched and then detach from my terminal, for instance: I can launch VSCodium with "vscodium" binary/command and it opens its window without hogging my terminal. I like this behaviour, I would like to keep it. What are the risks of this?
This is my unit (copied from https://www.emacswiki.org/emacs/EmacsAsDaemon):
[Unit]
Description=Emacs text editor
Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/
[Service]
Type=forking
ExecStart=/usr/bin/emacs --daemon
ExecStop=/usr/bin/emacsclient --eval "(kill-emacs)"
Environment=SSH_AUTH_SOCK=%t/keyring/ssh
Restart=on-failure
Environment="PATH=/usr/lib/ccache/bin:/usr/local/bin:/usr/bin:/bin"
Environment="EDITOR=nano -c"
Environment="BROWSER=firefox"
Environment="NO_AT_BRIDGE=1"
[Install]
WantedBy=default.target
Thank you for your help.
Offline
https://man.archlinux.org/man/extra/ema … ent.1.en#n,
-n, --no-wait
Return immediately without waiting for you to "finish" the buffer in Emacs. If combined with --eval, this option is ignored.
If $SCRIPT does something like
$EDITOR foo.txt
cp foo.txt bar.txt
this would utterly fail if you're essentially always forking the editor.
What do you mean by "hogging the terminal" and how exactly does that related to starting emacs as user service and why in gods name do you have "Environment="EDITOR=nano -c"" in there???
If you want to run emacs (or pretty much anything that doesn't require a tty) from a terminal and then continue to use the terminal you can just fork it
emacs & disown
The "&" forks emacs (you return to your shell) and the "disown" on top will detach it from the parenting shell - so whatever happens to the shell (or terminal window) won't affect emacs (eg. if you close it)
You can also
emacs > /dev/null 2>&1 & disown
to make sure not of its output makes it to the terminal window ever.
Then alias that or whatever (but be weary about the $EDITOR resolution because of the forementioned problem)
Online
Thank you, that clear things up.
What do you mean by "hogging the terminal"
https://wiki.archlinux.org/title/Emacs
(...) and does not hog the terminal -n (--no-wait)...
So, no:
$ emacsclient -c
Waiting for Emacs...
why in gods name do you have "Environment="EDITOR=nano -c"" in there???
It's actually removed from my unit file, I just copied the example from Emacs page into mine so I could make a quick setup. I've just began learning Emacs.
Cheers.
Offline
Ok, that's a casual way to put it. The emacswiki seems localized and it's at least not in the german version.
So, no:
$ emacsclient -c
Waiting for Emacs...
suggests that the emacs daemon isn't running at this point?
Did you start/enable the user unit?
Online