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.

I wrote a little zsh function to allow me to run emacs from the command-line:

function emacs() {
    /Applications/Emacs.app/Contents/MacOS/Emacs $@ &
}

This works perfectly, but it seems to start emacs as the last window in my Cmd-tab list. Is there any way to make it take focus when it's started?

share|improve this question

2 Answers 2

The emacs way to open files into emacs is to use emacsclient from the command line. This requires that emacs is running the emacs server (using M-x server-start or put (server-start) into your .emacs file).

I've got this in my .bashrc (adapt for zsh as appropriate):

alias em='emacsclient -n'

I'm running GNU Emacs 23.1.50.5 (built from CVS last week sometime) and this version brings my emacs window to front.

If you're opening and exiting emacs for each file you edit, you're not taking full advantage of emacs' possibilities. I typically start emacs shortly after a reboot and it stays open until the next Mac software update requires a reboot.

share|improve this answer
open -a Emacs.app foo.txt

This will open the file "foo.txt" in Emacs.app. If you want to send command arguments to Emacs, use the args switch.

share|improve this answer
    
The problem with this is that I was intending the command-line options ($@) to go to emacs. With this approach, they go to open. –  Jason Baker Nov 21 '09 at 18:00
    
Scratch that. Apparently this does work if you invoke emacs like this: open -a /Applications/Emacs.app/Contents/MacOS/Emacs --args $@ –  Jason Baker Nov 21 '09 at 18:01
    
I thought the arguments were files you intended to open with the One True Editor. If not, then yes, you need the '--args' switch. –  Richard Hoskins Nov 21 '09 at 19:43
    
Hey Jason...did you figure out any way to get this to work without using the open command? –  Das Sep 19 '11 at 21:04
    
Actually nevermind. I think I can live with using that open command even though I think it is lame and reminiscent of kindergarten. –  Das Sep 19 '11 at 21:06

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.