Location of emacs socket

3.7k views Asked by At

I use emacs on a remote server. Since my sessions usually involve dozens of files and processes, I've been using the emacs server and connecting to it with the emacs client. That has the advantage that, if my ssh connection is interrupted for whatever reason (which happens very often since I'm in England and the server's in California), I simply connect to the emacs server again and continue working like nothing has happened.

However, some time ago, the administrators of the server have changed its configuration so that "unused" files get regularly purged from the /tmp directory, which is where the emacs socket is by default. Since the time stamp doesn't get updated after its initial creation, the purging process assumes that it's an unused file, which means that I can't connect to my server any more although it's running.

Does somebody know of a way to tell emacs to create the socket in a directory other than the default?

By the way, I also tried using a script that renews the socket's time stamp regularly, but it's still being deleted.

Thanks in advance.

2

There are 2 answers

1
AudioBubble On

It seems that server-socket-dir and server-auth-dir are the variables you are looking for, from the documentation C-hvserver-socket-dirRET

The directory in which to place the server socket. If local sockets are not supported, this is nil.

C-hvserver-auth-dirRET

Directory for server authentication files. We only use this if server-use-tcp' is non-nil. Otherwise we useserver-socket-dir'.

2
ACz On

I finally found out myself, so sharing with everybody. Works with TCP and unix sockets.

ATMP="${HOME}/.tmp"     # alternative tmp directory, choose any directory you like
mkdir $ATMP
env TMPDIR=${ATMP} emacs --daemon=$SOCKETNAME   # start the daemon; SOCKETNAME can be anything
emacsclient -s ${ATMP}/$SOCKETNAME $OTHER_ARGS  # start the client