From: Mark Walters <markwalters1009@gmail.com>
To: notmuch@notmuchmail.org
Subject: [PATCH] emacs: jump: make multilevel keys do multilevel jump
Date: Sun, 9 Oct 2016 08:37:20 +0100 [thread overview]
Message-ID: <1475998640-25434-1-git-send-email-markwalters1009@gmail.com> (raw)
In-Reply-To: <877f9i459j.fsf@tethera.net>
notmuch jump allows the user to specify a key sequence rather than
just a single key for its bindings. However, it doesn't show what has
already been typed so it can be difficult to see what has
happened. This makes each key press appear, and the jump menu reduce
to the possible follow up keys.
We also bind backspace (emacs symbol DEL) to go back up a level in the
subjumpmaps, and to exit from the top level.
---
This fixes both the bug bremner pointed out about backspace not
working in a terminal and the bug/enhancement about exiting when
backspace is pressed at the top level.
[Note it is possible to (mis)configure a terminal so that this does not
work -- eg by setting backspace to do C-h -- but the standard C-?
should be fine.]
Best wishes
Mark
emacs/notmuch-jump.el | 41 +++++++++++++++++++++++++++++++++++------
1 file changed, 35 insertions(+), 6 deletions(-)
diff --git a/emacs/notmuch-jump.el b/emacs/notmuch-jump.el
index 963253c..de14110 100644
--- a/emacs/notmuch-jump.el
+++ b/emacs/notmuch-jump.el
@@ -104,7 +104,7 @@ not appear in the pop-up buffer.
(copy-sequence minibuffer-prompt-properties)
'face))
;; Build the keymap with our bindings
- (minibuffer-map (notmuch-jump--make-keymap action-map))
+ (minibuffer-map (notmuch-jump--make-keymap action-map prompt))
;; The bindings save the the action in notmuch-jump--action
(notmuch-jump--action nil))
;; Read the action
@@ -161,18 +161,47 @@ buffer."
(set-keymap-parent map minibuffer-local-map)
;; Make this like a special-mode keymap, with no self-insert-command
(suppress-keymap map)
+ (define-key map (kbd "DEL") 'exit-minibuffer)
map)
"Base keymap for notmuch-jump's minibuffer keymap.")
-(defun notmuch-jump--make-keymap (action-map)
+(defun notmuch-jump--make-keymap (action-map prompt)
"Translate ACTION-MAP into a minibuffer keymap."
(let ((map (make-sparse-keymap)))
(set-keymap-parent map notmuch-jump-minibuffer-map)
(dolist (action action-map)
- (define-key map (first action)
- `(lambda () (interactive)
- (setq notmuch-jump--action ',(third action))
- (exit-minibuffer))))
+ (if (= (length (first action)) 1)
+ (define-key map (first action)
+ `(lambda () (interactive)
+ (setq notmuch-jump--action ',(third action))
+ (exit-minibuffer)))))
+ ;; By doing this in two passes (and checking if we already have a
+ ;; binding) we avoid problems if the user specifies a binding which
+ ;; is a prefix of another binding.
+ (dolist (action action-map)
+ (if (> (length (first action)) 1)
+ (let* ((key (elt (first action) 0))
+ (keystr (string key))
+ (new-prompt (concat prompt (format-kbd-macro keystr) " "))
+ (action-submap nil))
+ (unless (lookup-key map keystr)
+ (dolist (act action-map)
+ (when (= key (elt (first act) 0))
+ (push (list (substring (first act) 1)
+ (second act)
+ (third act))
+ action-submap)))
+ ;; We deal with backspace specially
+ (push (list (kbd "DEL")
+ "Backup"
+ `,(apply-partially #'notmuch-jump action-map prompt))
+ action-submap)
+ (setq action-submap (nreverse action-submap))
+ (define-key map keystr
+ `(lambda () (interactive)
+ (setq notmuch-jump--action
+ ',(apply-partially #'notmuch-jump action-submap new-prompt))
+ (exit-minibuffer)))))))
map))
;;
--
2.1.4
next prev parent reply other threads:[~2016-10-09 7:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-08 15:09 feature request: highlighting of partial jump sequences David Bremner
2016-10-08 23:00 ` [PATCH] emacs: jump: make multilevel keys do multilevel jump Mark Walters
2016-10-09 2:37 ` David Bremner
2016-10-09 7:37 ` Mark Walters [this message]
2016-10-09 11:46 ` David Bremner
2016-10-15 11:50 ` Mark Walters
2016-10-16 1:01 ` David Bremner
2016-10-17 17:53 ` feature request: highlighting of partial jump sequences Matt Armstrong
2016-10-18 9:38 ` Mark Walters
2016-10-18 17:07 ` Matt Armstrong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1475998640-25434-1-git-send-email-markwalters1009@gmail.com \
--to=markwalters1009@gmail.com \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).