Prosthetic Conscience
Jason McBrayer's weblog; occasional personal notes and commentary
Thu, 19 Jul 2012
Running Emacs on an Android tablet
One of the things I’ve always wanted in a portable computer is the ability to run Emacs. The main reason is that since 2005 or so, my whole life has been run in org-mode, and, slightly before that, in howm. So, of course, when I got a low-end Android tablet, an Archos 70, of course, I…didn’t install Emacs on it. As EmacsWiki implies, there’s no perfectly obvious way to do so. And, there’s MobileOrg-Android. When I first got my tablet, MobileOrg-Android was pretty bad. But it got better. Today, it’s got a great user interface, syncing is fast and generally reliable, and there’s an active core group of developers who are constantly adding features and contributing back to org-mode itself.
But…after quite a bit of trying, I still haven’t made the MobileOrg workflow work for me. I keep my org files in a Mercurial repository on my home machine, and carry a clone with me. I run org-mobile-push and org-mobile-pull from the home repository, which requires it to be up to date, which usually can be done without manual intervention, but not always. And both pushing and pulling can make changes, which have to be committed. And you really have to sync on the mobile device twice: once before you push/pull, and once after, if you want the desired effect of pushing all your changes and captures to the repository, and having them all reflected on your device. The MobileOrg workflow is based on the idea that your mobile device doesn’t have the horsepower to compute agendas on the fly. But is that true these days? I’ll return to that issue later.
After seeing that some people had successfully run an Ubuntu user environment in a chrooted loopback filesystem on a similar tablet, I decided to try to get my Emacs that way. It didn’t exactly work out right a way, and it took me quite a while to make time for the yak-shaving involved. Finally, I did, but with my preferred GNU/Linux distribution, Fedora.
Overview (the short version, aka tl;dr)
My sdcard is formatted ext3, and has the Fedora 13 rootfs unpacked into it. From a root prompt in ConnectBot, I bind-mount some required special filesystems under Fedora’s root, then chroot into it, and start sshd. Then I can ssh into localhost with ConnectBot and run Emacs (and other things).
Longer version
Don’t take this as a step-by-step instruction guide. What works and doesn’t work on my device is likely to be quite different from what works and doesn’t work on yours (unless yours is an Archos Gen8). This is really more to give you an idea of the kind of yak-shaving involved in getting this working.
First I rooted my tablet. I would have done this even if I weren’t planning on running Emacs. For reference, the tablet is an Archos 70, running the latest version of the stock (Froyo) firmware, with a rooted initramfs.
Then, I tried installing the Ubuntu loopback images mentioned above. This didn’t work for me, because the stock Archos kernel doesn’t include the loop device, and for some reason, even when I built custom kernels with the loop device enabled, I couldn’t get it to work.
Fortunately, my device has a microSD card slot, which is above and beyond the internal storage that the Archos firmware treats as an sdcard for the purposes of App2SD and so forth. I formatted a card as ext3, and tried to unpack the Ubuntu image onto it. This should have worked, but for some reason, my tablet didn’t like having so much data pushed onto it over USB, and I lost the enthusiasm I needed to work on it.
Later, I unpacked the Fedora 14 ARM root filesystem more successfully, and tried chrooting into it, only to find that my kernel was too old for the version of glibc in Fedora 14. This also tragically sapped my motivation, causing me to stop working on it again for a while.
When I got another round tuit, I started with the Fedora 13 ARM root filesystem, and it worked pretty straightforwardly. This is what I did:
# umount /mnt/storage/sdcard
# mount -o noatime,nodiratime /dev/block/mmcblk2p1 /mnt/storage/sdcard
The sdcard is mounted with the options nodev,noexec,fmode=0666, and several other options that would make running it as the root filesystem of a normal linux slightly inconvenient. Some of the other parameters could be reset with mount -o remount,blah,noblah, but there doesn’t seem to be a way to do that for fmode and dmode, so unmount and remount it is.
# cd /mnt/storage/sdcard/fedora
# mount –bind /dev dev
# mount –bind /dev/pts dev/pts
# mount –bind /proc proc
# mount –bind /sys sys
Now mount the various special filesystems that Fedora is going to need, that are provided by the kernel.
# chroot . /bin/bash -
# service sshd start
Now chroot into the Fedora environment, and start sshd. I’ve omitted some other stuff, like setting a (new?) password on the root account, and so forth. Technically, even starting sshd isn’t necessary. You can just chroot into Fedora and run what you want to. Having sshd running makes it easier to reconnect to the Fedora environment without having to go through the process of cd’ing and chrooting to the Fedora directory.
From here on out, it’s just installing stuff with yum. I’ve tried to avoid installing anything except what I particularly need.
# yum install -y emacs-nox git mercurial aspell aspell-en \
diffutils patch man screen
What works
Installing things with yum!
There are things in the Fedora repositories that aren’t supported on ARM, but I haven’t had cause to install them yet.
Emacs!
Fedora 13 had Emacs 23.2.1, which is not exactly the latest and greatest, but it’s not old enough to cause serious compatibility problems, either. I used hg to pull in my emacs startup code from my desktop, then created a mobile branch to strip it down and remove features I wouldn’t be using, and to change paths to work with my mobile setup. Everything works as expected.
Emacs startup is surprisingly snappy. I had slower emacs startup times on my desktop as recently as 5 or 6 years ago, and this isn’t exactly a fast tablet.
You might think it would be hard to use Emacs with a mobile keyboard, but Hacker’s Keyboard takes care of that, by and large. It’s still an onscreen keyboard, but it’s an onscreen keyboard with all the keys you’d expect on a standard PC keyboard.
Color themes work, as long as they would work under xterm-256color. Sorry for not including a nice one in the screenshots, but those were taken right after I got emacs running.
Org-mode!
This was where I had some concerns going in. The design of org-mobile was premised on the idea that mobile devices didn’t have enough oomph to generate agendas on the fly, so emacs pushes pre-generated agendas. I have fairly large org-mode files. They’d be smaller if I archived to file more often, but I don’t. So, is emacs on my tablet able to generate my agendas?
The answer is yes, mostly. The first time I run org-agenda, emacs spends a very long time reading in my org-mode files; I suspect that the slow sdcard I’m running this from may be part of the problem. The first time, it was ’30s, but similar ‘cold’ agenda startups have been around ’10s since then. Subsequently, however, the agendas are generated perfectly quickly.
All in all, my orgmode workflow works perfectly on the tablet, with the exception that hg tries to use vimdiff to do merges, for some reason!
Also, one other issue is that since I am using emacs in a (local) terminal window, I have to use the alternate tty keys.
What doesn’t work well
Writing a lot.
This is not exactly a surprise. Unless I go to another machine and ssh into my tablet (and what would be the point?), I’m constrained to use the onscreen keyboard. And not only that, it’s worse trying to write with the onscreen keyboard in a regular Android app, because the predictive text is not active in ConnectBot.
If I had a small hardware keyboard, I’d be more inclined to do actual writing on this setup.
Another alternative is to let Emacs do the text completion, using either Predictive Mode or auto-complete. However, while both of those do prose completion fairly well (different strengths), neither does autocorrection, which is just as important with a soft keyboard.
Leaving an Emacs session running all the time
I’m used to never exiting Emacs. On my desktop/home-server machine, Emacs is started for me by systemd, which runs it with –daemon, and restarts it if it should ever crash. On my tablet, I started out by running it under screen, and switching back to it as needed. It turns out that this is fine, as long as I want to stay in the Fedora environment, but it doesn’t leave enough memory for my usual set of Android apps to perform normally.
Conclusion
I haven’t tried the next logical step, which would be to install Xvnc and its dependencies, and to run a local X session, to be displayed in an Android VNC client. I may not do so, because it looks like the keyboard situation in the main free Android VNC clients is not much better (if at all) than in the terminal, in terms of having the full set of keysyms available. And it is worse, in that in ConnectBot, Emacs’s screen gets resized to accommodate the soft keyboard, whereas in VNC, the soft keyboard sits on top of part of the display area, which is not resized.
On the whole I’m happy with this experiment. I don’t think it will replace my use of Jota for note taking, because of the text auto-completion and auto-correction issue. I’m not sure whether it will completely replace MobileOrg for me. I’m enjoying finding out.
[ Posted: 21:50] | [ Category: ] | Permalink | Comments: 2 ]
Powered by PyBlosxom
Subscribe