Emacs on the iPad

The iPad Pro has more people considering using the iPad for production, not just for entertainment. I have long been jealous of those who could use an iPad for most of their work, especially now, as iPad displays get bigger and nicer. I would love to be able to throw an iPad and keyboard into a small bag and be able to use the same tool for both reading and writing.

Unfortunately, though, two things have kept me from being able to easily do that. First, I do almost of all my work in Emacs, and I’m afraid that Apple would never allow Emacs on the iPad. Second, except for blog posts, almost everything I write eventually becomes a LaTeX document that is compiled into a PDF.

I’m sure that most people wouldn’t be troubled at all by either of these problems. My projects usually begin as Markdown files, and there are some decent Markdown editors on iOS. Most of these are limited to using one subfolder in Dropbox, and I have a folder for each course, writing project, my website, etc. A larger problem is that Emacs becomes a finely tuned, personal tool for a user. With one keystroke, I can renumber ordered lists, insert a reference from my bibliography database, commit changes to a git repository, and many other things. Once this has become ingrained, it is very difficult to go to anything else. I can write LaTeX on the iPad, but I can’t compile. That still has to be done on another machine. So, while others are carrying their nice, light tablets, I’ve been schlepping a MacBook Pro.

A few days ago, I noticed that Digital Ocean has a remote server plan with 20 GB of solid state storage for five dollars a month. It only has 512 MB of memory, but that seems to be plenty for Emacs and Vim. I signed up, started a machine, and installed Ubuntu. I installed Emacs, Vim, Pandoc, and LaTeX. I changed the shell to the fish shell, and moved all of my configuration files. Since the configuration files are all on Github, moving them to the machine was simple.

So, the good news is that I’m now writing this in Emacs on the iPad. The bad news is, since I had given up being able to use the iPad to write, I traded in my larger iPad for an iPad mini. Now, I really will be looking longingly at those iPad Pros I see at Starbucks.

LaTeX-Skim Sync

I recently started using John Wiegley’s use-package for my Emacs init files. For Auctex, I used

(use-package texn    :ensure auctex)

and everything worked except for sync with Skim on OS X. C-c v would not launch the Skim, even though I was confident that the Skim was set to be the default viewer. Instead, no viewer would launch, and I’d see “View command: dvi2tty -q -w 132” in the minibuffer.

After seeing that some others had used a slightly different configuration, I changed mine to

(use-package tex-siten    :ensure auctex)

and everything started working fine. I still have no idea why, but it may help someone else.

Using Marked with Emacs

It’s time to revisit a subject I covered in 2014, using Emacs to open a Markdown file in Marked, an excellent Markdown previewer for OS X.1 I have used two different methods of opening files in Marked from Emacs, both of which have respective advantages.

The first is a function expressly for opening files in Marked. Add the following code to your emacs init file, and then press “Control-c m” to open the current file in Marked.

