Emacs and OSX should play nicer
October 1, 2006 8:54 AM   Subscribe

How can I make my Mac Emacs experience approximate my Linux one?

I've got a couple of issues that crop up when doing this, but first a bit of background:

I'm new to the OSX world.

I've got TextMate, which is nice and GUI, but I prefer Emacs for writing C.

I use plain old GNU Emacs. I have a .emacs file that is shared across several machines, configuring a whole big pile of extensions. I mention this last because it means that tricks like this one to switch the meta key to option instead of tab don't work everywhere. Which, in fact, leads to the first part of my issues: I need to have a way to have platform-specific sections in my .emacs file so that I can have Mac-only code in there.

Secondly, if I expect to use this editor at all, I need to be able to launch it from the command line. Using symlinks into the .app/contents/MacOS directory doesn't work, as applications launched by symlink cannot find their resources, but it also seems counter to the idea of relocatable apps to add the internal structure of my bundle to my shell path. Is there a way around this? I usually run emacs-server and emacsclient, and right now I'm using the emacs build highlighted on Apple's page here. I'm open to other builds, though -- there's a Cocoa emacs build hosted on Sourceforge that I'm willing to try. Whatever one has a simple way to integrate it with the command line, that's all I ask.

In addition, any other issues that might plague me as an emacs user on OSX?
posted by ChrisR to Computers & Internet (12 answers total) 2 users marked this as a favorite
I'm not much of a fan of emacs, myself, so I can't help you make your editor environment more familiar, but I can help you launch a bundled application from the shell without trying to be clever mucking around in the bundle's innards: man open
posted by majick at 9:11 AM on October 1, 2006

Aquamacs, Aquamacs, Aquamacs. Download it now and try it out. You will thank me later.

By the way, the trick for opening things from the command line in OS X is the open command, e.g. open -a '/Applications/Aquamacs\ Emacs.app/' file.txt Set up an alias if you want to make that easy to do.
posted by onalark at 9:23 AM on October 1, 2006

Seconding onalark.

I really like Aquamacs, which is a port of Emacs to OS X that has added "snug this into OS X/Aqua" stuff chunked in. It also maps the basic set of Apple keystrokes (cmd-c to copy, cmd-v to paste, etc.) in addition to the traditional Emacs keybindings, though at the expense of using the cmd key as the meta key.

the Aquamacs page on EmacsWiki is full of pointers for integrating Aquamacs with OS X.

The issue of dealing with command line integration is a little tricky. Phil Hollenbeck's notes are pretty helpful. Search down that page to "script to force Aquamacs to open in front of terminal," which not only deals with launching from the command line but making sure the GUI/mouse focus works more like you'd expect.
posted by mph at 9:24 AM on October 1, 2006

Oh, and Aquamacs doesn't prefer you use the standard .emacs file for user preferences, there's another file to modify (you'll need to read the FAQ).
posted by onalark at 9:26 AM on October 1, 2006

Response by poster: I've tried Aquamacs before, and I don't like it; it's too dissimilar to emacs in other environments, and I work on Linux at work.

The open -a trick looks good, but it doesn't do emacsclient for me if I have an emacsserver running, which is a bit of a dealbreaker for that trick. Any other ideas?
posted by ChrisR at 10:35 AM on October 1, 2006

The open -a trick looks good, but it doesn't do emacsclient for me if I have an emacsserver running, which is a bit of a dealbreaker for that trick. Any other ideas?

Use the script I pointed to on Phil Hollenbeck's page. It's written to work with the Aquamacs app bundle, but it'll work with any OS X emacs that ships with emacsclient. Note that you can't use the built-in emacsclient OS X ships with if you're not also using the OS X emacs, so you'll need to get it out of your path. Hollenbeck's page addresses this as well.

Also, since Aquamacs is out of the question, the other build of Emacs I've had good luck with is the one at porkrind.org. I used it for a while before I found Aquamacs. The maintainer recently announced that he's back to maintaining it actively, supporting both PPC and Intel, with plans to introduce universal builds.
posted by mph at 10:56 AM on October 1, 2006

One other note is that if you're used to the pageup/pagedown/home/end bindings that are common to every OS but Mac, you can have them if you put a KeyBindings.dict file in place.
posted by SpecialK at 12:45 PM on October 1, 2006

In interesting fact about GNU emacs on OS X is that the developer who actually did most of the work (Andrew Choi) got fed up and went to xemacs. Supposedly one reason was that the emacs development team wasn't especially friendly to the project because OS X is not Free. (He also somewhere has a rather bitter rant about people who package his version of gnu emacs and describe what they did as porting it to os x, or "developing" it, etc.) So as a long term solution you might consider switching to xemacs. Since there is no binary of the development version, if you do want to use xemacs now you'll have to compile a beta from scratch, applying the patch yourself. This was pretty straightforward for me when I did it, though it can take a while. Because the port was mostly done by the same person, right now it works about like all the versions of gnu emacs people are recommending above, so I don't know if there is any short term advantage to doing this.
posted by advil at 1:53 PM on October 1, 2006

I am currently running an emacs that I built from source which was the only way I could find the features I wanted without too much mac-isms layered on top. Begin by installing (and updating) the developer tools. This is free but requires that you sign up for a (also free) account with apple. Next check out a copy of emacs.

Then, from the top of your code tree:
$ cd mac
$ rm -f EmacsInstaller.dmg        #only necessary after cvs up
$ ./make-package --self-contained
$ open EmacsInstaller.dmg
and you are done. I have only once been forced to update and rebuild over the past 2-3 years. Although I did have to add this line to my .emacs to deal with ... something:
(setq process-connection-type t)
I don't run it from the command line (often) so I can't speak much to your concerns there. However, I just added symlinks to the binaries to my ~/bin directory and found that emacs did not behave well but emacsclient worked just fine.
posted by Mr Stickfigure at 5:11 PM on October 1, 2006

You don't mention this as a problem, but I'll post for the benefit of others who arrive at this thread seeking OSX + Emacs wisdom.

When several of my Emacs key bindings failed to work under OSX, after much head-scratching I realized that Terminal.app does not seem to generate Ctrl + Meta (at least in a way that Emacs recognizes), making many of my Emacs key bindings inaccessible.

I mainly use Emacs from the command line, often over ssh connections, and the only solution I found without being forced into using X was to use a terminal emulator called GLterm, a $10 shareware app. which is inferior to Terminal.app in many ways but gets Ctrl + Meta right so I can use Emacs properly. GLterm's most notable disadvantages are the inability to resize fonts on the fly (with Cmd-+, Cmd--) and occasional rendering problems.
posted by harmfulray at 6:42 PM on October 1, 2006

Response by poster: So, it looks like emacsclient, unlike emacs itself, works intelligently when accessed from an arbitrary executable. This is a good thing, and means that I should be able to keep working with this.

The GNU free/non-free distaste for OSX doesn't surprise me too much, but so be it.

I'd use xemacs, but it doesn't work the same way with the extensions I use, or at least that's what I was told by my boss when he helped me get set up to go. I might experiment, just to see what works.

The one other thing I had wondered about was conditional execution of parts of my .emacs depending on my running platform; does anyone know how to do that?
posted by ChrisR at 7:33 AM on October 2, 2006

Best answer: Check against system-type:

Something like

(if (eq system-type 'darwin) junk-you-want-it-to-do-if-it's-a-Mac )
posted by mph at 10:18 AM on October 2, 2006

« Older Did Steve Irwin expore WW2 sites?   |   Help me find fun games for kids with disabilities Newer »
This thread is closed to new comments.