I have several script that will launch all the apps and files related to a specific project. But, it will launch multiple emacs instances, rather than simply cause the current emacs to open the requested files. I'd rather the current emacs simply opened the project text files in a new buffer.

Any ideas how I can do that?


2 Answers 2


M-x server-start inside the Emacs session, then use emacsclient -n file1 file2 ... to add files to the existing Emacs. There are additional options you might want to use, e.g. -c to open the files in a new window (frame).

  • Normally, you'd want to put (server-start) in your .emacs file, rather than starting the server manually. I use (and window-system (server-start)) to avoid starting the server if I'm running emacs in a terminal.
    – cjm
    Mar 12, 2011 at 17:57
  • In modern Emacs it's just as useful in a terminal; see the -t option.
    – geekosaur
    Mar 12, 2011 at 17:58
  • @cjm - actually I do start the server in my .emacs file. I just didn't use it :-)
    – bev
    Mar 12, 2011 at 18:52

Put (server-start) in your .emacs file.

Add this to ~/.bashrc

alias myedit='emacsclient --alternate-editor="" --no-wait $*' #quotes intentionaly left blank

then use myedit as your editor. You will have to use the -c option to bring up a window.

So you may do this:

myedit -c a-file
run-script #that uses myedit


run-script #that uses myedit
myedit -c
  • Richard, thanks for the input. I'm still puzzling out a few things with your script. First, since emacsclient doesn't have a -c option, I'm assuming that it's a bash thing, but don't know. Second, why not put emacs as the alternate editor? Thanks
    – bev
    Apr 6, 2011 at 19:57
  • #$ emacsclient --help .... The following OPTIONS are accepted: ... -c, --create-frame Create a new frame instead of trying to use the current Emacs frame ... -a EDITOR, --alternate-editor=EDITOR Editor to fallback to if the server is not running If EDITOR is the empty string, start Emacs in daemon mode and try connecting again Apr 26, 2011 at 10:13
  • You do not need (and, in fact, probably do not want) to use positional parameters in the definition of an alias. Consider how alias foo='echo bar $*' expands in set quux; foo baz. If you want to use the positional parameters, try it as a shell function: myedit() { emacsclient … "$@"; } May 18, 2011 at 5:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .