I’ve just switched whole hog to ElementaryOS. So now I’m exploring new improvements in some of my ancient setups. For example, emacs. I’ve been using emacs for probably 20+ years. I’ve been using the exact same emacs setup for 5-10 years. Needless to say, I think its likely there are some improvements that are possible. And this wil also apply to other GNOME and GTK environments, I’m sure.
Since I use it a lot, it is worth running it in “daemon” mode, which means that emacs is always running in the background, and running an emacs
command really just means connecting to the daemon that is already running. I’ve never found a way to set that up to make it seamless or without silly shell script hacks. I don’t want to remember to type emacsclient
with all sorts of various options. I want to just type emacs
. And I want to launch emacs
in the standard GUI ways and have that work also.
Here’s how I did it. First, setup up the .desktop files to autostart Emacs daemon and configure the GUI stuff to use emacsclient
:
~/.config/autostart/emacs24-daemon.desktop
[Desktop Entry] Version=1.0 Name=GNU Emacs 24 Daemon GenericName=Text Editor Comment=View and edit files MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++; Exec=/usr/bin/env XLIB_SKIP_ARGB_VISUALS=1 emacs24 --daemon TryExec=emacs24 Icon=/usr/share/icons/hicolor/scalable/apps/emacs24.svg Type=Application Terminal=false Categories=Utility;Development;TextEditor; StartupWMClass=Emacs24 X-GNOME-Autostart-enabled=true
~/.local/share/applications/emacs24.desktop
[Desktop Entry] Version=1.0 Name=GNU Emacsclient 24 GenericName=Text Editor Comment=View and edit files MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++; Exec=/usr/bin/emacsclient --create-frame --alternate-editor "" %F TryExec=emacs24 Icon=/usr/share/icons/hicolor/scalable/apps/emacs24.svg Type=Application Terminal=false Categories=Utility;Development;TextEditor; StartupWMClass=Emacs24
Next up, set up the emacs command in the terminal to also plug into this:
update-alternatives --install /usr/bin/editor editor /usr/bin/emacsclient 50 update-alternatives --install /usr/bin/emacs emacs /usr/bin/emacsclient 50
That’s pretty much it. You might want to set some vars in your .bashrc
, but I think that’s optional:
export ALTERNATE_EDITOR="" # $EDITOR should open in terminal export EDITOR="emacsclient -t" # $VISUAL opens in GUI with non-daemon as alternate export VISUAL="emacsclient -c -a emacs"