(defun markdown-preview-file ()n  "run Marked on the current file and revert the buffer"  (interactive)n  (shell-commandn   (format "open -a /Applications/Marked 2.app %s"           (shell-quote-argument (buffer-file-name))))n  )nn(global-set-key "C-cm" 'markdown-preview-file)

The second is a function for opening files in the default application for that type of file. This is part of Bozhidar Batsov’s Emacs Prelude starter kit, which I highly recommend. Again, add the following to your init file:

(defun open-with (arg)n  "Open visited file in default external program.When in dired mode, open file under the cursor.With a prefix ARG always prompt for command to use."  (interactive "P")n  (let* ((current-file-namen          (if (eq major-mode 'dired-mode)n              (dired-get-file-for-visit)n            buffer-file-name))n         (open (pcase system-typen                 (`darwin "open")n                 ((or `gnu `gnu/linux `gnu/kfreebsd) "xdg-open")))n         (program (if (or arg (not open))n                      (read-shell-command "Open current file with: ")n                    open)))n					(start-process "prelude-open-with-process" nil program current-file-name)))nn(global-set-key (kbd "C-c o") 'open-with)

The second method is what I currently use. “Control-c o” opens the current file in the default application, which is set in the system. In order for it to work with Markdown files, you’ll need to make Marked the default application for Markdown files, which means that to open a file for editing from the Finder, you’ll need to right-click and select “Open With.” The advantage is that you can use the same command from Dired to open PDF’s in your preferred PDF reader, Word docs in Word, etc.

  1. Its excellence lies partly in the fact that it’s not simply a previewer, it also does many other things, like word count, reading analyses, and link validation. [return]

Open Dired From Shell

I was browsing the interwebs this morning, looking for a way to open a Dired buffer of the current finder window. There is a lot on going the other way, from Emacs to the Finder, but nothing from the Finder to Emacs. I got this from Fortune Datko:

Add this to your shell rc file (in my case, .zshrc):

# open a dired window for the current directoryndired() {n    emacsclient -e "(dired "$PWD")"n}n

Then, assuming that Emacs server is running, type “dired” in the shell, and a Dirednbuffer of that directory opens in the current Emacs frame.

Just out of curiosity, I wondered what typing “emacsclient -c .” would do. It opens a dired buffer in a new frame. I have a shell script called “ec” that starts a new emacs client, but it’s easy to do it with a zsh alias:

alias ec="emacsclient -c -a ''"n

This starts a server if there is not one already, then opens a new client. So, typing ec . should then open a Dired buffer in a new frame.

Emacs on OS X


I install Emacs with Homebrew. After installing Homebrew, just type the following in Terminal:

brew install emacs --cocoa

This makes upgrading very easy, brew upgrade updates everything that you’ve installed in Homebrew. It also keeps things nicely organized in /usr/local/Cellar/ and puts symbolic links in /usr/local/bin/. After installation, you have two options for getting Emacs into your Applications directory. First, Homebrew can put a link there with brew linkapps Emacs. Second, you can copy Emacs to /Applications with

cp -r /usr/local/Cellar/emacs/24.5/Emacs.app /Applications/


I use Emacs Prelude, a starter kit by Bozhidar Batsov. There are many Emacs users that advocate setting up your own configuration from scratch, and I’ve done that many times. I keep coming back to Prelude, though, it just makes the initial work so much easier. Prelude includes a personal directory for individual configuration files. I keep all of those files in a git repository located in Dropbox with symbolic links in the Prelude personal directory. That way, I can use Github for version control, but have all machines in sync with no effort.

There are two important files in my personal directory. The first is an emacs-lisp file containing this:

;;Load emacs personal settings via orgn(prelude-require-package 'org)n(org-babel-load-filen(expand-file-name "personal/settings.org" user-emacs-directory))n

This file loads an org-mode file that contains the actual configuration. If you’d like to see it, it’s all here on Github.

Starting Emacs

I like to start Emacs using the daemon, which keeps an Emacs server running in the background, then connect to that server with Emacs Client. This makes opening Emacs nearly instantaneous.

In the past, I’ve done this from the terminal by putting with these aliases in my zshrc:

alias daemon="emacs --daemon"

alias ec="emacsclient -c -a ''"

alias ef="emacsclient -c -a '' -F '((fullscreen . maximized))'"

alias e="emacsclient -t"

The first simply starts the server. I never used it, because the second would connect to the server one were already running, otherwise, it would start one, then connect to it. The third does the same thing, but starts an Emacs client with a maximized frame.

This worked well, but I usually use Alfred to start applications, not the terminal. After trying many options, I ran across these instructions by Jesse Haber-Kucharsky. I created the Emacs Daemon application with one change, instead of using Emacs in /Applications, I had the script point directly to /usr/local/bin/ instead. I created the three shell scripts as directed, but instead of the Emacs-Cocoa application, I created one called “Emacs Client” that started the “ec” script. The daemon runs at startup, then I call Emacs Client from Alfred whenever I want to start Emacs.

There are parts of this that I really didn’t need to do, but too much is better than not enough, I suppose.

Stringp, Nil Error in Emacs

This is one of those posts that serve only to remind me of something in the future. My Emacs configuration was working well on one machine. Whenever I opened dired on another machine, though, this error was returned:

wrong type argument: stringp, nil

Finally, I remembered that I had required GNU ls in my Emacs settings, and had not installed it on the machine in question. A quick “brew install coreutils” to install the GNU Command Line Tools with Homebrew did the trick.

Back to Emacs Prelude

As I said a few days ago, I switch my Emacs config files to Kieran Healy’s Starter Kit. I really liked the use of Org-mode for the config, and especially the LaTeX and RefTeX configuration. I still like Batsov’s Prelude, though, and there were certainly some things that I missed greatly.

This afternoon, I found Mike McFarland’s Emacs configuration online. He uses Prelude with a personal configuration in Org-mode. I have switched back, and brought in much of Kieran’s LaTeX configuration.

You can see the results here, although it’s not now as literate as I hope it will be.

Emacs Starter Kit

The first week of a break from classes is always a good time for a massive reconfiguration of something tech-related. Last time it was the blog, this time it is Emacs. Since I primarily use Emacs only for LaTeX and Markdown editing, I though I would give Kieran Healy’s Emacs Starter Kit for the Social Sciences a try. He has done a masterful job of setting up a great LaTeX editing machine. Easy to install, and easy to customize.