From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id DEBFC6DE1310 for ; Sun, 9 Oct 2016 00:37:32 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.015 X-Spam-Level: X-Spam-Status: No, score=0.015 tagged_above=-999 required=5 tests=[AWL=-0.115, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id v2nSxg0AL-0H for ; Sun, 9 Oct 2016 00:37:31 -0700 (PDT) Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by arlo.cworth.org (Postfix) with ESMTPS id 361716DE12EB for ; Sun, 9 Oct 2016 00:37:30 -0700 (PDT) Received: by mail-wm0-f66.google.com with SMTP id b201so9298280wmb.1 for ; Sun, 09 Oct 2016 00:37:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ymbR8o6hs4msr2TUM16C0vniR7ON7hW8e5l0NgkR7l8=; b=D7agRvWVcD4FcFiD/WZJh7sCKNxlLhvkgHgNxJTJ/pAT4tdtMWN6CWmohoo4kyt1tx kCIq6lnRgGEpD6BW4S+3aYFsLGk5urPB3fK/cNaCQkYpgDp07JDxYtny0YLb/Paes5PX zGyfcRGZ8Hols7zp6hU/klpjdWYxhPCb9oWdS/asJV4EaZiAunZk6Lht7EFm/4SxuhWT IiVT0CVKdK5pAcMr7QPYHKSK9cvVRd+kS2D/CLM3bHR6Spj9fn22jXGs8PvnfgEbKPqn Hzc9Ygt2PbQeCGmz5xhUgG+X69ppdyOFEtaIVM/CaM7Y+UE7G0KIYydXwDV/OVo+drnh 3DIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ymbR8o6hs4msr2TUM16C0vniR7ON7hW8e5l0NgkR7l8=; b=TbIjLiap1Q1RIZbsNGItuOHFZh6fX58n8wTMhpOgJhudKw+zoF+11VMqMqk3JxPxH1 0EiTRrjmaQg18V8KBWD+JRU3ZQqQS4pbj4at4inlRTT88D8CBhY+LaqsZ0iOP7Fiqx9j 5gVFhRNnAG5220VYs6jQnfsKZLrq1g1SLydiEFCKFg6etBlW/Dc4cCxWjP2hwgEZM6IZ EiGMSa+EDx/jFsXm8ZcUpTlT21uhF/Ync3oOKilVl/bRPrCxi79/3Wk94bDp3DMoAqux MKnkK/xgQaApxBJLJGfkqrnBC4dC+Ap7VuvSNPhADdou0U6VZ3WhkdhX3URwi1qIZ2J/ 0/DA== X-Gm-Message-State: AA6/9RkQAcxIdJi8isJjmhkqOBLC3pI1+Y6QSkU1L+MgAHk6DvZZBCp87w5GhfC5zpr7ug== X-Received: by 10.194.76.68 with SMTP id i4mr26528892wjw.100.1475998647922; Sun, 09 Oct 2016 00:37:27 -0700 (PDT) Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162]) by smtp.gmail.com with ESMTPSA id y39sm11872931wmh.21.2016.10.09.00.37.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Oct 2016 00:37:27 -0700 (PDT) From: Mark Walters To: notmuch@notmuchmail.org Subject: [PATCH] emacs: jump: make multilevel keys do multilevel jump Date: Sun, 9 Oct 2016 08:37:20 +0100 Message-Id: <1475998640-25434-1-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <877f9i459j.fsf@tethera.net> References: <877f9i459j.fsf@tethera.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 09 Oct 2016 07:37:33 -0000 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