Super User is a question and answer site for computer enthusiasts and power users. 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

How to open a file from command line and have it shown in one of the existing windows in the existing frame, otherwise in a new window in a new frame? The default behavior is it is opened in a new frame. I'm using

GNU Emacs 23.4.1 (x86_64-apple-darwin10.8.0) of 2012-01-29 on

Edit 1

I didn't pay enough attention to my aliases definition. I'm using

alias emacs=open -a /Applications/Macports/

in my .bashrc. With this setting, if there is an existing Emacs frame I opened earlier, when a new emacs is run from command line ($ emacs foobar.txt), it opens a new frame, and even loads .emacs for it, and then displays the file in one of the windows of the new frame. (My .emacs setting automatically split the frame into two windows.)

share|improve this question
up vote 2 down vote accepted

You don't specify exactly how you're opening a file from the command line, but the default behavior for emacsclient is in fact the opposite: it re-uses a frame. From the emacsclient documentation at, the -c option is used to get the behavior you seem to have by default.

-c Create a new graphical frame, instead of using an existing Emacs frame. Emacs 23 can create a graphical frame even if it was started in a text-only terminal, provided it is able to connect to a graphical display. If no graphical display is available, Emacs creates a new text-only terminal frame (see Frames). If you omit a filename argument while supplying the ‘-c’ option, the new frame displays the ‘scratch’ buffer (see Buffers).

I can confirm that's how it works on my system, which is few revs behind: GNU Emacs 23.2.1 (x86_64-apple-darwin, NS apple-appkit-1038.29) of 2010-05-08 on black.local"

I'd check to make sure you're using the emacsclient that shipped with your emacs, and that you aren't inadvertently sending -c.

share|improve this answer
It turns out I aliased emacs with alias emacs=open -a /Applications/Macports/ But still, if there is an existing Emacs frame, when a new emacs is run from command line, it opens a new frame, and even loads .emacs with it. – Computist Apr 25 '12 at 17:33
@Computist, in fact, when you use that alias. You start a new Emacs, it does not open a new frame in the running Emacs. I would recommend using "emacsclient". – Lindydancer Apr 26 '12 at 8:49
@Lindydancer, do you have more specific suggestion as to how my alias might be modified to use emacsclient? – Computist Apr 26 '12 at 15:29

I use this:

emacs() {
/Applications/MacPorts/ --alternate-editor=/Applications/MacPorts/ $1 &

It uses emacsclient to open the file you specified - if it doesn't find an existing Emacs server, it opens a new one.

In .emacs, do


so that starting emacs also starts a server.

share|improve this answer

You must log in to answer this question.

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