]> git.notmuchmail.org Git - notmuch/commitdiff
emacs: add '?' to some prefix keymaps to describe its bindings
authorMark Walters <markwalters1009@gmail.com>
Thu, 14 Nov 2013 09:49:46 +0000 (09:49 +0000)
committerDavid Bremner <david@tethera.net>
Mon, 9 Dec 2013 19:52:54 +0000 (03:52 +0800)
Added function notmuch-subkeymap-help to describe keybindings of a
subkeymap (eg after . or c in notmuch-search and notmuch-show).

emacs/notmuch-lib.el
emacs/notmuch-show.el
emacs/notmuch.el

index 49fe64457b3a03e34241fb6741ebf82f19d9c7cd..2be409b39a1abe1fee91b514ce9f96347eb15644 100644 (file)
@@ -231,7 +231,8 @@ depending on the value of `notmuch-poll-script'."
   "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))))
+  (let* ((key-vector (if (vectorp key) key (vector key)))
+        (desc (format-kbd-macro key-vector)))
     (if (string= desc "ESC")
        "M-"
       (concat desc " "))))
@@ -337,6 +338,28 @@ of its command symbol."
       (set-buffer-modified-p nil)
       (view-buffer (current-buffer) 'kill-buffer-if-not-modified))))
 
+(defun notmuch-subkeymap-help ()
+  "Show help for a subkeymap."
+  (interactive)
+  (let* ((key (this-command-keys-vector))
+       (prefix (make-vector (1- (length key)) nil))
+       (i 0))
+    (while (< i (length prefix))
+      (aset prefix i (aref key i))
+      (setq i (1+ i)))
+
+    (let* ((subkeymap (key-binding prefix))
+          (ua-keys (where-is-internal 'universal-argument nil t))
+          (prefix-string (notmuch-prefix-key-description prefix))
+          (desc-alist (notmuch-describe-keymap subkeymap ua-keys subkeymap prefix-string))
+          (desc-list (mapcar (lambda (arg) (concat (car arg) "\t" (cdr arg))) desc-alist))
+          (desc (mapconcat #'identity desc-list "\n")))
+      (with-help-window (help-buffer)
+       (with-current-buffer standard-output
+         (insert "\nPress 'q' to quit this window.\n\n")
+         (insert desc)))
+      (pop-to-buffer (help-buffer)))))
+
 (defvar notmuch-buffer-refresh-function nil
   "Function to call to refresh the current buffer.")
 (make-variable-buffer-local 'notmuch-buffer-refresh-function)
index 784644cd18f43e85dcbb009b883e9f2f0d59d233..1ac80cac9cba3559a002da14c78b4a6835047ff3 100644 (file)
@@ -1241,6 +1241,7 @@ reset based on the original query."
     (define-key map "t" 'notmuch-show-stash-to)
     (define-key map "l" 'notmuch-show-stash-mlarchive-link)
     (define-key map "L" 'notmuch-show-stash-mlarchive-link-and-go)
+    (define-key map "?" 'notmuch-subkeymap-help)
     map)
   "Submap for stash commands")
 (fset 'notmuch-show-stash-map notmuch-show-stash-map)
@@ -1251,6 +1252,7 @@ reset based on the original query."
     (define-key map "v" 'notmuch-show-view-part)
     (define-key map "o" 'notmuch-show-interactively-view-part)
     (define-key map "|" 'notmuch-show-pipe-part)
+    (define-key map "?" 'notmuch-subkeymap-help)
     map)
   "Submap for part commands")
 (fset 'notmuch-show-part-map notmuch-show-part-map)
index c9bc2f22c7d43a21598e2c189ef6fe3f0f738f5a..047175001c777d0e7fe9dfa26bdb69a0dd668a2d 100644 (file)
@@ -165,6 +165,7 @@ To enter a line break in customize, press \\[quoted-insert] C-j."
 (defvar notmuch-search-stash-map
   (let ((map (make-sparse-keymap)))
     (define-key map "i" 'notmuch-search-stash-thread-id)
+    (define-key map "?" 'notmuch-subkeymap-help)
     map)
   "Submap for stash commands")
 (fset 'notmuch-search-stash-map notmuch-search-stash-map)