Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
add comment

3 Answers 3

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

share|improve this answer
    
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 '12 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". –  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
add comment

The display-buffer-alist can be used control how file and non-file buffers are displayed, along with the function that is activated when opening a file from an external source. Please see the following detailed example of how this could work:

http://stackoverflow.com/questions/18346785/how-to-intercept-a-file-before-it-opens-and-decide-which-frame

share|improve this answer
add comment

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

(server-start) 

so that starting emacs also starts a server.

share|improve this answer
add comment

Your Answer

 
discard

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.