3

I usually have 3 or 4 emacs open because I am working at 3 or 4 different projects in different workspaces. Now when I try to open a new file using emacsclient I don't have a control on which emacs it goes to. Usually it goes to the emacs in other workspace. Is there a way to specify which emacs to open it into ?

One way is to restart the server in which I want that file to go but its not the solution I was looking for.

2 Answers 2

5

Burton's solution is on the right track, but is overly complicated because you shouldn't need to futz around with the name of the temp dir. You can just do:

(defun start-named-server (name)
  (let ((server-name name))
    (server-start)))

and then use

emacsclient -s <name> "$@"
3

You can give the server socket file a specific name and then invoke emacsclient to use that socket:

(defun get-tmpdir ()
    (or (getenv "TMPDIR") "/tmp"))

(defun start-named-server (name)
    (let ((server-name (format "%s/emacs-%s" (get-tmpdir) name))
        (server-start))

Now define a shell script 'ec' that will allow you to specify the server name:

emacsclient -s ${TMPDIR-/tmp}/emacs-${1?"usage: ec [emacs server name] ..."} "$@"

So now you can go "ec 1 myfile" after you have run M-: (start-named-server "1") in your emacs, and repeat for all your other emacs' with 2, 3, 4 ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.