Home About Articles Projects Rss


Posted 2013-07-01

I have been using the GNU Emacs editor as of late. I used to use vim, but I recently converted. While I was learning lisp, I used the slime plugin for emacs and from that I got hooked into using the emacs editor.

Key Mappings

I remap several keys to make my editing more comfortable on my laptop keyboard. The gist of the remapping is to put CTRL right next to the space bar, and META to the side of that, two keys away from the spacebar. I accomplished it with the following xmodmap configuration, though you will most likely need to replace the keycodes with the codes for your own system. These can be trivially determined by xev.

There are a number of reasons for this swap. They better reflect the placement of the CTRL and META keys on the system which emacs was originally designed on. CTRL is more of a primary key than META and typed more often, so it is important that the CTRL key be in a convenient position. See http://xahlee.info/kbd/keyboard_hardware_and_key_choices.html for more details. Some users prefer to map the caps lock key to ctrl, but I found this mapping uncomfortale for chording. Additionally, having just one ctrl key violates the separation of modifier keys, namely that you should press the modifier key with one hand, and the key being modified with the other. Another keymapping I use is I swap the backspace and caps lock keys. When I used vim I put Esc in the caps lock position, as this makes it easier to change modes and is better reflecting of the original keyboard it was developed on. However, as I don’t use Esc nearly as much in emacs, I have moved the backspace here.

I find that typing the enter and backspace keys is especially uncomfortable on my pinkies. I’ve remapped them into more comfortable positions, although this is most certainly nonstandard, it is not unprecedented. For example, on the lisp machine keyboard there is a “rub-out”, presumably delete where the modern caps lock key is today.

I would like to have a better position for the enter key as well, but I have not found a suitable position for it.

My .Xmodmap:

clear Control
clear Mod1
clear Mod4
clear Lock

! windows key becomes alt
keycode 133 = Alt_L
keycode 37 = Super_L

! printscreen key becomes alt
keycode 134 = Alt_R
keycode 105 = Super_R

! alts become control
keycode 64 = Control_L
keycode 108 = Control_R

! caps lock becomes backspace
! backspace becomes caps lock
keycode 66 = BackSpace
keycode 22 = Caps_Lock

add Control = Control_L Control_R
add Mod1 = Alt_R Alt_L
add Lock = Caps_Lock
add Mod4 = Super_R Super_L

The original keyboard mapping can be restored, by running the command setxkbmap -layout us . However if you are not using a us keyboard, replace layout by the appropriate layout for your keyboard.

Emacs Settings

For Lisps

When working with languages in the lisp family (Common Lisp, Scheme, etc) there are a couple different extensions I just love having. Most essential are a structural editor and a REPL integration plugin.

A structural editor allows you to edit the lisp source code based on the lisp native structure, the parenthesized S-expression. For this purpose I like to use Paredit. Paredit allows you to easily move expressions and sub-expressions in and out of lists, merge and split lists, increase/decrease expression nesting levels, automatically balance parentheses and much, much more.

A REPL integration plugin allows you to use emacs to interact with your lisp implementations REPL, the read eval print loop, or for you lispers out there (loop (print (eval (read)))). This makes emacs very powerful for interactive programming, and incremental development. You can evaluate changes to single functions and play around with each function very easily and flexibly. It’s interesting how much more productive you can be when you can see the result of your changes without waiting for your whole program to compile, and how much more power this gives you when writing your code.

For Common Lisp, I use slime for REPL integration. Really for Common Lisp. this is pretty sure the only good option, and it’s more than good… it’s great. For scheme, I use geiser. There is another useful plugin called quack which other people are very excited about, but I prefer geiser. quack does some things that geiser does not, but geiser is more similar to slime, and does pretty much all I need it to. I may look more into quack in the future, but right now geiser is satisfactory.


For my color scheme, I like zenburn.

For intelligent soft line wrapping, I use Visual Line Mode, and for line numbers I use Global Linum Mode.

comments powered by Disqus

Copyright © 2013 - 2016 Nate Craun. This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.