Surprisingly, Emacs on Android is pretty good

Lately I’ve been taking steps towards a better mobile-PC workflow. So far, I’ve been using the community-developed Orgazli-Revived app exclusively on Android. My intention was to use Orgzly—Revived for simple task management and another app for more note-taking purposes—but I never found another app on Android that I was happy with. But I remember reading good things about it native Emacs app on Android a few months ago. So I tried it…and was instantly sold!

The good and the bad: what to expect on Android

First, let’s make sure our expectations are tempered: Emacs on Android won’t be as enjoyable as the full desktop experience. Absolutely. Phone screens are small, and unless you’ve connected a physical keyboard, you’ll have to manage with a virtual keyboard (see Use a special virtual keyboard). on the top of that:

tooling
To make non-Emacs programs available, you must install Emacs in a special way with Termux to expose Termux’s binaries to Emacs. (See Recommended way to install Emacs.) The initial set up is lengthy, but it’s worth it.
file path
Android “sandbox” every app. You can think of each app as having its own “section” of the file system that they can read or write to (unless they are given explicit access to that external directory; see) info "(emacs) Android Document Providers"Thus, if someone, for example, wants to access his Notes directory outside the Emacs app sandbox, he finds himself struggling with obnoxiously long Android file paths. This is a minor inconvenience, however.
write to file system
By comparison, writing to a file system can sometimes take a long time. Not too long, but still long, as far as I’ve experienced, this only happened when saving files outside the Emacs sandbox.

So, actually, the situation is very good!

And finally: YMMV on other Android devices. My current phone is a OnePlus 7 Pro which runs Android version 12.

installation

Option 1

The first option is as simple as it gets, but you’ll have no way to access the other CLI tools:

  1. Download F-droid App Store. For the layman who doesn’t know what it is: It’s basically an alternative to the Play Store. Some apps that may not be on the Play Store (fact check, maybe link vaccines) do exist.
  2. Download the Emacs app.
  3. Open Emacs! The version of Emacs available as I write this is Emacs 30.1.

It’s perfectly possible to use Emacs this way if you only need elisp. But if you need other tools like Git, I recommend another way to install Emacs.

This option makes the Emacs Android application container accessible to other CLI tools. This is a little more troublesome.

The method is outlined in this SourceForge repository. In short, inside termux/ This SourceForge repository’s directory contains modified Emacs .apk files. These .apk files allow the Emacs app container to access the Termux (clarify what Termux is) app container, meaning that CLI tools installed with Termux will become accessible to Emacs. But the installation is specific; Read the detailed instructions inside that repository. I’ll outline them briefly below, but be careful if you’re reading this in the future, as the instructions may change contextually.

In short,

  1. Remove any existing Emacs or Termux apps.
  2. Make sure you’ve enabled the setting that allows you to install third-party apps (i.e., non-Play Store apps) on your phone.
  3. Install Termux. Do not open Termux yet.
  4. Select the appropriate .apk file for your phone. There are different .apk files for different versions of Emacs and devices.
  5. Install Emacs via this .apk. (If your phone refuses to install the .apk, you may have selected the wrong type of .apk file for your device. So try different .apk files for the same Emacs version.)
  6. In Termux, run pkg update && pkg upgradeSay “yes” to each prompt,
  7. Open Emacs.
  8. create a ~/.emacs.d/early-init.el And place the following inside it:
    1
    2
    3
    
    (setenv "PATH" (format "%s:%s" "/data/data/com.termux/files/usr/bin"
                           (getenv "PATH")))
    (push "/data/data/com.termux/files/usr/bin" exec-path)
    
  9. and you’re done! Programs installed through Termux will be made accessible to Emacs.

configuring Android-specific Emacs

Required Reading: Manual

Chances are you may not know that the Emacs manual has its own section for Android systems: (info "(emacs) Android")Before anything else, I advise you to study this section thoroughly, and to read and study specific parts in more depth as you see fit, In particular, I found the following information nodes essential:

  • (info “(emacs) Android file system”) (This is especially important if you want to understand what ~/ means path for Emacs.)
  • (info "(emacs) Android Document Provider")
  • (info "(emacs) android fonts")
  • (info "(emacs) android windowing")

There is a lot of information found directly inside these information pages.

Additionally, I also think reading about Emacs’ features for touchscreens and virtual keyboards (bet you didn’t know it was in the manual!) is essential: (info "(emacs) other input"),

