当Emacs以守护进程模式启动时,如何在通过X11或终端连接时自动加载正确的初始化设置?

7
我最近开始在启动时以守护进程模式运行emacs。通过GUI客户端(Emacs.app)连接似乎能正确加载自定义设置。但是,通过终端连接emacsclient却不行。
第一个症状出现在尝试在终端中使用M-x customize-variable时,会产生以下消息:

Cannot save customizations: init file was not fully loaded

这可能与emacs --daemon忽略所有与X11相关的选项根据此处有关。虽然在我的情况下看起来,emacsclient没有加载后续选项。
在研究问题和可能的解决方案后,我无法确定处理此问题的绝对可靠的方法。我看到了建议创建不同的init文件和相应的bash别名,每次想要在终端中打开emacs缓冲区时将其传递给emacsclient --eval。我也看到其他人在主init文件中使用if-else语句来处理与X11相关的选项。但在走向任何一条路之前,我想知道是否有一种标准的处理方法,我是否遗漏了什么(或者我只是在某个地方犯了错误)。
非常感谢您提供的建议、批评和技巧。
编辑添加:
* GNU Emacs 24.3.1
* emacsclient 24.3
* 在OS X 10.9上都使用homebrew安装
这是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>

这里是点文件配置:
# 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=""  

有时我也喜欢在tmux内启动emacs:
# 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"

Emacs的哪个版本?OSX用户通常运行相当旧的版本。在当前版本中是否仍然发生这种情况? - phils
@phils,我正在运行24.3版本,在OS X 10.9上使用homebrew安装。 - d3vin
1个回答

1
emacsclient 不会读取任何初始化文件的部分内容。也就是说,在您的使用情况下,您需要设置初始化文件以涵盖 所有 使用情况(包括文本终端和 GUI 窗口),因为您可以同时拥有几种不同类型的窗口。

Cannot save customizations: init file was not fully loaded 消息表示在加载 ~/.emacs 时发生了错误,请检查 *Messages* 的内容以查看错误并尝试修复它。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接