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

Does anyone know any tricks for launching emacs with GUI on OS X with the standard command emacs?

I'm a ten year Linux user and thought I would buy a Mac for a while to stay diverse. I can open files via emacs now with open file.txt, but that wont allow me to use debugging mode.

share|improve this question
Have you tried open -a ProgramName --args program_arguments or /Applications/ProgramName/Contents/MacOS/binary_name program_arguments? – Daniel Beck Aug 1 '11 at 14:57
Yah, I tried that originally but I want the simplicity of launching it with just plain old, 'emacs.' Thanks anyway. – trentonknight Aug 1 '11 at 15:03
Besides the already mentioned alias I would recommend using Aquamacs instead of the standard emacs because it is already optimised for an OS X environment. – eFrane Aug 1 '11 at 15:47

You could create an alias such as:
alias emacs = "open -a ProgramName"

share|improve this answer
Yup, put it in my bash_profile: emacs='open -a /Applications/ "$@"' – trentonknight Aug 3 '11 at 16:18
If it works, please accept the answer. – Yitzchak Aug 3 '11 at 17:21

If the following is within your realm of expertise it may be worth doing:

  1. Create a directory under /Users/Fred, for instance, /Users/Fred/bin where you store your own executable programs.

  2. Ensure that MacOS knows about your executable directory at login by editing the settings in ~/.MacOS/environment.plist .

  3. Create a file called ~/bin/emacs . In it put the lines

    exec /Applications/ $* 
  4. Ensure that the file has execute permission: chmod a+x ~/bin/emacs

  5. Depending on your success with 2 (and whether or not you have logged out and in) you should be able to execute emacs with either just emacs or [worst case] with ~/bin/emacs

  6. The advantage of this approach over using open is that you can now use command lines like sudo emacs --user Fred /etc/something-owned-by-root. The --user Fred being useful if you have heavily customized emacs.

share|improve this answer
Does it make sense to add a test whether there's an emacs-server running (as per @DougHarris) and if so, then use it to visit the file. And otherwise, start a new session of emacs? – Dror Jan 24 '13 at 7:36
How do I prevent this from launching a second instance of GUI Emacs if one is already open? – incandescentman Jul 18 '15 at 22:32

Are you using bash? With this bash function definition in your .bashrc (or whatever file you source your bash aliases from), 'emacs <stuff more stuff>' will do what you expect, including leaving your terminal back at the prompt immediately after launching emacs.

emacs() { /Applications/ "$@" & }
share|improve this answer
Outstanding! I will try that! Thank You. – trentonknight Aug 3 '11 at 15:59
I made a few changes but your answer was on point. This is what I have in my .bash_profile on Lion: alias emacs='open -a /Applications/ "$@"' – trentonknight Aug 3 '11 at 16:15

Have you tried Aquamacs? It has command-line kit, and then you can use it from the command line.

share|improve this answer
I tried it and its nice but its almost not emacs anymore itsso customized. It kinda takes all the fun of being miserable and manually adding all my el files. Also it rejected my .emacs file completely. I sure there is a work around but why bother when I want a purer version of emacs anyway. Thanks. – trentonknight Aug 3 '11 at 16:01
  1. Launch Emacs after each reboot. Never quit. (Only reboot your computer when you an OS update forces a reboot).
  2. Make sure that you start Emacs server when Emacs launches by putting (server-start) in your .emacs file.
  3. Use the command line utility emacsclient -n to open files in Emacs.

Optional step 4 - create an alias to make it shorter:

alias em='emacsclient -n'
share|improve this answer

You must log in to answer this question.

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