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 390C06DE12E1 for ; Sat, 8 Oct 2016 16:00:25 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.014 X-Spam-Level: X-Spam-Status: No, score=0.014 tagged_above=-999 required=5 tests=[AWL=-0.116, 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 WODdrEDYC__w for ; Sat, 8 Oct 2016 16:00:24 -0700 (PDT) Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by arlo.cworth.org (Postfix) with ESMTPS id 506EF6DE12DD for ; Sat, 8 Oct 2016 16:00:24 -0700 (PDT) Received: by mail-wm0-f65.google.com with SMTP id b201so8382373wmb.1 for ; Sat, 08 Oct 2016 16:00:24 -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=4+nG6QHaHop3LsLKiZCitvr5Fp8QUGgAZCfCd/7OGcs=; b=SrMkCgXtMtOXh7oUjMdxtVenLSxpUJ+a9avzGMXVAbG/hUMCDCD8BEIn2Q83KMULn6 HHGnvIZiDrzrSFXrUD72Jxa7884tSHrTKNfnsxkG+nbYiP85Gl5wr8MeAsnFDhUL2EYy LhZJafqSsVtsXfm+frWYTK7mAUXNanlrgDBnPD6NZvs53slTtDLA9KNwAPU//bwUrsJ3 2cqenyJaKAwmxiKow44donsQR8wxpY+nPWHpHYiK1ocW8MWo/pJul3Pm01hPZHiLzcG9 lSioigTQFLTVdYTKX0lRd613hxIfpxEZNrIJ3qWKKu2Dmkp27ZqS7XPrjwP9lmjTCQ6q X72A== 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=4+nG6QHaHop3LsLKiZCitvr5Fp8QUGgAZCfCd/7OGcs=; b=SB2jnN71fT+u15JcORmmGA3rXayxDst5ixH/dtB07xDcCigs+s7bJ//AKnfWsmxjgu xW54jz7rUY9xYy2QE9GFhhcUGyOS3UcJhtTe4z54CMDlsfozWfxWpURa2SkgAIeWmltc e7EnrqZXHFPJGOg1krdFJJh9MiZgUpwbT9dpxUWAnhx7PEZcEdmhljx/z/AJZrvPjRl+ QnAQrzkxCxk046M1nmBGaH4EN5RxXFU231XryybKsbU1/l1T26xK5Whfz4EHg4XZa7YZ 6XNaejtaKEQpQ/2ac0awos/OUaSosPKgOKSR953NyPt4M7WJ9eFLgArVfvCnNuoegGD4 nUpw== X-Gm-Message-State: AA6/9RmtoyG81yY0L4ozilnjU5UoR6pgoqb4JQ7uLEJ0hvYoMtIpNpi1BOSbbHL14OgJWA== X-Received: by 10.28.199.204 with SMTP id x195mr4710772wmf.41.1475967622995; Sat, 08 Oct 2016 16:00:22 -0700 (PDT) Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162]) by smtp.gmail.com with ESMTPSA id uq6sm26945289wjc.37.2016.10.08.16.00.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Oct 2016 16:00:22 -0700 (PDT) From: Mark Walters To: notmuch@notmuchmail.org Subject: [PATCH] emacs: jump: make multilevel keys do multilevel jump Date: Sun, 9 Oct 2016 00:00:19 +0100 Message-Id: <1475967619-24268-1-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <8737k6andm.fsf@zancas.localnet> References: <8737k6andm.fsf@zancas.localnet> 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: Sat, 08 Oct 2016 23:00:25 -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. --- bremner pointed out that multi-key key sequences were unclear in tag-jump (and other jump uses). This makes it clearer by displaying the keys typed so far and reducing the displayed options based on what has been typed so far. Backspace is bound to remove the last typed character and return to the previous level. Slightly unfortunately emacs likes to call backspace "DEL". There is noticeable increase in the complexity of the jump code. However, in the common case of all key sequences being single keys then it looks exactly as before. Finally there are a couple of corner cases that are of the form "don't do that". The first is if the user specifies two bindings one of which is a prefix of the other (I don't know what happens before but we now just take the shorter one). The second is that the user can't bind backspace in any submap (i.e. as the second or subsequent key of a key-sequence) as it is used for going back up a level. Best wishes Mark emacs/notmuch-jump.el | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/emacs/notmuch-jump.el b/emacs/notmuch-jump.el index 963253c..b7df1c2 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 @@ -164,15 +164,43 @@ buffer." 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 "") + "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