LinuxHappy's Weblog

Failures and Successes of Linux-based Development

emacs on MacOS (10.6) using Carbon Emacs

Posted by linuxhappy on September 19, 2009

Ok, I’ve recently bought a mac book pro. To say the least, I’m not super excited about it.. In my opinion, it’s got a lot of the nice things Linux has, but a lot of features that I haven’t figured out yet, or that the Mac just doesn’t have. Then again, my mac is sexy as hell and lasts about 7 hours on a plane, so I can’t complain.

Anyways, not having an emacs where I could quickly “M-x query-replace (Alt-x query replace)” really pissed me off.. Having to Ctrl-Escape-x was just a road block in my retarded little brain, and to make things worst, Apple (like Lenovo) switched the stupid control button with the fn key. One month later, I said to myself, okay. I spent 2000 bucks on this machine, i should be able to figure out how to get a decent emacs on this thing.. I found aquaemacs.. but it was a little bit different from Gnu emacs, and to be honest.. nice try, but I since I work on Linux all day, coming home to something slightly different was just a bit of a pain. So here it is.. I stumbled up on Carbon emacs.. beautifully (so far) the same as what I use on Ubuntu 9.04.. First.. I found a comment posted on this posting:

http://www.lshift.net/blog/2007/11/27/emacs-in-macos-x-105-leopard

The comment suggested to use Carbon Emacs, and then went on to say to make a softlink to /Applications/Emacs.app/Contents/MacOS/Emacs so you can quickly call emacs from a terminal.. Well. that didn’t work for me. Carbon Emacs, for some reason, didn’t like being called from an absolute path. E.g. The following command failed:

/Applications/Emacs.app/Contents/MacOS/Emacs

.. and softlinking

/usr/bin/emacs to /Application/Emacs.app/Contents/MacOS/Emacs

Also failed miserably.

So I created a script, to replace the original /usr/bin/emacs binary. So..
1. cd /usr/bin
2. sudo mv emacs emacs.old.leopard
3. Assuming you installed emacs into the Applications folder, copy and paste the script below into a file called “emacs”
4. sudo chmod 755 emacs
5. You should be able to use emacs from the MacOS terminal, just like on Linux 🙂


#!/bin/bash
EMACSHOME=/Applications/Emacs.app/Contents/MacOS
ARGLIST=
while [ $# -ne 0 ]; do
echo "$1" |grep "^/"
if [ $? -eq 0 ]; then
ARGLIST="$ARGLIST $1"
else
ARGLIST="$ARGLIST $PWD/$1"
fi
shift
done
cd ${EMACSHOME} && ./Emacs ${ARGLIST}

I had to append the $PWD variable to files that did not have an absolute path (those files listed on the command line that don't start with /) to allow opening of files, since we are having to 'cd' into the /Applications/Emacs.app folder

Cheers.

Advertisements

One Response to “emacs on MacOS (10.6) using Carbon Emacs”

  1. Tom said

    I can recommend http://emacsformacosx.com/ It’s the pure gnu emacs and you get version 23.1 I’m sure the Carbon Emacs is just fine, but I go with the original. However, there are no additional packages (like AUCTeX, if you use it). I have no problems running emacs from command line (/Applications/Emacs.app/Contents/MacOS/Emacs) and the built in /usr/bin/emacs remains unchanged. I swap caps and ctrl keys system-wide and use command key as meta in emacs only by setting:

    (setq mac-command-modifier ‘meta) ; standard keyboard, switch in Emacs
    (setq mac-option-modifier ‘meta)) ; standard keyboard, use meta again

    It’s easier to access than alt-option key. I’m not sure how it is in Carbon Emacs, but I can copy text from other windows with Command-c and then yank in emacs ctrl-y, and the other way around.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s