执行'emacs --daemon'后为什么emacsclient无法找到套接字

sag*_*han 11 emacs

令人困惑的是,emacsclient表示在执行emacs --daemonbash 后无法找到套接字:

$ ps aux | grep emacs
shiangro         1744   0.0  0.0  2432784    604 s000  S+    1:03??   0:00.00 grep emacs
$ /usr/local/bin/emacs --daemon
("emacs")
Starting Emacs daemon.
Restarting server
$ /usr/local/bin/emacsclient -t
emacsclient: can't find socket; have you started the server?
To start the server in Emacs, type "M-x server-start".
emacsclient: No socket or alternate editor.  Please use:

    --socket-name
    --server-file      (or environment variable EMACS_SERVER_FILE)
    --alternate-editor (or environment variable ALTERNATE_EDITOR)
Run Code Online (Sandbox Code Playgroud)

我的.emacs中有这个设置:

(server-start)
(setq server-socket-dir "~/.emacs.d/server")
Run Code Online (Sandbox Code Playgroud)

它工作,服务器文件~/.emacs.d/server/server就在那里,但emacsclient说它找不到套接字,所以很烦人,我必须使用该-s选项告诉他套接字文件.

我发现这个棘手的问题,我希望让emacs在每次使用crontab的?reboot特殊字符串重启(启动)systerm后作为守护进程运行.

在这种情况下,cron成功启动了emacs服务器并且服务器文件~/.emacs.d/server/server也在那里,但是后来当我启动终端并尝试时emacsclient -t,它失败并抱怨无法找到套接字文件!

虽然我可以通过-s ~/.emacs.d/server/server每次使用emacsclient或者别名emacsclient 来绕过这个问题emacsclient -s ~/.emacs.d/server/server,但这是一种更好的方式来安慰我的心?

背景:

系统:Mac OS X 10.9.2

emacs:由homebrew安装的GNU Emacs 24.3.1

oco*_*odo 12

查找服务器套接字文件是一个棘手的问题,您可以使用lsof它来查找它,然后稍微grep提取套接字路径/文件名.

lsof -c emacs | grep server | grep -E -o '[^[:blank:]]*$'
Run Code Online (Sandbox Code Playgroud)

或OSX,当你希望运行/Application/Emacs你改变命令名字lsof找的是-c Emacs.即.

lsof -c Emacs | grep server | grep -E -o '[^[:blank:]]*$'
Run Code Online (Sandbox Code Playgroud)

您可以使用cut而不是凌乱的过滤grep(搜索非空格直到行结束[^[:blank:]]*$)

lsof -c Emacs | grep server | cut -c70-
Run Code Online (Sandbox Code Playgroud)

更好的是,挤压间隙并使用cut现场切割.

lsof -c Emacs | grep server | tr -s " " | cut -d' ' -f8
Run Code Online (Sandbox Code Playgroud)

既然你有套接字(或它是空的)你可以做一个有条件的启动emacsclient,即.

#!/bin/bash 

socket_file=$(lsof -c Emacs | grep server | tr -s " " | cut -d' ' -f8)

if [[ $socket_file == "" ]]; then        
    # Just run Emacs (with any arguments passed to the script)
    # It would be a good idea to parse the arguments and clean/remove
    # anything emacsclient specific. 
    # (ie. -e should be --eval for emacs)
    # note that emacsclient doesn't fix these args for you either
    # when using -a / --alternate-editor

    emacs $@ &

    # or on OSX

    /Application/Emacs.app/Contents/MacOS/Emacs $@ &

else

    emacsclient $@ -n -s $socket_file

fi
Run Code Online (Sandbox Code Playgroud)


Dia*_*gon 9

既然你做了:

/usr/local/bin/emacs --daemon
Run Code Online (Sandbox Code Playgroud)

服务器已经启动.所以,你实际上并不需要:

(server-start)
(setq server-socket-dir "~/.emacs.d/server")
Run Code Online (Sandbox Code Playgroud)

在你的.emacs中.当您遵循该方法时,服务器将放在/ tmp/emacs502(或者其他一些数字)中.在linux上,emacsclient似乎没有在那里找到它(在那种情况下,我看到/ tmp/emacs1920),所以"emacsclient -nw"工作.我正在使用HomeBrew在OSX上尝试它,就像你一样,我发现我必须连接使用:

emacsclient -nw -s /tmp/emacs502/server
Run Code Online (Sandbox Code Playgroud)

(如果您使用了--deamon = name,那么您将在最后一行使用"name"而不是"server".)

  • 可能的原因是您正在使用无法找到Emacs 24的Mac OS X股票emacsclient(版本22).检查您的$ PATH是否如下所示:`/ usr/bin:/ bin:/ usr/sbin:/ sbin:/ usr/local/bin:`因为要自制的符号链接工作,/ usr/local/bin必须来_before_/usr/bin (9认同)

art*_*can 1

我认为只能在标准路径中emacsclient查找特殊文件,例如在. 如果你改变这个参数,那么你应该通过按键告知它。server/tmp/emacs1000server-socket-diremacsclient-s