开发者

emacs on OS X 10.6

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 em开发者_开发百科acs 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


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.


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


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.


I create a shell script named emacs in my ~/bin directory containing:

open -a Emacs "$@"

Obviously, ~/bin needs to be before /usr/bin in my PATH which I set in ~/.profile so that it shadows the preinstalled emacs binary.

I also create a symlink via ln -s /Applications/Emacs.app/Contents/MacOS/bin/emacsclient ~/bin/emacsclient so that this also shadows the preinstalled emacsclient binary.

For additional connivence, I create an alias ec='emacsclient -a emacs -n ' and include (server-start) in my emacs init scripts. This enables me to open a file from the commandline using ec filename regardless if emacs is or is not already running.

Another tip: When you launch the emacs via Applications or open, emacs does not inherit the same path as you have in your terminal environment, so one thing I have found very useful is to run the following in my .profile after setting my path to change the PATH inherited cocoa applications:

   defaults write ${HOME}/.MacOSX/environment PATH "$PATH"


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