I recently began running emacs in daemon mode on startup. Connecting via GUI client (Emacs.app) appears to load customizations correctly. However, connecting via emacsclient
in Terminal does not.
The first symptom appeared after trying to M-x customize-variable
in Terminal which produced the following message:
Cannot save customizations: init file was not fully loaded
This may have something to do with emacs --daemon
ignoring all X11-related options according to this. Though it would appear in my case that instead of ignoring the X11-related options emacsclient fails to load subsequent options.
After researching the problem and possible solutions I've been unable to determine a bulletproof method for dealing with this. I've seen suggestions to create a different init file and corresponding bash alias that passes it to emacsclient --eval
each time one wants to open an emacs buffer in Terminal. And I've seen others who use if-else statements in their main init file to deal with X11-related options. But before going down one path or another I'm wondering if there's a canonical way of dealing with this that I've somehow overlooked (or if I've simply made a mistake somewhere).
Advice, criticism, tips would be much appreciated.
Edit to add:
* GNU Emacs 24.3.1
* emacsclient 24.3
* both installed with homebrew on OS X 10.9
Here is the LaunchAgent:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>emacsdaemon</string>
<key>ProgramArguments</key>
<array>
<string>/opt/boxen/homebrew/bin/emacs</string>
<string>--daemon</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>ServiceDescription</key>
<string>Emacs Daemon</string>
<key>UserName</key>
<string>my_name</string>
</dict>
</plist>
Here are the dotfile configs:
# relevant lines of .zshrc:
alias emacs="/opt/boxen/homebrew/bin/emacsclient -nw"
# set emacsclient as default editor
export EDITOR="emacsclient"
# use only emacscilent
export ALTERNATE_EDITOR=""
Sometimes I also like to launch emacs from within tmux:
# relevant lines of .tmux.conf:
# open emacs inside of tmux in a new window
# hat tip: http://perlstalker.vuser.org/blog/2012/10/16/emacsclient-and-tmux/
bind-key y new-window -n "emacs" "/opt/boxen/homebrew/bin/emacsclient -nw"
One easy way to start the Emacs daemon is via “Settings > Session and Startup > Application Autostart”. You can also place an init script to place in /etc/init. d/emacsd.
[While you wait for a real answer] Something like: emacsclient -e "(kill-emacs)" will do it. (You might want save-buffers-kill-emacs instead; that asks for confirmation first.)
The simplest way to use the emacsclient program is to run the shell command ' emacsclient file ', where file is a file name. This connects to an Emacs server, and tells that Emacs process to visit file in one of its existing frames—either a graphical frame, or one in a text terminal (see Frames and Graphical Displays).
emacsclient
does not cause any part of the init file from being read. I.e. in your use case, you need to setup your init file such that it covers all use cases (both for text-terminals and for GUI frames) since you can have several of the different kinds at the same time anyway.
The Cannot save customizations: init file was not fully loaded
message indicates that an error was signaled while loading ~/.emacs
, so go check the contents of *Messages*
to see what the error was and try to fix it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With