spnw*

Quicker access to Emacs Info manuals

Pressing C-h r to open the main Emacs manual is handy. Having to use info-display-manual for the others is a bit less so — you have to type (or at least complete) the manual’s name, and you can’t jump straight to a given section.

My solution is to rebind C-h r to a custom dispatch function. This lets me press e.g. C-h r l for the Elisp manual or C-h r d for the Dired section of the Emacs manual. Pressing C-h at the prompt reminds me what my options are.

(defvar my-display-manual-alist
  '((?r . "emacs")
    (?l . "elisp")
    (?d . "(emacs)dired")))

(defun my-display-manual-help ()
  (mapconcat (lambda (x) (format "[%c] %s\n" (car x) (cdr x)))
             my-display-manual-alist))

(defun my-display-manual ()
  (interactive)
  (info
   (cdr
    (assoc (let ((help-form '(my-display-manual-help)))
             (read-char-from-minibuffer
              "Display manual: "
              (mapcar #'car my-display-manual-alist)))
           my-display-manual-alist))))

(keymap-global-set "C-h r" #'my-display-manual)