Re: [PATCH 3/4] emacs: help: remap support
authorAustin Clements <aclements@csail.mit.edu>
Thu, 7 Nov 2013 19:47:05 +0000 (14:47 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:58:04 +0000 (09:58 -0800)
ad/9fec1ea5aba71f18e71be334907f9ac9fc043e [new file with mode: 0644]

diff --git a/ad/9fec1ea5aba71f18e71be334907f9ac9fc043e b/ad/9fec1ea5aba71f18e71be334907f9ac9fc043e
new file mode 100644 (file)
index 0000000..be72bd9
--- /dev/null
@@ -0,0 +1,174 @@
+Return-Path: <amdragon@mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 07D34431FDC\r
+       for <notmuch@notmuchmail.org>; Thu,  7 Nov 2013 11:47:18 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id sfU0r7Nhzvgt for <notmuch@notmuchmail.org>;\r
+       Thu,  7 Nov 2013 11:47:09 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-1.mit.edu (dmz-mailsec-scanner-1.mit.edu\r
+       [18.9.25.12])\r
+       (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id AFB9D431FCF\r
+       for <notmuch@notmuchmail.org>; Thu,  7 Nov 2013 11:47:09 -0800 (PST)\r
+X-AuditID: 1209190c-b7f058e000005fd9-48-527bee3cac01\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+       (using TLS with cipher AES256-SHA (256/256 bits))\r
+       (Client did not present a certificate)\r
+       by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id C3.84.24537.D3EEB725; Thu,  7 Nov 2013 14:47:09 -0500 (EST)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+       by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id rA7Jl7e6032410; \r
+       Thu, 7 Nov 2013 14:47:08 -0500\r
+Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
+       (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id rA7Jl5hY011187\r
+       (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT);\r
+       Thu, 7 Nov 2013 14:47:06 -0500\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.80)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1VeVXl-0004Cf-8R; Thu, 07 Nov 2013 14:47:05 -0500\r
+From: Austin Clements <aclements@csail.mit.edu>\r
+To: Mark Walters <markwalters1009@gmail.com>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH 3/4] emacs: help: remap support\r
+In-Reply-To: <1382821479-23384-4-git-send-email-markwalters1009@gmail.com>\r
+References: <1382821479-23384-1-git-send-email-markwalters1009@gmail.com>\r
+       <1382821479-23384-4-git-send-email-markwalters1009@gmail.com>\r
+User-Agent: Notmuch/0.16+110~g45444ee (http://notmuchmail.org) Emacs/23.4.1\r
+       (i486-pc-linux-gnu)\r
+Date: Thu, 07 Nov 2013 14:47:05 -0500\r
+Message-ID: <87habokn9i.fsf@awakening.csail.mit.edu>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFnrIIsWRmVeSWpSXmKPExsUixG6nrmv7rjrIYN0SNovVc3ksrt+cyezA\r
+       5LFz1l12j2erbjEHMEVx2aSk5mSWpRbp2yVwZWya3cZacE6hYt2vBawNjNskuxg5OSQETCT+\r
+       dGxkhLDFJC7cW8/WxcjFISQwm0niwebNYAkhgQ2MEmt3R0EkTjFJNDx7ww7hLGGUOPX3E1gV\r
+       m4C+xIq1k1hBbBEBV4mn3z4zg9jCAsYSEyZNBbM5Bbwkts95ygTR3M4osXTRDrBmUYF4ianf\r
+       5rCD2CwCqhJf5vwHa+AFum/VxmOMELagxMmZT1hAbGYBLYkb/14yTWAUmIUkNQtJagEj0ypG\r
+       2ZTcKt3cxMyc4tRk3eLkxLy81CJdQ73czBK91JTSTYygkOSU5NnB+Oag0iFGAQ5GJR7eggvV\r
+       QUKsiWXFlbmHGCU5mJREeZXeAIX4kvJTKjMSizPii0pzUosPMUpwMCuJ8B5ZCJTjTUmsrEot\r
+       yodJSXOwKInz3uSwDxISSE8sSc1OTS1ILYLJynBwKEnwnn0L1ChYlJqeWpGWmVOCkGbi4AQZ\r
+       zgM0/AlIDW9xQWJucWY6RP4Uo6KUOO8DkIQASCKjNA+uF5YyXjGKA70izLsOpIoHmG7gul8B\r
+       DWYCGhzyqxJkcEkiQkqqgbHhT6Fb7rTJeqc+bW26/vw3w4SMOxN/XbsnNn3DOy371DXphqtU\r
+       leqT+/8fWakQoZ45+/BuuxcZ/B63FhUcON83lXdnGStH5IGVHt2LtjyS4l3gp71tncBt64x7\r
+       QWlrDqlNeXZPbkOQ8k1r++0sez8z5ZhZcljN2s8vxRi4XD9wk+abo6mT4xyUWIozEg21mIuK\r
+       EwGEff5l9AIAAA==\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 07 Nov 2013 19:47:18 -0000\r
+\r
+I originally wanted to see these concerns separated -- to have a\r
+separate function that took care of resolving remaps to keep the logic\r
+out of notmuch-describe-keymap -- but then I tried to write that\r
+function and gave up.  If you can think of a way to do that, I think it\r
+would make this code clearer, but if not that's fine, too.\r
+\r
+On Sat, 26 Oct 2013, Mark Walters <markwalters1009@gmail.com> wrote:\r
+> If a user or mode uses remap to rebind a keybinding then it appears in\r
+> the help as a line <remap><function> New function docstring. Special\r
+> case these remapping lines so that we print the actual binding.\r
+> ---\r
+>  emacs/notmuch.el |   21 ++++++++++++++-------\r
+>  1 files changed, 14 insertions(+), 7 deletions(-)\r
+>\r
+> diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+> index b9db9ba..c354b05 100644\r
+> --- a/emacs/notmuch.el\r
+> +++ b/emacs/notmuch.el\r
+> @@ -140,7 +140,7 @@ This is basically just `format-kbd-macro' but we also convert ESC to M-."\r
+>      "M-"\r
+>        (concat desc " "))))\r
+>  \r
+> -(defun notmuch-describe-keymap (keymap ua-keys &optional prefix tail)\r
+> +(defun notmuch-describe-keymap (keymap ua-keys &optional prefix tail remap)\r
+>    "Return a list of cons cells, each describing one binding in KEYMAP.\r
+>  \r
+>  Each cons cell consists of a string giving a human-readable\r
+> @@ -150,16 +150,23 @@ documentation is extracted.\r
+>  \r
+>  UA-KEYS should be a key sequence bound to `universal-argument'.\r
+>  It will be used to describe bindings of commands that support a\r
+> -prefix argument.  PREFIX and TAIL are used internally."\r
+> +prefix argument.  PREFIX, TAIL and REMAP are used internally."\r
+>    (map-keymap\r
+>     (lambda (key binding)\r
+>       (cond ((mouse-event-p key) nil)\r
+>         ((keymapp binding)\r
+\r
+I think it would be worth documenting what's going on with remaps here.\r
+I didn't get it until I wrote some of my own test code *and* chatted\r
+with you on IRC.  Perhaps something like:\r
+\r
+  ;; Remapping are represented as a binding whose first "event" is\r
+  ;; 'remap.  Hence, if the keymap has any remappings, it will have a\r
+  ;; binding whose "key" is 'remap, and whose "binding" is itself a\r
+  ;; keymap that maps not from keys to commands, but from old (remapped)\r
+  ;; functions to the commands to use in their stead.\r
+\r
+> -        (setq tail\r
+> -              (notmuch-describe-keymap\r
+> -               binding ua-keys (notmuch-prefix-key-description key) tail)))\r
+> +        (if (equal key 'remap)\r
+\r
+`eq' would be more standard here.\r
+\r
+> +            (setq tail\r
+> +                  (notmuch-describe-keymap\r
+> +                   binding ua-keys prefix tail t))\r
+> +          (setq tail\r
+> +                (notmuch-describe-keymap\r
+> +                 binding ua-keys (notmuch-prefix-key-description key) tail))))\r
+>         (t\r
+> -        (let ((key-string (concat prefix (format-kbd-macro (vector key)))))\r
+> +        (let* ((actual-key (if remap\r
+> +                               (where-is-internal key nil t)\r
+\r
+Is it okay to use nil for the keymap to `where-is-internal' here?  It\r
+seems like maybe we have to pass down a "root" keymap from\r
+`notmuch-substitute-command-keys' so it knows what to resolve the\r
+remappings relative to.  Arguably the original caller should provide\r
+just the root keymap, while the "current" sub-keymap should be one of\r
+the internal recursive arguments.\r
+\r
+> +                             (vector key)))\r
+> +               (key-string (concat prefix (format-kbd-macro actual-key))))\r
+>            ;; We don't include documentation if the key-binding is\r
+>            ;; over-ridden. Note, over-riding a binding\r
+>            ;; automatically hides the prefixed version too.\r
+> @@ -168,7 +175,7 @@ prefix argument.  PREFIX and TAIL are used internally."\r
+>                         (get binding 'notmuch-prefix-doc))\r
+>                ;; Documentation for prefixed command\r
+>                (let ((ua-desc (key-description ua-keys)))\r
+> -                (push (cons (concat ua-desc " " prefix (format-kbd-macro (vector key)))\r
+> +                (push (cons (concat ua-desc " " prefix (format-kbd-macro actual-key))\r
+>                              (get binding 'notmuch-prefix-doc))\r
+>                        tail)))\r
+>              ;; Documentation for command\r
+> -- \r
+> 1.7.9.1\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r