Monday, April 16, 2012

Move personal bindings to Hyper- in emacs

I guess everybody who heavily use emacs has a number of his / her own key-bindings. Unfortunately, personal key-bindings (if not too long) could conflict with system ones. If not in one mode, it would happen in another mode.

Now I am happy with my solution: I map left alt to Hyper, and  then bind everything personal to Hyper. The mapping can be done in xmodmap: create a file, say, .Xmodmap, with
clear Mod1
add Mod1 = Alt_L
add Mod3 = Hyper_L
add Mod4 = Super_L
keycode 108 = Hyper_L
Then run xmodmap .Xmodmap (and put it to startup applications so it runs every time when login).

Then in .emacs, set every key-binding you like with Hyper (I set a lot of them. Here are only some samples):
(global-set-key (kbd "H-g") 'goto-line)
(global-set-key (kbd "H-l") 'forward-char)
(global-set-key (kbd "H-h") 'backward-char)
(global-set-key (kbd "H-j") 'next-line)
(global-set-key (kbd "H-k") 'previous-line)
(global-set-key (kbd "H-\\") 'math-eval)
(global-set-key (kbd "H-p") 'my-org-screenshot)
(global-set-key (kbd "<H-SPC>") 'save-buffer)
(global-set-key (kbd "<H-escape>") '(lambda ()   (interactive)   (kill-buffer (current-buffer))))
Another advantage is that I press left alt using thumb. Thumb is much stronger than little figure for frequent use :)