Last active
December 29, 2021 16:15
-
-
Save ca7023/513f9d0333f03592576338f90bc2f898 to your computer and use it in GitHub Desktop.
Run Emacs.app as Client/Server, for someone who likes GUI emacs and emacsclient to speed up start-up time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
BG_RED=`tput setaf 1` | |
BG_GREEN=`tput setaf 2` | |
BOLD=`tput bold` | |
RESET=`tput sgr0` | |
EMACS='/Applications/Emacs.app' | |
EMACS_CLIENT='/Applications/Emacs.app/Contents/MacOS/bin/emacsclient' | |
DEFAULT_EVAL='(switch-to-buffer "*scratch*")' | |
DEFAULT_ARGS="-e" | |
NO_WAIT='-n' | |
function run_client(){ | |
if [ $# -ne 0 ] | |
then | |
${EMACS_CLIENT} ${NO_WAIT} $@ | |
else | |
${EMACS_CLIENT} ${NO_WAIT} ${DEFAULT_ARGS} "${DEFAULT_EVAL}" &> /dev/null | |
fi | |
} | |
echo -e "Checking Emacs server status...\c" | |
if pgrep Emacs &> /dev/null | |
then | |
echo "${BOLD}${BG_GREEN}Active${RESET}" | |
echo -e "Connecting...\c" | |
run_client $* | |
echo "${BOLD}${BG_GREEN}DONE${RESET}" | |
else | |
echo "${BOLD}${BG_RED}Inactive${RESET}" | |
echo -e "Emacs server is starting...\c" | |
open -a ${EMACS} | |
echo "${BOLD}${BG_GREEN}DONE${RESET}" | |
echo -e "Trying connecting...\c" | |
until run_client $* &> /dev/null;[ $? -eq 0 ] | |
do | |
sleep 1 | |
done | |
echo "${BOLD}${BG_GREEN}DONE${RESET}" | |
fi |
Thank you, ChillingHsu. This works with the MacPort build by YAMAMOTO Mitsuharu by changing the path of emacsclient to where it is. But there are some issues.
- Closing the windows of emacs closes the server by C-x C-c. Is it possible to leave the daemon running in the background?
- Is it possible to let GUI emacs connect to existing emacs daemon?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@SolidStill sorry for my late reply, according to your spacemacs given, it seems that you did not start emacs server successfully. I have not used spacemacs so I'm not very sure whether the
(server-start)
can successfully boot up your emacs server. And you can tryemacs -Q
and runserver-start
manually byM-x
, and run the script again to make sure it work properly on your emacs. If it does, the question should come from your spacemacs.