#+TITLE: My Emacs on Android Setup #+DATE: 2020-09-12T16:37:38-04:00 #+DRAFT: false #+DESCRIPTION: A quick walkthrough of how I use Emacs on my Android tablet #+TAGS[]: emacs android termux #+KEYWORDS[]: emacs android termux #+SLUG: #+SUMMARY: #+ATTR_HTML: :title Android, Termux, and Emacs #+ATTR_HTML: :alt Android, Termux, and Emacs [[file:cover.png]] Not too long ago I purchased a Samsung Galaxy Tab A. I bought it mostly for browsing the internet and reading PDFs, but I've been using it a lot more for working in Emacs recently. With the help of [[https://termux.com/][Termux]], I've gotten more or less a fully functional development and writing environment which has both a small physical size, and long battery life. With the use of a bluetooth keyboard, I have everything required to work, and comfortably at that. I use the HHKB Professional Hybrid, which I highly recommend for the task. It's nearly impossible to properly rebind keys on Android, and I need the control key to be in the place of caps lock to be effective at using Emacs. In addition, I have a stand case for my tablet, so it is able to sit up in landscape mode by itself. It's also possible to connect a bluetooth mouse, then to enable =xterm-mouse-mode= in Emacs, but I rarely find that necessary. Thanks to the mostly frontend agnostic nature of Emacs, everything I would normally do on my desktop computer or laptop work almost identically when working from within Termux. I actually often find it much easier to write on my tablet than I do on my computer, since the fullscreen nature of Termux tends to stop me from getting distracted by other things I'm working on in the background. #+ATTR_HTML: :title Emacs in Termux #+ATTR_HTML: :alt Emacs running on termux, showing the Emacs welcome screen [[file:termux emacs screenshot.jpg]] The first thing I had to do was install Emacs and git, which are as easy as running a single command. #+BEGIN_SRC shell pkg install emacs git #+END_SRC Since I host my Emacs configuration on [[https://github.com/dantecatalfamo/emacs.d][GitHub]], getting things started here is effortless. All I had to do was clone it onto my system, and open Emacs. It completely sets itself up courtesy of =use-package=, which installs all the required packages and dependencies without requiring my intervention. Because I host my blog's contents in a git repository as well, I'm also able to clone that and work on it using the =hugo= package. #+BEGIN_SRC shell pkg install hugo #+END_SRC I can even run the development server in a =shell= buffer in Emacs and check out how the post I'm writing looks in Firefox, all on the tablet. In fact, this post itself was written entirely from my tablet! From there I'm able to much of the same things as I do anywhere else. For writing C, I installed =clang= and =gdb=, which are both available from the default repo as well. #+BEGIN_SRC shell pkg install clang gdb #+END_SRC This setup works particularely well because of Emacs' excellent =gdb= debugging interface. Thanks to not needing any sort of graphical interface beyind Emacs, my ability to get things done is completely unhindered. I'm a huge fan of =gdb= mode, especially with =(setq gdb-many-windows t)=. #+ATTR_HTML: :title An example gdb session in Emacs #+ATTR_HTML: :alt An example gdb session in Emacs [[file:termux emacs gdb screenshot.jpg]] I'm also able to work on my org documents, which I store in a personal Nextcloud instance, thanks to =rclone=. I have two small scripts which I've written so I'm able to sync the files before I start editing them, and after I'm done. Setting up =rclone= to work with my nextcloud instance is incredibly easy and only took me a minute using [[https://rclone.org/webdav/][this]] guide from the =rclone= website. Both scripts are incredibly simple, consisting mainly of a single line each. =nextcloud-pull.sh= #+BEGIN_SRC shell #!/bin/sh echo echo "############################" echo "## PULLING FROM NEXTCLOUD ##" echo "############################" echo rclone sync -i nextcloud:Org Org #+END_SRC =nextcloud-push.sh= #+BEGIN_SRC shell #!/bin/sh echo echo "##########################" echo "## PUSHING TO NEXTCLOUD ##" echo "##########################" echo rclone sync -i Org nextcloud:Org #+END_SRC There's even a spectacular third-party repository called [[https://github.com/its-pointless/its-pointless.github.io][its-pointless]], which provides tools which aren't available in the main Termux repo. Perhaps most importantly from an Emacs perspective, they provide =ecl=. Because of this, I'm able to have a full interactive Common Lisp development environment on my tablet. There's something about that I find really cool! Of course because of how =ecl= works, the first time I launched =sly= it took a couple seconds while =ecl= compiled everything. Something which is important to note is that even though it's not installed as a dependency by default, =ecl= requires the =libatomic-ops-dev= package in order to function correctly. They also provide an up to date version of [[https://raku.org/][Raku]], a language which I really enjoy toying around with, along with [[https://julialang.org/][Julia]], [[https://www.gnu.org/software/octave/][octave]], and [[https://www.r-project.org/][R]], among other things. One shortcoming of running my large Emacs configuration on such a low power device is that it can take a couple of seconds to start the first time. Fortunately =emacsclient= works perfectly in Termux, so I'm able to simply launch the Emacs daemon in the background when I fist launch it. I have an alias in my =.bashrc= to do this automatically. #+BEGIN_SRC shell alias em="emacsclient -c -t -a ''" #+END_SRC I just call =em= instead of =emacs= when I want to edit a document. It will either open a new frame connected to an already running Emacs daemon, or launch the daemon, and then connect once it's started. I'm still working out the kinks in my setup, but I'm overall extremely pleased with how well it works.