Moments like this are truly a testament to Emacs’ dedication to being an accessible editor.

How to configure your init.el on a mobile device?

Later I’ll explain how you make typing code on touchscreen devices easier by installing a handy virtual keyboard. But I highly recommend that you wait until you decide on a configuration you are willing to type. Make the most of the customized interfaceThis means accessing the customize interface through the tool-bar button Then tap the available buttons using your touchscreen optimized-mode Buffers. (Then, if you want, after setting multiple options with Customize, you can re-do the customize options you entered in your init.el For example in use-package form.)

If you have not used Customize before, you can take a look at the available Customize commands C-h a ,apropos-command), find “Customize”. The most useful commands are:

  • custom-group,
  • custom-options,
  • custom-face,

Step One: A Better UI for Touchscreens

The first thing I did when I opened Emacs was enable these little modes:

  • modifier-bar-mode
  • tool-bar-mode

and set tool-bar-position To ‘bottomPlacing it close to where my fingers and the virtual keyboard are.

Desktop users may have disabled these years ago in favor of keyboard-centric workflows, but in my opinion they’re wonderful for touchscreens.

Android-specific commands and options

There are some built-in Android commands and options you should be aware of. (Pro tip: anyone can MX Info-Index or press i In the Emacs Info manual, accessible via C-h rOr mx info-emacs-manualThen search the string “Android” to find all specific mentions of “Android”.)

  • Order:
    • android-request-directory-access To request access to file paths of other apps
    • And vice versa, android-discard-directory-access,
  • Option:
    • android-pass-multimedia-button-to-system,
    • android-intercept-control-space,
    • touch-screen-display-keyboard,
    • (And more than that is not useful to me).

Also, don’t forget to allow Emacs to be visible to other apps. This is a device setting, not an Emacs setting.

Use a special virtual keyboard

Unless a physical keyboard is connected to your mobile device, typing will be difficult. For that, we install a virtual keyword that gives us easy access to modifier keys, function keys, arrow keys and symbols. As far as I know, there are currently two main options:

Having tried both briefly, I personally prefer the latter. However if you like that the first one works fine.

fonts

You may want a set of fonts that are not already installed on your Android system. If so, you should read this (info "(emacs) android fonts") manual page.

That page states that if you want to install fonts for your user (in the Emacs app container), you should put them in ~/fonts/, Getting those fonts was somewhat cumbersome for me: I had to download them manually, unzip them with Termux, put them inside a directory that Emacs had access to (see Android-specific commands and options), then copy them. ~/fonts/,

Note: In my experience, Fonts are not recursively checked inside this directoryThat is, you should place your example ,ttf files inside that folder, not in a subdirectory,

Tip: You can remap the volume buttons

The volume buttons are un-mapped by default (see). android-pass-multimedia-button-to-systemThis is what I have, but if you feel like it, you can reassign them to something else after setting up android-pass-multimedia-button-to-system In a proper way. Some possibilities would be for navigation between headings, more for lists.

conclusion

in conclusion,

  • Make the most of the customized interface. (At least initially – once you’re comfortable in Emacs, you can repurpose it into a more familiar form from the desktop.) init.el,
  • Enable small modes and options specific to touchscreen-powered use.
  • Install a virtual keyboard to gain access to modifiers, function keys, and more.

As of right now I have achieved a set up that I am happy with. I’ve moved the relevant parts of my configuration into org, org-capture, and org-node, but in the future if I need more from Emacs-on-mobile, I’ll consider expanding my configuration as needed. (This includes version-control mine init.el,

And finally: YMMV on other Android devices. My current phone is a OnePlus 7 Pro which runs Android version 12.

Bonus: My Wish List

touchscreen gestures
It has built-in Strokes.L, but Strokes.L, as far as I can tell, doesn’t work for touchscreens. Additionally, making it touchscreen friendly would require significant changes to its code base. So, for now, we have to settle for the virtual keyboard…
Automatic keyboard/IME switching
Ideally, I would have my particular virtual keyboard automatically selected when using Emacs and deselected when not using Emacs. Right now, I have to switch on it manually. As far as I know, there is no easy way to accomplish this.
Large tool bar and menu bar
The tool bar and menu bar are useful, but they’re also small. I want them to be bigger and easier to tap.



<a href

Leave a Comment