In my last post, I talked about how to set up Emacs as a Python IDE. Since then, two things have changed:
- I got a Macbook Air. Switching from Linux to Mac required a few (mostly minor) changes to my Emacs configuration.
- I have begun using the fabulous IPython Notebook, which has really helped me organize my code and streamline my workflow.
In this post I’ll tell you how switching to a Mac has affected my configuration. In a future post (coming soon!), I’ll talk about the IPython Notebook, how I set it up for my configuration, and how it’s really improved my Python development environment. You can find the emacs configuration associated with this post here.
Disclaimer: I’ve made a lot of these changes piecemeal over the course of a few months, so I may not be 100% correct about all of the customizations here (and may have accidentally left out some steps). If you run into any issues, let me know and I’ll try to help you debug!
Mac Package Management
First off, I should mention which package manager I’ve been using to set up my Mac. After hearing too many stories of frustration about MacPorts, I was given a recommendation for Homebrew instead. So far, I’ve found it to be quite straightforward and pleasant. It doesn’t have every application or library I want to install, but it has given me enough of the basics that I’m satisfied. I’ll be using homebrew to install a lot of things in this guide, so the setup might be a little different if you use MacPorts or something else. In theory, it shouldn’t matter since everything is compiled from source regardless. With Homebrew, I installed a few utilities that have made my Mac act more like Linux. These are optional with respect to this guide, but I find them essential to really get anything done so I’m listing them here anyway.
OS X comes with many of the standard coreutils (e.g.
ls), but they
are outdated versions. For example, the default build of
ls is from
2002! There are much more recent versions than that, so I installed an
updated version (coreutils 8.20):
brew install coreutils
Homebrew installs these programs prefixed with ‘g’, e.g.
didn’t want to use these utilities to be used system-wide by default
in case something needed backwards compatibility, so I am instead
using bash aliases. You can add something like the following to your
1 2 3
Ok, on to Emacs! First, of course, we need to actually install it. There are a few options available:
- Special Emacs builds like Aquamacs, which makes some modifications to make Emacs more OS X-like.
- X11 Emacs running under XQuartz (you can install this version
of Emacs using
brew install emacs --with-x), which is traditional Emacs but runs under the X windowing system. This is the windowing system used by many flavors of linux, so it is literally as close as you can get to a linux build of Emacs.
- Cocoa Emacs, which is traditional Emacs built using Apple’s Cocoa API and thus appears like a native OS X application.
I decided that I didn’t want that much customization to my Emacs environment – I wanted it to be as similar to the Emacs I use under Linux as possible (especially because I still access Linux machines fairly frequently). I first tried out the traditional X11 Emacs but it was fairly annoying to have to switch to XQuartz and then Emacs from my other applications. So, I ultimately settled on a Cocoa build, which is basically traditional Emacs but is also integrated into the OS X environment:
brew install emacs --cocoa
First, as I mentioned, I still use some Linux machines and wanted to be able to share my Emacs configuration between them and my Mac. So, I defined some helper functions to differentiate between OS X and Linux, in cases where changing the configuration to make it work in OS X would break it in Linux:
1 2 3 4 5 6 7
Remapping the Meta Key
If you’re used to using Emacs on a PC, then you’re probably used to using the key(s) closest to the spacebar as your meta key. On a PC, these are the Alt keys, but on a Mac, the Alt a.k.a. Option (⌥) keys are actually the second closest to the spacebar: instead, the closest keys are the Command (⌘) keys. By default, the meta key in Emacs on a Mac is bound to Option. I don’t know why this is the case, because it’s the most awkward key to hit. I rebound my meta key to the Command key:
1 2 3
I should also note that in System Preferences, I remapped my Caps Lock to be another Control key.
True and False
There were a lot of places in my configuration files that used
t for false and true, respectively. This apparently does not
work in Cocoa Emacs. Replace
1 and this
should fix configuration options that seem to have stopped working.
Many of the theme customizations I had in
stopped working. I had to rewrite some of the settings as explicit
commands, for example:
I also removed the dependency to Color Theme (which I was previously using as a base for color customizations), as it is no longer supported in Emacs 24.
Cocoa Emacs does not use
PYTHONPATH as it is defined in
.bash_profile, because those files are only evaluated
in an interactive shell. Unless Emacs is run from the shell, it will
not be running in an interactive session. Therefore, it is necessary
to redefine the
PYTHONPATH from Emacs’ configuration,
1 2 3 4 5 6 7 8 9 10 11 12 13
I began manually setting the default frame size to the full height and half the width of my screen, so I didn’t have to resize it every single time. This is less of a Mac-specific thing, but I thought I’d mention it:
1 2 3 4 5 6
AUCTeX wasn’t being activated by default on OS X (whereas it used to
be under Linux). This required adding
(require 'tex-site) to enable
AUCTeX. To further enable correct LaTeX syntax highlighting, I needed
(require 'font-latex). I also changed the PDF viewer
invocation to use Skim instead of evince:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22