Emacs for iPhone

Emacs is the closest thing to an Operating System that a simple text editor should ever be allowed to come, if we’re to maintain our sanity. It’s also my favorite IDE.

The easiest way to get Emacs for iPhone is through my Cydia repository. This will let you install a pre-built, pre-verified Emacs. However, if you want to know how to build it from scratch, read on.

You’ll need an on-iPhone development environment to build Emacs, because it does this freaky thing where it loads a built version of itself, loads a ton of Lisp files, and then dumps itself out. This can’t be done in a simple cross-compiler setup!

As always, you can contact me if you need help.

The Easy Way

First, we need to install dependencies and fetch the Emacs sources and the patch file:

iphone:~ mobile$ sudo apt-get install ncurses
iphone:~ mobile$ wget http://ftp.gnu.org/pub/gnu/emacs/emacs-23.2.tar.bz2
iphone:~ mobile$ wget http://gammalevel.com/forever/emacs-23.2-iPad.patch

Next, we extract the sources and patch them:

iphone:~ mobile$ tar xjvf emacs-23.2.tar.bz2
iphone:~ mobile$ cd emacs-23.2
iphone:~/emacs-23.2 mobile$ patch -p1 < ../emacs-23.2-iPad.patch

Now, with the sources fully patched, we can build and install Emacs:

iphone:~/emacs-23.2 mobile$ ./configure
iphone:~/emacs-23.2 mobile$ make
iphone:~/emacs-23.2 mobile$ sudo make install

This compile can take a while on an iPad, and even longer on an iPhone. Go grab some coffee. Congratulations! You now have Emacs!

The Hard Way

Here, I’ll actually guide you through editing the files by hand instead of using a patch. I’ve also included why you edit the files this way, in case the patch doesn’t work.

First, we need to tell Emacs that Darwin on ARM makes sense. Open up configure, and do a search for the string “*-apple-darwin*. This will help you locate the block that checks machine types for Apple Darwin systems. Right below the line that says

powerpc-* )     machine=macppc ;;

add a line below it that says:

arm-* )         machine=arm ;;

Also, we need to edit src/unexmacosx.c. Search for the string “nothing to do for prebound lazy pointer. Underneath this case in the switch statement, outside of the #if defined (__ppc__) / #endif block, and before the default case, add in this case:

case GENERIC_RELOC_LOCAL_SECTDIFF:
     /* no idea what this is, but we ignore it anyway */
     break;

iPhone OS uses a Mach-O executable format section that Emacs doesn’t normally support, so it will yell at us when we try to compile. This fix will tell Emacs to ignore that section instead. I have no idea what this section does, but when it’s ignored, Emacs still runs fine, so it must not be too important.

Now, you can compile as above!