Sunday 21 December 2014

Emacs and (synchronised) org-mode on Android

Running emacs and org-mode under Android. I’m doing this on my Android tablet - it’s not perhaps as useful on a phone, though it’s not unmanageable.

There used to be an Emacs app for Android in the Google Play store - in fact it’s still there, but the server it used to download its files from is no longer working - and the app was always a bit fiddly to get to work properly.

Here’s a better way of getting it working:
  • Install ZShaolin, a console terminal emulator (zsh shell) for Android with a number of useful commandline tools like rsync, awk, imagmagick etc.
  • Then install the files from the old Emacs app. They’re no longer accessible via the app from the Play store, but I had saved the files from back when it still worked, and have zipped them up and thrown them on mega: https://mega.co.nz/#!B4AThKxI!_ImT57mJNirozxna-1SOcNGAzPRr9QacM34jUoPVMgo
  • Unzip the files from there and place at /sdcard/emacs/ on your device.
  • Then, open up ZShaolin and start a session, and type “emacs”. VoilĂ .
Now for getting org-mode to work. Org-mode is part of the basic Emacs setup in recent versions of Emacs (including the one above). For some reason, though, at least when I ran it, I had trouble turning on org-mode. Here’s the fix:
  • Create a .emacs file (if you don’t have one already) in ~ under ZShaolin and put the following into:
(defun load-history-filename-element (file-regexp)
  "Get the first elt of `load-history' whose car matches FILE-REGEXP.
        Return nil if there isn't one."
  (let* ((loads load-history)
         (load-elt (and loads (car loads))))
    (save-match-data
      (while (and loads
                  (or (null (car load-elt))
                      (not (and (stringp (car load-elt)) ; new condition
                                (string-match file-regexp (car load-elt))))))
        (setq loads (cdr loads)
              load-elt (and loads (car loads)))))
    load-elt))
That gets org-mode to work as expected.
fh9YvOc.png
Figure 1: Emacing an org file on Android (with ZShaolin)

Now, most likely you will have org-files that you want to keep synchronized. You may already be running MobileOrg, with something like a Dropbox synchronisation. Note that the way that the MobileOrg app works, you can’t edit the org files that it uses directly. MobileOrg utilises some sort of database and the changes that it pushes back are done so through the database, so editing the org files that MobileOrg is synched with (say, in Dropbox) won’t result in any changes being propagated back to your other devices.

So, if you’re running MobileOrg with Dropbox, you’ll need to have a separate Dropbox synchronisation in order to be able to edit org-files in Emacs on Android in a way that allows for propagation of changes from Android to other devices/repositories.

Here’s a method which allows for editing of org-mode files on Emacs which allows for back-propagation via Dropbox:
  • Create a separate Dropbox synchronisation directory - that is, separate from the one you use for MobileOrg synchronisation. [The way I did this on my Linux desktop was to create a symlink from my “Org folder” in my Documents directory to the “actual” Org directory in my Dropbox folder. In my setup, this directory also synchs with a git repository, so I ended up excluding the hidden .git directory from synching with Dropbox, since I have only a free, very-limited-space Dropbox account.]
  • Open up the Dropbox app on your Android device. Navigate to your new Org directory (not the one you use for MobileOrg). “Open” any of the org files you want to have access to. It doesn’t matter if they successfully open or not - the act of “opening” them gets the Dropbox app to save a local copy which it will keep synchronised with your Dropbox repository.
  • The location for these local files is a path like this: /sdcard/Android/data/com.dropbox.android/files/u87923223/scratch/YourOrgDirectoryName/ the u-number part of the path I assume varies from user to user; and of course the final part of the path will depend on what you named your Org folder and files
  • Files in the above path can be opened in Emacs on Android. Any changes you make will be propagated via Dropbox.
Again, this will be perhaps of limited use on a phone — though ZShaolin does have a built-in software keyboard which works very well for Emacs — on a tablet device with a keyboard (I use an Asus tablet) it works pretty well. (Though I haven’t figured out how to remap CAPSLOCK on my tablet to CTRL yet….)

Saturday 20 December 2014

In praise of DejaVu (Sans Mono)

I do the majority of my work in Emacs - from the composition of linguistics articles and chapters, to lecture slides, to keeping track of grades, to email. Much of what I do requires a monospaced font, and much of what I do requires a good Unicode font. Which narrows the range of potential font candidates significantly. And, since I spend so much time looking at it, I would like the font to be aesthetically-pleasing.
After trying many different fonts, at different sizes and so forth, I’ve found that DejaVu Sans Mono is really the only font which meets all of these criteria. It is really a good-looking font too. Here it is in a few different applications:

Figure 1: DejaVu Sans Mono in mu4e mail
cMMuHWf.png
Figure 2: DejaVu Sans Mono in LaTeX doc
ox7g0FF.jpg
Figure 3: DejaVu Sans Mono displaying some Unicode
And…it appears to be the same font used in the terminal in Tron: Legacy:
TRON_EMACS.JPG
Figure 4: kill -9ing in Tron: Legacy with DejaVu