: Learning GNU Emacs, 3rd Edition

13.2.4 Starting Emacs from the Command Line on Mac OS X

13.2.4 Starting Emacs from the Command Line on Mac OS X

On Mac OS X, you have Emacs preinstalled, but as we know, it is an older version of Emacs. Let's say that you have installed the graphical version and want to start it with some command-line arguments. For example, you might want to run emacs debug-init to debug your .emacs file. The Mac OS X Gnu icon certainly should be a permanent fixture on your Dock, but at times the command line is the way to go.

We learned this trick from Andrew Choi's Mac OS X FAQ, and we share it here, slightly tweaked, for convenience. Check out his page at http://members.shaw.ca/akochoi-emacs/stories/faq.html.

Essentially, you replace the binary that comes with Mac OS X with a shell script that runs the new version of Emacs you installed. You might want to simply rename the old binary so that you can on occasion use it instead.

Here's the procedure.

1.To be sure which Emacs runs when you type emacs, type which emacs in the Terminal application.

% which emacs

2.Rename or delete /usr/bin/emacs.

% sudo mv /usr/bin/emacs /usr/bin/oldemacs

3.You'll be prompted for your password.

4.Create a file called emacs with the following two lines:

/Applications/Emacs.app/Contents/MacOS/Emacs "$@"

If you installed Emacs into a different folder, adjust the second line accordingly.

5.Move the file you created to /usr/bin:

% sudo mv emacs /usr/bin

6.Change /usr/bin/emacs to be executable by the world:

% chmod +x /usr/bin/emacs

Now you can invoke graphical Emacs from the terminal window simply by typing emacs, with or without command-line arguments.[92]

: 0.769. /Cache: 3 / 0