Running Emacs on an Android Device

Table of Contents

1 Emacs on Android

This article is an incomplete work-in-progress.

1.1 Introduction

I’ve got an Android phone (I’ve gone through a whole series of them from a Motorola Droid X through my current Pixel 1). I had a Samsung Android tablet, one of those monster 12 inch things. And when that died prematurely due to poor design resulting in a failed charging circuit, I eventually replaced it with a much better Asus Zenpad 3S 10 Z500M.

I kept thinking that it ought to be possible to use these devices as productivity tools, particularly the tablets. It was a frustrating journey trying to make this happen, filled with hacks, workarounds, moderate to severe compromises, and in the end, dissatisfaction.

My normal workflow depends heavily on Emacs and org-mode. Trying to work around that was difficult. I tried things like the Jota+ text editor (really a good product) and then FileSync, Acrosync, and other apps and tools. I was able to do some writing but it was really like going uphill, into the wind, against the current, and backwards all at once.

I needed Emacs, and an implementation good enough to encompass most of the functions I had fully integrated and synced among a desktop and three laptops.

There was an older Emacs implementation for Android. It was a nice try but it just didn’t cut it. It was buggy, unstable, and incomplete, and org-mode didn’t work; unfortunately it was a complete non-starter. The dev dropped it (as a free product, none of us had a right to expect anything) and that was that.

So, rather than be sensible and just use my Asus Zenbook (a fantastic laptop with no moving parts and over 9 hour battery life) I tried other things. (When I’m on a crusade, I pursue it far beyond the limits of reason.)

I set up a DOS environment with Magic Dosbox. Seriously, I did. I was able to run Lotus Agenda, Grandview 2, and Xywrite 4. That really wasn’t bad. It was nothing like my Emacs workflow but there were some pretty good tools on tap, although conversion and syncing were going to be a headache. A giant compromise to be sure, but at least the environment was comfortable.

But there were a couple of flaws. I write a certain amount in German and a great deal more in French, and I had to set up Xywrite to handle the accent marks. Okay, did that, messed with various keyboard drivers, and so on. Got it working in the end.

However, Magic Dosbox, run at a speed fast enough to be useful, is, shall we say, tough on the tablet battery. Now, the Asus Zenpad is not known for fabulous battery life. They claim 10 hours but most reports are in the 6 to 7 hour range. With Magic Dosbox running, it was more like three hours. That didn’t cut it. I needed to be able to safely do two working sessions of three hours each during the day, without having to recharge.

But then I discovered Termux, and that’s what the rest of this post is about.

1.2 Termux: What is it?

Termux is an Android “app” but calling it that is a huge understatement. It’s really a Linux-like environment (though certainly not a full Linux implementation) that presents itself in the form of a non-graphic shell. (There is no X server and you really can’t run any graphical programs.)

For a two-fisted command line/Emacs person, this presents only a few limitations, as we’ll see.

Termux is part of a large and growing ecosystem, with its own package manager and a respectable set of packages. There isn’t quite everything (no msmtp as yet, for one) but there are amazing things like expect, python, a variety of shells, a full TeXlive, and, of course, Emacs. It also seems quite possible, with some study and effort, to be able to build your own packages. I’ve yet to try this, but it looks feasible.

Termux has its own idea of a file system, using the native Android file system, and this causes a few issues, but nearly all of them come pre-solved, or can easily be solved on the spot.

Termux is available from the Google Play Store and on F-Droid. It is completely free. There are a few add-ons that enhance it a lot, and the dev asks a couple of dollars each. Buy them and support the developer.

1.3 Emacs Implementation

1.3.1 It’s the Real Thing

As of this writing, you can install Emacs 25.3 into Termux. It’s the real thing, not some ersatz or stripped-down version. It is built as text-mode only, so you may run into a couple of things that don’t work (like scroll-bar-mode, for instance) but these are relatively easy to find and fix.

The Emacs package manager works perfectly, so you can install all of your favorite stuff. Most of it works out of the box, although there are some obvious exceptions, such as packages that deal with X-Windows or most any sort of graphics.

1.3.2 I Did It My Way

The remainder of this document will be about how I set up Termux and Emacs to meet my needs and give me a functional equivalent (at around the 95% level) of my Linux workflow. I’ll go into how I made things work, how I worked around things, things that I haven’t yet verified, and those few things that just aren’t going to work out.

The bottom line, though, is that I have my workflow implemented to an extent that I can use my Android tablet to get things done. Not everything, but lots of things.

Primarily, I’m a writer, and my workflow reflects that. You might have more or less success depending on your own needs.

1.3.2.1 The Basics
1.3.2.1.1 Installation

Installing Termux is easy, as noted above. Get it from F-Droid or Google Play. There are a few add-on packages and you want all of them. These are not free, but don’t cost much, and provide at least minimal support to the developer. (I think I paid about US $8 for everything.)

Termux comes with a package system similar to ’apt’. Use that to install emacs:

pkg install emacs

and then just give the command emacs on the command line. Amazing, isn’t it? As I said, the real thing.

1.3.2.1.2 Additional Packages

Termux as delivered uses busybox for many basic commands. You might want to install the ’real’ versions of some of these, as the busybox versions are often abbreviated.

1.3.2.2 File and Directory Paths
1.3.2.2.1 When to use termux-fix-shebang
1.3.2.2.2 Shebang workarounds
1.3.2.2.3 When and how to fix paths in Elisp
1.3.2.3 Email
1.3.2.3.1 gnus
1.3.2.3.2 bbdb
1.3.2.3.3 msmtp
1.3.2.4 Audio
1.3.2.4.1 vlc
1.3.2.4.2 play-audio/play
1.3.2.4.3 emms
1.3.2.5 Miscellaneous Hacks
1.3.2.5.1 Tex packages/path hacks
1.3.2.5.2 reuse of startup files
1.3.2.5.3 .emacs file, .emacs.local
1.3.2.5.4 graphics / openwith
1.3.2.5.5 Linux/X dependent stuff
1.3.2.5.6 clipboard limitations
1.3.2.6 Syncing
1.3.2.6.1 What you can sync
1.3.2.6.2 What you can’t sync
1.3.2.6.3 What you should save separately
1.3.2.7 Remaining Issues
1.3.2.8 Non-Emacs Considerations
1.3.2.8.1 Building Packages
1.3.2.9 A Surprising and Pleasing Side Benefit

I mentioned above an earlier attemtp at workflow implementation with Magic Dosbox, and how battery drain was a real show-stopper. So I wondered how that would work out with Termux.

I quickly found out that Termux is very easy on the battery. This really caught me by surprise when first working with it. I had fully charged the tablet and started work. After a while I noticed the battery sitting at 86%. I thought that since it hadn’t drained much, I probably hadn’t been working as long as I thought. But ’uptime’ showed that I had actually been running for 1 hour 32 minutes. In other words, on my particular hardware setup, Termux drains less than 10% per hour and I’m getting that 10 hour plus battery life which Asus claimed in their hyped-up publicity.

Ten hours is almost enough for a flight from Honolulu to New York, with just a few rest breaks. (Of course, now there are those seat-back chargers on most flights, but stil

Author: Bob Newell

Email: bobnewell@bobnewell.net

Created: 2018-03-07 Wed 14:12

Validate