2

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?

2 Answers 2

4

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.

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

5
  • The problem with this is that I was intending the command-line options ($@) to go to emacs. With this approach, they go to open. Nov 21, 2009 at 18:00
  • Scratch that. Apparently this does work if you invoke emacs like this: open -a /Applications/Emacs.app/Contents/MacOS/Emacs --args $@ Nov 21, 2009 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. Nov 21, 2009 at 19:43
  • Hey Jason...did you figure out any way to get this to work without using the open command? Sep 19, 2011 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. Sep 19, 2011 at 21:06

You must log in to answer this question.

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