Emacs on Android, because why not?

For those of you familiar with a terminal, whether it be from back in the MS-DOS days, because you need to manage some headless machines for a job, or you just like to toy around with Linux, I would hope you’ve heard of Emacs.  For those of you who don’t (or are die-hard vi fans), it’s a pretty impressive piece of software which some say can almost replace your entire operating system due to its already large feature set and extensibility.  Personally the feature I find the most useful (and also confusing to learn) is the “kill-ring” which allows you to keep multiple text snippets for pasting at once (in Emacs this is called “”).  However, great as Emacs is, it can’t really compete with today’s tasks of rich-text email, Instagram photos, Google Drive and other cloud storage, etc.  But just like there will always be a place for the command line, I’m sure Emacs will continue to live on as an older, but still effective application for some specific purposes.  So if that’s the case, then why not install it on your phone?  While the use may be questionable, the difficulty level is low, and the fun & educational factors should outweigh it.

So here’s what we’ll need:

TerminalIDE is an app which I’ve always had some mixed feelings about.  It hasn’t seen development in awhile, but luckily works well for our purposes right now.  What sets it apart from some other terminal applications is that the Unix applications have all been recompiled to work locally within the app, thus it works even on phones that are not rooted.  The flip side of this is that the app is quite large in size (so if you’re limited on space you might have to pass this one by) and the native applications within TerminalIDE are not able to do DNS resolution, so any network activity must use IP addresses (or be preceded by a call to jping to get the IP).

For anyone clever enough to notice that there’s an Emacs app for Android, I’m sure you’ll also notice how ineffective/buggy it is, thus the reason for this post.

The data files are the same ones used by the Emacs Android app, but independent of the less-than-useful terminal emulator.  By joining the two, we can create a functional instance of Emacs to fool around with.

First, start by installing TerminalIDE and placing the Emacs files in an accessible location on your device.  If you know where the home folder within TerminalIDE is, and you can place them there then that’s great, otherwise, the Downloads folder works just as well (yes if you wanted you could do this whole process from just your phone).

Issue the following commands to decompress the Emacs binary and make it executable:

unlzma emacs.lzma
chmod 755 emacs

Next we need to create the directory for Emacs to work in.  For our purposes (and in being consistent with Android applications) this will be an ’emacs’ directory placed within ‘sdcard’:

mkdir sdcard/emacs

Now we must move the other downloaded files to this new directory and extract them:

mv etc.tlzma sdcard/emacs/etc.tar.lzma
mv lisp.tlzma sdcard/emacs/lisp.tar.lzma
cd sdcard/emacs
unlzma etc.tar.lzma
unlzma lisp.tar.lzma
tar xvf etc.tar
tar xvf lisp.tar
rm etc.tar
rm lisp.tar

At this point Emacs should be ready to go, this can be checked by going back to your home directory and executing it:

cd
./emacs

And that’s it!  If Emacs fails to load, it could be because there seems to be a minimum screen width.  On my Moto X (2014) loading in landscape worked (with about 4 usable lines in the editor) but portrait would not work until reducing the text size in the TerminalIDE options.

Usability?

So here’s the question: is it really usable?  Well you definitely need a full-featured keyboard.  This can be accomplished in at least three ways:

  • Install a third-party keyboard such as Hacker’s Keyboard
  • Attach an external keyboard via USB OTG or Bluetooth
  • Use telnet or ssh to access it from another machine with a full keyboard (details available within the TerminalIDE app)

After fiddling with the first option, I can say that it does indeed work, but I wouldn’t call it efficient or particularly enjoyable (except for when I played a decent game of Emacs Tetris!).  I think this option would be nice to have in your back pocket (or front pocket, or purse, wherever you keep your device) just in case you absolutely need to use Emacs at the drop of a hat.  The second option is a bit more enticing, it allows you to type like you normally would, leaving only the tiny screen to stand in your way of ultimate Emacs exploitation.  For this I wonder if utilizing screen mirroring via Miracast or Chromecast would make for a decent setup (somewhat reminds me of the “Could companies issue only one device and have it do everything?” question raised by the Ubuntu Phone).  As far as the last option goes, at that point I don’t see the use.  If you have another machine with a full-keyboard then why aren’t you just using Emacs on that (I’m sure someone playing devil’s advocate could come up with something…)?

So is it usable? Yes, but there’s a reason GUIs were invented and screens became touch-enabled, and I think that for most of us, embracing these things will allow for a much more pleasant experience.  However, there will always be a place for terminals and robust applications to run on them, and here’s just one example of how you can keep one within arm’s reach, for whatever you dream up.

Screenshot_2014-11-11-18-29-41Productivity at its finest

UPDATE: With the release of Android 5.0 “Lollipop” the need for Android executables to be Position Independent (PIE) is enforced. As such, the method outlined above will no longer work. In addition, a bug in TerminalIDE causes it to crash when the Google Keyboard is toggled, this behavior is not exhibited using Hackers keyboard or the built in TerminalIDE keyboard, however there doesn’t seem to be any active development on either projects at this time.

Special thanks to David Megginson for the instructions that inspired this post, and for all the people who have contributed to the development and use of GNU Emacs.