A nifty feature in the current development version of Emacs (now available in a pretest release candidate) is that you can start it as a daemon, to which graphical and terminal clients alike can attach. A not so nifty lack of feature is there being no easy standard way to do the obvious: launch a client if the daemon’s running; if it’s not, start the daemon, and then launch the client. So everyone cobbles together their own. Here’s mine, which cribs from here.
if [ -z $DISPLAY ] ; then
if [ -z “$*” ]; then
OPT=“$OPT -e (raise-frame)”
emacsclient $OPT 2>/dev/null || (
I have that as /usr/local/bin/editor. To stop emacs nicely, and get prompted to save unfinished business, I have another script with:
/usr/local/bin/editor -e ‘(save-buffers-kill-emacs)’