Endless Parentheses

Ramblings on productivity and technical subjects.

profile for Malabarba on Stack Exchange

The Toggle-Map and Wizardry

I love intuitive keymaps. Some are so perfect, you just can’t avoid mouthing the words every time you hit that blissful combo. A wizard murmuring an incantation under his breath as his fingers draw the arcane patterns.

The following keymap toggles some options which tend to be useful throughout a session.

(define-prefix-command 'endless/toggle-map)
;; The manual recommends C-c for user keys, but C-x t is
;; always free, whereas C-c t is used by some modes.
(define-key ctl-x-map "t" 'endless/toggle-map)
(define-key endless/toggle-map "c" #'column-number-mode)
(define-key endless/toggle-map "d" #'toggle-debug-on-error)
(define-key endless/toggle-map "e" #'toggle-debug-on-error)
(define-key endless/toggle-map "f" #'auto-fill-mode)
(define-key endless/toggle-map "l" #'toggle-truncate-lines)
(define-key endless/toggle-map "q" #'toggle-debug-on-quit)
(define-key endless/toggle-map "t" #'endless/toggle-theme)
;;; Generalized version of `read-only-mode'.
(define-key endless/toggle-map "r" #'dired-toggle-read-only)
(autoload 'dired-toggle-read-only "dired" nil t)
(define-key endless/toggle-map "w" #'whitespace-mode)

There are eight keys being defined there, most of which aren’t even used every day, but I know I’ll never forget a single one. That is the beauty of mnemonics.

Doesn’t “Emacs, toggle column” just roll off your tongue as you’re typing C-x t c? I feel like I’m commanding the strands of reality, but that could just be my D&D past taking the better of me.

Also note: The manual recommends C-c for user keys, but I like using C-x for global keys and using C-c for mode-specific keys.

comments powered by Disqus