0

Is there a way to get the emacs shell command (the UNIX utility) to start an emacs process, if none exists, but if one does, switch to it?

More specifically, is there a way to get the command emacs file1 file2 visit file1 and file2 in the existing emacs process, if one already exists?

BTW, I'm not sure how to tag this.

2

First you should run (server-start) within emacs. This can be put in your init file.

The command you are looking for is emacsclient --no-wait --alternate-editor=emacs. You can put this behind an alias if you want. This will open the files on the existing server and frame if there is one, and will otherwise run emacs as usual. The --no-wait is optional and prevents the command from blocking the terminal.

  • 1
    The equivalent short options are emacsclient -n -a emacs. You can also use an empty string for the fallback editor arg to "start Emacs in daemon mode and try connecting again". emacsclient -n -a '' – phils Mar 2 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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