From ada203a26fef67c844e6acb1b9db5137f1932fa9 Mon Sep 17 00:00:00 2001 From: Mark Walters Date: Tue, 12 Nov 2013 20:10:55 +0000 Subject: [PATCH] [PATCH v4 3/7] emacs: help: remove duplicate bindings --- 85/c3138b6a36abc5428c4fef320ce385b9fcd138 | 145 ++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 85/c3138b6a36abc5428c4fef320ce385b9fcd138 diff --git a/85/c3138b6a36abc5428c4fef320ce385b9fcd138 b/85/c3138b6a36abc5428c4fef320ce385b9fcd138 new file mode 100644 index 000000000..bfd95527d --- /dev/null +++ b/85/c3138b6a36abc5428c4fef320ce385b9fcd138 @@ -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 8BABF431FD7 + for ; Tue, 12 Nov 2013 12:18:04 -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 StzzUjPrxCuO for ; + Tue, 12 Nov 2013 12:17:58 -0800 (PST) +Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com + [209.85.212.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id CF432431FCF + for ; Tue, 12 Nov 2013 12:17:57 -0800 (PST) +Received: by mail-wi0-f181.google.com with SMTP id f4so617394wiw.14 + for ; Tue, 12 Nov 2013 12:17:56 -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=ICVpgctOq3VK9xNLH18+fEKS/0O162OYUXgyxgGmz9I=; + b=xVW/d9Tpmx1+Efd+rMMXKW+X2UNk+bIWlOz3nCxrogTk0KcYI7rmrPV2TuMLOwAqIm + fUF1WL9B55Dhny1KZH6q6B0fKfBGAS7hF/cJL4eM2p+SU5l5ZP6I3Mt7WAsYcuRSO6Si + E6l2HPaFydyyWpkbsFrZb+huI+kPp4dmlzxrVqYpJf/Di0fHbsSDRR+RMwPMR7A0qj0o + JC/yB6k4ea20coN81VhaVc9itU0QDDN8z25Sa6FROLPTZFoKPI9pfNBPMm6JSg4eqMgC + owPlkhdMkRSPb+OJ4sSBX8MO5eias7H6bdYiLYBHLLiUKEF3L9zB25qrwlPKQ4t2c+CI + DUWA== +X-Received: by 10.180.78.132 with SMTP id b4mr4666796wix.0.1384287070016; + Tue, 12 Nov 2013 12:11:10 -0800 (PST) +Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31]) + by mx.google.com with ESMTPSA id + qc10sm48006738wic.9.2013.11.12.12.11.09 for + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Tue, 12 Nov 2013 12:11:09 -0800 (PST) +From: Mark Walters +To: notmuch@notmuchmail.org +Subject: [PATCH v4 3/7] emacs: help: remove duplicate bindings +Date: Tue, 12 Nov 2013 20:10:55 +0000 +Message-Id: <1384287059-3525-4-git-send-email-markwalters1009@gmail.com> +X-Mailer: git-send-email 1.7.9.1 +In-Reply-To: <1384287059-3525-1-git-send-email-markwalters1009@gmail.com> +References: <1384287059-3525-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: Tue, 12 Nov 2013 20:18:04 -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 6abc4ea..dde636a 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) + +@@ -279,7 +285,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))) + (mapconcat #'identity desc-list "\n"))))) + (setq doc (replace-match desc 1 1 doc))) + (setq beg (match-end 0))) +-- +1.7.9.1 + -- 2.26.2