Add new emacs-gui-server and emacs-gui-client commands

The idea behind these commands is to easily launch a Emacs server which
runs in the background, but with font/theme/etc settings as if it was
launched like a normal GUI.

I used to just launch Emacs.app directly, but, now I use these binaries
to open a full GUI frame by executing `emacs-gui-client -c &`. After
starting the GUI server with `emacs-gui-server start` of course.

The main difference between calling `emacs --daemon` and
`emacs-gui-server start` is that the latter uses a custom socket as to
not interfere with any console-base Emacs server, and it also sets the
`EMACS_GUI_SERVER` environment variable to `1`, letting my Emacs config
figure out which theme/fonts/etc to load.
This commit is contained in:
2013-02-18 01:02:56 +00:00
parent d568031579
commit 89fa2342d3
2 changed files with 73 additions and 0 deletions

15
bin/emacs-gui-client Executable file
View File

@@ -0,0 +1,15 @@
#! /bin/bash
# Defaults
SOCKET_DIR="$TMPDIR/emacs-gui-server$(id -u)"
SOCKET_FILE="$SOCKET_DIR/server"
EMACSCLIENT="emacsclient"
ALTERNATE_EDITOR="nano"
# Set to binary bundled in Emacs.app if it exists
if [ -f "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient" ]; then
EMACSCLIENT="/Applications/Emacs.app/Contents/MacOS/bin/emacsclient"
fi
# Execute emacsclient
exec $EMACSCLIENT -s "$SOCKET_FILE" --alternate-editor=$ALTERNATE_EDITOR "$@"

58
bin/emacs-gui-server Executable file
View File

@@ -0,0 +1,58 @@
#! /bin/bash
# Config
SOCKET_DIR="$TMPDIR/emacs-gui-server$(id -u)"
SOCKET_FILE="$SOCKET_DIR/server"
EMACS="emacs -nw"
EMACSCLIENT="emacsclient"
# Set to binaries bundled in Emacs.app if they exists
if [ -f "/Applications/Emacs.app/Contents/MacOS/Emacs" ]; then
EMACS="/Applications/Emacs.app/Contents/MacOS/Emacs -nw"
fi
if [ -f "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient" ]; then
EMACSCLIENT="/Applications/Emacs.app/Contents/MacOS/bin/emacsclient"
fi
# Functions
start () {
EMACS_GUI_SERVER=1 env $EMACS \
--eval "(setq server-socket-dir \"$SOCKET_DIR\")" --daemon
}
stop () {
env $EMACSCLIENT -s "$SOCKET_FILE" --eval "(kill-emacs)"
}
status () {
echo -n 'Emacs GUI Server... '
! result=`eval $EMACSCLIENT -s "$SOCKET_FILE" --eval \"\(print \'OK\)\" 2>/dev/null`
if [[ $result == "OK" ]]; then
echo 'RUNNING'
else
echo 'STOPPED'
fi
}
# Command Parsing
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
*)
echo 'usage: emacs-gui-server [command]'
echo ''
echo 'Available commands:'
echo ' start: Start Emacs GUI Server.'
echo ' stop: Stop Emacs GUI Server.'
echo ' status: Show status of Emacs GUI Server.'
;;
esac