From: Mark Walters Date: Fri, 8 Nov 2013 17:40:14 +0000 (+0000) Subject: [PATCH v3 2/7] emacs: help: remove duplicate bindings X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=c5326c6df1e12449804c606a03cd59a471d0538a;p=notmuch-archives.git [PATCH v3 2/7] emacs: help: remove duplicate bindings --- diff --git a/6a/4d31fb2103c93c7d6708074a15ddf2aabe7d97 b/6a/4d31fb2103c93c7d6708074a15ddf2aabe7d97 new file mode 100644 index 000000000..1bce8c74a --- /dev/null +++ b/6a/4d31fb2103c93c7d6708074a15ddf2aabe7d97 @@ -0,0 +1,145 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 0D70C429E37 + for ; Fri, 8 Nov 2013 09:40:35 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0.201 +X-Spam-Level: +X-Spam-Status: No, score=0.201 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001, + RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id dNvnUtZ4lBup for ; + Fri, 8 Nov 2013 09:40:27 -0800 (PST) +Received: from mail-we0-f171.google.com (mail-we0-f171.google.com + [74.125.82.171]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 749F6431FD8 + for ; Fri, 8 Nov 2013 09:40:27 -0800 (PST) +Received: by mail-we0-f171.google.com with SMTP id t60so2262554wes.2 + for ; Fri, 08 Nov 2013 09:40:26 -0800 (PST) +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=Fm0Ak7Bnh5SyCxrN12BxddioUn35q6zAGzx3BxMSKq8=; + b=JW1sTRFpbKZm92hKvfYyJuzDKEjDaU3tPpwDhbWa1TJavv+Tm9yjS1zOWHhewmwx6j + 8cMQQ9sEHvxxJe/BTiIbrbvxjd6P49cKDeU6kN0qF1c90TQziXGUXIPanC3l400B6tBW + ISf47aJQTfYs8fb6gS6j44TFzQ0FxIsShYIcXxgWoMPH8uSW2X8e3OTMIUCtlG4AcWVJ + sVW61pJ/lCdIffr3YF0JNbAai+BwKH50N1X8nvUCN/mYRH/ewMh9EjN7L6Sdm3dqJIgw + ZLM7tdjHvBnx3bpEYjzZ8HJyIZ2WS58UrAd41lzaR7HTwcfkHB8rSTkEDtC7NvpQYvdQ + n/Ig== +X-Received: by 10.180.182.47 with SMTP id eb15mr1661244wic.51.1383932426453; + Fri, 08 Nov 2013 09:40:26 -0800 (PST) +Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31]) + by mx.google.com with ESMTPSA id td6sm7510308wic.10.2013.11.08.09.40.25 + for + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Fri, 08 Nov 2013 09:40:26 -0800 (PST) +From: Mark Walters +To: notmuch@notmuchmail.org +Subject: [PATCH v3 2/7] emacs: help: remove duplicate bindings +Date: Fri, 8 Nov 2013 17:40:14 +0000 +Message-Id: <1383932419-12533-3-git-send-email-markwalters1009@gmail.com> +X-Mailer: git-send-email 1.7.9.1 +In-Reply-To: <1383932419-12533-1-git-send-email-markwalters1009@gmail.com> +References: <1383932419-12533-1-git-send-email-markwalters1009@gmail.com> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +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: Fri, 08 Nov 2013 17:40:35 -0000 + +If the user (or a mode) overrides a keybinding from the common keymap +in one of the modes then both help lines appear in the help screen +even though only one of them is applicable. + +Fix this by checking if we already have that key binding. We do this +by constructing an list of (key . docstring) pairs so it is easy to +check if we have already had that binding. Then the actual print help +routine changes these pairs into strings "key \t docstring" +--- + emacs/notmuch-lib.el | 41 ++++++++++++++++++++++++----------------- + 1 files changed, 24 insertions(+), 17 deletions(-) + +diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el +index ec5a2cb..2195166 100644 +--- a/emacs/notmuch-lib.el ++++ b/emacs/notmuch-lib.el +@@ -238,11 +238,12 @@ This is basically just `format-kbd-macro' but we also convert ESC to M-." + (concat desc " ")))) + + (defun notmuch-describe-keymap (keymap ua-keys &optional prefix tail) +- "Return a list of strings, each describing one binding in KEYMAP. ++ "Return a list of cons cells, each describing one binding in KEYMAP. + +-Each string gives a human-readable description of the key and a +-one-line description of the bound function. See `notmuch-help' +-for an overview of how this documentation is extracted. ++Each cons cell consists of a string giving a human-readable ++description of the key, and a one-line description of the bound ++function. See `notmuch-help' for an overview of how this ++documentation is extracted. + + UA-KEYS should be a key sequence bound to `universal-argument'. + It will be used to describe bindings of commands that support a +@@ -255,18 +256,23 @@ prefix argument. PREFIX and TAIL are used internally." + (notmuch-describe-keymap + binding ua-keys (notmuch-prefix-key-description key) tail))) + (binding +- (when (and ua-keys (symbolp binding) +- (get binding 'notmuch-prefix-doc)) +- ;; Documentation for prefixed command +- (let ((ua-desc (key-description ua-keys))) +- (push (concat ua-desc " " prefix (format-kbd-macro (vector key)) +- "\t" (get binding 'notmuch-prefix-doc)) +- tail))) +- ;; Documentation for command +- (push (concat prefix (format-kbd-macro (vector key)) "\t" +- (or (and (symbolp binding) (get binding 'notmuch-doc)) +- (notmuch-documentation-first-line binding))) +- tail)))) ++ (let ((key-string (concat prefix (format-kbd-macro (vector key))))) ++ ;; We don't include documentation if the key-binding is ++ ;; over-ridden. Note, over-riding a binding ++ ;; automatically hides the prefixed version too. ++ (unless (assoc key-string tail) ++ (when (and ua-keys (symbolp binding) ++ (get binding 'notmuch-prefix-doc)) ++ ;; Documentation for prefixed command ++ (let ((ua-desc (key-description ua-keys))) ++ (push (cons (concat ua-desc " " prefix (format-kbd-macro (vector key))) ++ (get binding 'notmuch-prefix-doc)) ++ tail))) ++ ;; Documentation for command ++ (push (cons key-string ++ (or (and (symbolp binding) (get binding 'notmuch-doc)) ++ (notmuch-documentation-first-line binding))) ++ tail)))))) + keymap) + tail) + +@@ -277,7 +283,8 @@ prefix argument. PREFIX and TAIL are used internally." + (let* ((keymap-name (substring doc (match-beginning 1) (match-end 1))) + (keymap (symbol-value (intern keymap-name))) + (ua-keys (where-is-internal 'universal-argument keymap t)) +- (desc-list (notmuch-describe-keymap keymap ua-keys)) ++ (desc-alist (notmuch-describe-keymap keymap ua-keys)) ++ (desc-list (mapcar (lambda (arg) (concat (car arg) "\t" (cdr arg))) desc-alist)) + (desc (mapconcat #'identity desc-list "\n"))) + (setq doc (replace-match desc 1 1 doc))) + (setq beg (match-end 0))) +-- +1.7.9.1 +