emacs

2014-11-11

Emacs Lisp and the ability to hack Emacs like a REPL on steroids is probably Emacs' greatest feature from my perspective. I enjoy the immediacy of hacking Emacs in Emacs every time. As I started to clean up my .emacs.d recently, I enjoyed writing a couple of extensions myself. This post introduces each one briefly. Maybe some of these extensions are useful to you as well or trigger your interest to hack on some yourself :)

basic theme

As I started with a clean slate, I didn't have major modes installed for some of the languages I work with daily. Funnily enough, I enjoyed the lack of colors and am still practicing abstinence today ;) Controversial I bet, but it works for me at the moment. I generally try to reduce the UI noise, much like Bastien's #Emacs, naked. I wrote the minimal fgeller/basic-theme.el to accomodate this. Here's the *scratch* buffer after startup:

basic theme: scratch buffer

Not much changes visually when editing Emacs Lisp:

basic theme: Emacs Lisp

Notice that the mode-line is nearly entirely hidden. I use a little helper to make it visible from time to time. Check out fgeller/basic-theme.el for the basic idea.

highlight-thing

While I disable the font-lock machinery globally to prevent syntax highlighting, the UI is not fully monochrome. Certain elements are still colorized to facilitate reading and finding patterns.

One package I used previously is the excellent nschum/highlight-symbol.el that highlights the symbol under point and the other occurrences of it in the current buffer. However, it relies on font-lock for highlighting, which I'm trying to get around. So I wrote a very simple global minor mode that does just this, highlight the current symbol or word under point: fgeller/highlight-thing.el.

highlight-thing

This allows me to quickly find occurrences of a variable or function name. The minor mode uses only built-in functionality and is very lightweight (~50 lines of code). There are plenty of solutions that are more sophisticated (e.g. nschum/highlight-symbol.el which also adds helpers for navigation, or boyw165/hl-anything which introduces more detail control over what to highlight when and how to get around multiple highlights conflicting with each other), but I enjoy the simplicity of highlight-thing.

fingers

The last extension is the result of trying multiple other modes to get around the infamous pinky or modifier problem. I had used chrisdone/god-mode happily for a while: It allows for a comfortable transition to modal editing. When enabled, all commands that require the control modifier C- are available as if C- was pressed. So to move point a line up and then down again you can press pn rather than C-p C-n. Other prefixes like M- and C-M- are also conveniently accessible via the g and G prefix.

I recently tried jyp/boon which requires a bigger step by introducing entirely new bindings for navigation and text manipulation. Rather than relying on Emacs' bindings that are mostly based on mnemonics, boon adds key bindings that are organized with ergonomics in mind and several helpful text manipulation commands. For example, navigation commands are bound to your right hand: home row allows for navigation within a line, the top row allows for navigation across lines. I enjoyed the ideas quite a bit, but found it rather hard to extend boon. It is optimized for the Colemak keyboard layout and I found no easy mapping mechanism.

Standing on the shoulders of both giants, I wrote fgeller/fingers.el. It combines ideas from both god-mode and boon. For example, navigation and text manipulation is split between right and left hand like for boon and you can access commands that require the M- prefix similarly to god-mode. fingers-mode has no external dependencies and I try to limit the bindings to what is generally applicable. This is a short demo of some of the text manipulation commands as discussed in the README:

fingers-mode

The README contains more details and examples and I added mappings for Qwerty and Neo, so maybe give it a try and let me know what you think :)

publish

All three can be installed by cloning the respective repository and adding it to your load-path manually. fingers.el is already available via MELPA, and the other two packages may soon be available too.

If you're curious, the process of adding a package to MELPA was straight-forward and smooth:

  • Fork milkypostman/melpa
  • Add a recipe of the form (name :fetcher github :repo "fgeller/name.el")
  • Package it locally: make recipes/name
  • Inspect and install it locally in a sandbox: EMACS=~/bin/emacs make sandbox
  • Commit to a new branch and push it to your fork
  • Create a pull request against upstream.
  • Voilà!

That's it, happy Emacs hacking :)