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 beta.macosforge.org

Edit 1

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

alias emacs=open -a /Applications/Macports/Emacs.app

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

2 Answers 2


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 gnu.org, 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.

  • It turns out I aliased emacs with alias emacs=open -a /Applications/Macports/Emacs.app. 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, 2012 at 17:33
  • 1
    @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". Apr 26, 2012 at 8:49
  • @Lindydancer, do you have more specific suggestion as to how my alias might be modified to use emacsclient?
    – Computist
    Apr 26, 2012 at 15:29

I use this:

emacs() {
/Applications/MacPorts/Emacs.app/Contents/MacOS/bin/emacsclient --alternate-editor=/Applications/MacPorts/Emacs.app/Contents/MacOS/Emacs $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.

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.