Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I keep emacs open all the time I'm working. I have several script that will launch all the apps and files related to a specific project. But, it will launch emacs again, 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?


share|improve this question
up vote 9 down vote accepted

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

share|improve this answer
thanks dood. That's what I need to know. I'm not checking 'right answer' yet, cause I heard that you should always keep it open for a bit to give others a chance to contribute. But I've already put your answer into some scripts. – bev Mar 12 '11 at 17:47
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 '11 at 17:57
In modern Emacs it's just as useful in a terminal; see the -t option. – geekosaur Mar 12 '11 at 17:58
@cjm - actually I do start the server in my .emacs file. I just didn't use it :-) – bev Mar 12 '11 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
share|improve this answer
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 '11 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 – richard Apr 26 '11 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 … "$@"; } – Chris Johnsen May 18 '11 at 5:08
I inadvertently downvoted you when I clicked the down-arrow instead of clicking the number (to view the +/- stats)... Because I didn't notice it soon enough, I can't change it back until the question is modified in some way.. If you make a change and inform me in a follow-up comment, I will add the point on again... (then we can delete the comments)... – Peter.O May 18 '11 at 14:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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