Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why emacsclient can't find socket after executing 'emacs --daemon'

Tags:

emacs

It is so confusing that emacsclient said it can't find socket just after executing emacs --daemon in bash:

$ 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)

I have this settings in my .emacs:

(server-start)
(setq server-socket-dir "~/.emacs.d/server")

and it works,the server file ~/.emacs.d/server/server was just there,but emacsclient say it can't find socket,so annoying that I have to tell him the socket file using the -s option.

I find this thorny problem while I want let emacs runing as a daemon after everytime rebooting(start) systerm by using crontab's ◎reboot special strings.

In this case ,cron successfully started the emacs server and the server file ~/.emacs.d/server/server was also there, but later when I started a terminal and tried to emacsclient -t ,it failed and complained can't find socket file!

Although I can bypass this problem by using -s ~/.emacs.d/server/server everytime I excute emacsclient,or alias emacsclient as emacsclient -s ~/.emacs.d/server/server ,but is ther a better way to comfort my heart?

Backgroud:

system: Mac OS X 10.9.2

emacs: GNU Emacs 24.3.1 installed by homebrew

like image 903
sage han Avatar asked Apr 18 '14 06:04

sage han


People also ask

How do I run Emacs as daemon?

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.

How do I use Emacsclient?

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).

How do I know if my Emacs server is running?

The server-running-p predicate will evaluate to t if the Emacs server is running, irrespective of which Emacs session currently "owns" the server process.


1 Answers

Since you've done:

/usr/local/bin/emacs --daemon

the server is already started. So, you don't actually need the:

(server-start)
(setq server-socket-dir "~/.emacs.d/server")

in your .emacs. When you follow that approach, the server is placed in /tmp/emacs502 (or maybe some other number). On linux, emacsclient doesn't seem to have trouble finding it there (in that case I'm seeing /tmp/emacs1920), and so "emacsclient -nw" works. I'm trying it on OSX using HomeBrew, as you are, and I find I have to connect using:

emacsclient -nw -s /tmp/emacs502/server

(If you used --deamon=name, then you would use "name" instead of "server" in that last line.)

like image 96
Diagon Avatar answered Oct 14 '22 20:10

Diagon