-(defun notmuch-documentation-first-line (symbol)
- "Return the first line of the documentation string for SYMBOL."
- (let ((doc (documentation symbol)))
- (if doc
- (with-temp-buffer
- (insert (documentation symbol t))
- (goto-char (point-min))
- (let ((beg (point)))
- (end-of-line)
- (buffer-substring beg (point))))
- "")))
-
-(defun notmuch-prefix-key-description (key)
- "Given a prefix key code, return a human-readable string representation.
-
-This is basically just `format-kbd-macro' but we also convert ESC to M-."
- (let ((desc (format-kbd-macro (vector key))))
- (if (string= desc "ESC")
- "M-"
- (concat desc " "))))
-
-(defun notmuch-describe-keymap (keymap &optional prefix tail)
- "Return a list of strings, each describing one key in KEYMAP.
-
-Each string gives a human-readable description of the key and the
-first line of documentation for the bound function."
- (map-keymap
- (lambda (key binding)
- (cond ((mouse-event-p key) nil)
- ((keymapp binding)
- (setq tail
- (notmuch-describe-keymap
- binding (notmuch-prefix-key-description key) tail)))
- (t
- (push (concat prefix (format-kbd-macro (vector key)) "\t"
- (notmuch-documentation-first-line binding))
- tail))))
- keymap)
- tail)
-
-(defun notmuch-substitute-command-keys (doc)
- "Like `substitute-command-keys' but with documentation, not function names."
- (let ((beg 0))
- (while (string-match "\\\\{\\([^}[:space:]]*\\)}" doc beg)
- (let* ((keymap-name (substring doc (match-beginning 1) (match-end 1)))
- (keymap (symbol-value (intern keymap-name)))
- (desc-list (notmuch-describe-keymap keymap))
- (desc (mapconcat #'identity desc-list "\n")))
- (setq doc (replace-match desc 1 1 doc)))
- (setq beg (match-end 0)))
- doc))
-
-(defun notmuch-help ()
- "Display help for the current notmuch mode."
- (interactive)
- (let* ((mode major-mode)
- (doc (substitute-command-keys (notmuch-substitute-command-keys (documentation mode t)))))
- (with-current-buffer (generate-new-buffer "*notmuch-help*")
- (insert doc)
- (goto-char (point-min))
- (set-buffer-modified-p nil)
- (view-buffer (current-buffer) 'kill-buffer-if-not-modified))))
-