views:

81

answers:

4

I am a new iMac user. I have extensive experience with Linux on a PC. I downloaded latest version of emacs to the Applications folder. I want to invoke emacs from the command line. However, the default path for emacs is /usr/bin/emacs. what is the best practice for adding the new emacs to the path? I am tempted to create a ~/bin directory and a link to the new emacs and adding ~/bin to the beginning of my path. This is how we did things in our software development environment on linux PC's

A: 

That will work. If this is a native mac application, the binary is actually located under the application directory (not the capitalization of the binary): .../Emacs.app/Contents/MacOS/Emacs

Since you are coming from linux, you might be interested in MacPorts. This is a large collection of packages ported from linux. It allows packages to be installed and upgraded from the command line, doe sdependancy management, all the stuff you would expect. It includes a native version of Emacs, that can be invoked from the command line.

KeithB
+1  A: 

Assuming you were still in linux land, wouldn't the canonical place to put this be in /usr/local/bin (and add that to your path?) ... I'd stick with that, if you were to go that route, but this is how I have my emacs setup:

  1. I've downloaded the latest plain/vanilla Emacs from emacsforosx.com
  2. I've made an emacs alias that I use to fire up a terminal-based version of emacs when I don't want (or can't) run the GUI version, like so:

    alias emacs='/Applications/Emacs.app/Contents/MacOS/Emacs -nw'

  3. If you want to fire up the GUI version of Emacs from the terminal, you can just type the following (which, AFAIK, is a mac-ism, so you wouldn't have known that coming from linux):

    $ open -a Emacs

Steve Lianoglou
+2  A: 

There's a slew of information about emacs on OS X at the emacs wiki.

~/bin or /usr/local/bin will work fine, as will manipulating your PATH.

Assuming you're using Emacs.app, simplest thing to do is to use open -a /Applications/Emacs.app "$@". open is the command line equivalent of double-clicking on something in Finder. Put that into a shell script, stick it into your PATH and go.

Installing emacs-app via MacPorts is probably the simplest way to get and maintain a Cocoa emacs.

You may wish to look into Aquamacs which is a further refinement of emacs for OS X. The emacs wiki page on Aquamacs is very helpful. It also has an option to add a little aquamacs script to your PATH that will open a file in the aquamacs GUI.

Schwern
+1  A: 

Best way is to use Homebrew and use

brew install emacs --cocoa

so you have a easy to update emacs installation. The Cocoa will make sure you have your mac keybinding working before emacs. Make the binary run at startup as a daemon (because it starts up not very fast), for instance:

 /usr/local/Cellar/emacs/23.2/Emacs.app/Contents/MacOS/Emacs --daemon

And make an script to the emacsclient command and saved it to /bin/emacs file (don't forget to make it executable):

#!/bin/bash
exec /Applications/Emacs.app/Contents/MacOS/bin/emacsclient -n -c "$@"

so when you fire up at bash "emacs something.txt" the already running emacs daemon opens it instantly. You can also extend it to open Emacs if the daemon is not running!

I tested it on the latest emacs 23.2, some features are not present on early versions.

Henry Mazza
You really shouldn't throw random stuff in `/bin` -- The right thing to do is to either put it earlier in your path or just make aliases for these things. I use Emacs.app out of the cellar as a normal double-clickable app.
Dustin
But if you use bash to edit a random file with emacs it opens another Emacs. My emacs script actually is on my ~/bin. Sometimes you have to manually set the bin as on: make EMACS=<path to actual emacs bin> if it depends on the actual bin file. 99% of the time you won't notice the diference.
Henry Mazza