Re: emacs: Customize how each tag is displayed
authorAustin Clements <amdragon@MIT.EDU>
Wed, 23 Jan 2013 00:24:48 +0000 (19:24 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:53:18 +0000 (09:53 -0800)
32/6a851aabdb6d4475a2ad9936682d3797f40af8 [new file with mode: 0644]

diff --git a/32/6a851aabdb6d4475a2ad9936682d3797f40af8 b/32/6a851aabdb6d4475a2ad9936682d3797f40af8
new file mode 100644 (file)
index 0000000..1298397
--- /dev/null
@@ -0,0 +1,215 @@
+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 BE06D431FCB\r
+       for <notmuch@notmuchmail.org>; Tue, 22 Jan 2013 16:24:55 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.574\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.574 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7, RDNS_NONE=1.274] 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 Mm9ad9CROnlE for <notmuch@notmuchmail.org>;\r
+       Tue, 22 Jan 2013 16:24:52 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-8.mit.edu (unknown [18.7.68.37])\r
+       by olra.theworths.org (Postfix) with ESMTP id D3AE3431FC0\r
+       for <notmuch@notmuchmail.org>; Tue, 22 Jan 2013 16:24:51 -0800 (PST)\r
+X-AuditID: 12074425-b7fec6d000007584-75-50ff2dd34fc5\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
+       by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 03.EC.30084.3DD2FF05; Tue, 22 Jan 2013 19:24:51 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id r0N0OoRt007754; \r
+       Tue, 22 Jan 2013 19:24:51 -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.6/8.12.4) with ESMTP id r0N0OmX9012539\r
+       (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT);\r
+       Tue, 22 Jan 2013 19:24:50 -0500 (EST)\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.80)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1Txo92-0004Te-MA; Tue, 22 Jan 2013 19:24:48 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: Damien Cassou <damien.cassou@gmail.com>,\r
+       notmuch mailing list <notmuch@notmuchmail.org>\r
+Subject: Re: emacs: Customize how each tag is displayed\r
+In-Reply-To: <1358525039-13569-1-git-send-email-damien.cassou@gmail.com>\r
+References: <1358525039-13569-1-git-send-email-damien.cassou@gmail.com>\r
+User-Agent: Notmuch/0.14+243~g18d79d1 (http://notmuchmail.org) Emacs/23.4.1\r
+       (i486-pc-linux-gnu)\r
+Date: Tue, 22 Jan 2013 19:24:48 -0500\r
+Message-ID: <87k3r4d9v3.fsf@awakening.csail.mit.edu>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFnrLIsWRmVeSWpSXmKPExsUixG6nontZ93+AwfUGMYtdd7cyWVy/OZPZ\r
+       gclj56y77B7PVt1iDmCK4rJJSc3JLEst0rdL4MqYvvMdS8EBvYpzN6obGL8odzFyckgImEic\r
+       adzDDGGLSVy4t56ti5GLQ0hgH6PEti3rGCGcDYwSJ5feYoFwLjJJzD59lAnCWcIosfHdU7B+\r
+       NgENiW37lzOC2CICKRJb73xgA7GFBcwltt2YyQRicwp4SFy8MYsVxBYScJd4P38dWK+oQLzE\r
+       nA1T2UFsFgFVie0zj7OA2LxA9116e5IRwhaUODnzCVicWUBL4sa/l0wTGAVmIUnNQpJawMi0\r
+       ilE2JbdKNzcxM6c4NVm3ODkxLy+1SNdCLzezRC81pXQTIzgkXVR3ME44pHSIUYCDUYmHN+HZ\r
+       vwAh1sSy4srcQ4ySHExKorxzdP4HCPEl5adUZiQWZ8QXleakFh9ilOBgVhLhVd4IVM6bklhZ\r
+       lVqUD5OS5mBREue9kXLTX0ggPbEkNTs1tSC1CCYrw8GhJMFbCDJUsCg1PbUiLTOnBCHNxMEJ\r
+       MpwHaPhqkBre4oLE3OLMdIj8KUZdjv1P2p8zCrHk5eelSolDDBIAKcoozYObA0slrxjFgd4S\r
+       5p0IUsUDTENwk14BLWECWsK7+DfIkpJEhJRUA2PVr0S7BrtlP/QWhBR8Cd7G92/7y6xMN+X/\r
+       phra1x/c3T75mznbhSPBRjqPF005wp411ebN9cTO53tfS/38dkZR6XSO5auD4rH1Rv8nzO/5\r
+       3/30U1v929ykeP1/OgcaEhN2mlxc/+BDc/PRKWfljaJqp1fO9VyZudZUO98nqjZutlaKwcNT\r
+       f+crsRRnJBpqMRcVJwIAMtlYtwADAAA=\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: Wed, 23 Jan 2013 00:24:55 -0000\r
+\r
+On Fri, 18 Jan 2013, Damien Cassou <damien.cassou@gmail.com> wrote:\r
+> [PATCH 1/4] emacs: Add notmuch-intersperse to notmuch-lib/\r
+> [PATCH 2/4] emacs: pictures that might be used as icons for tags\r
+> [PATCH 3/4] emacs: possibility to customize the rendering of tags\r
+> [PATCH 4/4] emacs: provide convenience functions for notmuch-tagger\r
+>\r
+>\r
+> These patches are the first of an upcoming series whose goal is to\r
+> integrate notmuch-labeler into notmuch. See the following for more\r
+> details: https://github.com/DamienCassou/notmuch-labeler\r
+>\r
+> Points of discussion:\r
+>\r
+> - This series does not have any unit-test to make it smaller and more\r
+>   amenable to comments. I will send a patch when requested.\r
+>\r
+> - Patch 3/4 formats tags as mode-line templates so that we can show\r
+>   tags in the header-line in a later series.\r
+>\r
+> - Patch 3/4 introduces `notmuch-tagger-formats', a list of pairs (KEY\r
+>   FORMAT) to format a tag matching KEY using a special format.\r
+>   Currently, an example of such a list is:\r
+>\r
+>     (("unread"\r
+>          (:propertize "unread" face\r
+>                       (:foreground "red")))\r
+>      ("flagged"\r
+>          (:propertize "flagged" display\r
+>                       (image :type svg\r
+>                              :file ,(notmuch-tagger-image-path "star.svg")\r
+>                              :ascent center :mask heuristic))))\r
+>\r
+>   to set the unread tag to be red and the flagged tag to have a star\r
+>   picture attached. Because this variable is hard to edit without\r
+>   making mistakes, patch 4/4 introduces customization functions that\r
+>   the user can call on their init.el file like this:\r
+>\r
+>   (notmuch-tagger-propertize "unread" :foreground "red")\r
+>   (notmuch-tagger-image-star "flagged")\r
+>\r
+>   Nevertheless, implementing a customize interface for this variable\r
+>   is difficult as Emacs does not provide customization widgets for\r
+>   text-property lists. A possible solution could be to change the list\r
+>   value so that it looks like:\r
+>\r
+>     (("unread" (propertize :foreground "red"))\r
+>      ("flagged" (image-star)))\r
+>\r
+>   where the FORMAT part of each pair would be the suffix of a\r
+>   notmuch-tagger customization function name (as introduced by patch\r
+>   4/4) and the rest would be parameters to pass to this function\r
+>   (except the KEY parameter that is already in each pair of the\r
+>   `notmuch-tagger-formats' list). This solution would be more amenable\r
+>   to the customization interface, but maybe less powerful.\r
+\r
+I'm not sold on your mode-line-format approach.  On the one hand, it's\r
+rather quaint that you can reuse all of the mode-line formatting\r
+mechanism.  But, on the other hand, 90% of the mode-line formatting\r
+mechanism makes no sense in this context, and all of the utility\r
+functions you add to make this variable accessible as well as the\r
+difficulty in creating a customize interface for it suggest that this is\r
+a false economy: that mode-line formatting is, in fact, the wrong\r
+abstraction for this.\r
+\r
+I'm not sure what the best representation is, but here's one idea.\r
+Instead of inventing (or reusing) some specialized formatting language,\r
+use the language already at your disposal: make the tag format a list of\r
+Elisp expressions that transform the tag string into an arbitrary\r
+propertized string to use in place of the tag.  You can't get much more\r
+powerful than that, and, plus, it would be really easy to implement.\r
+\r
+Here's what I'm imagining, complete with working (slightly hairy)\r
+customize interface:\r
+\r
+(defcustom notmuch-tag-formats\r
+  '(("unread" (propertize tag 'face '(:foreground "red")))\r
+    ("flagged" (notmuch-tag-format-image tag "star.svg")))\r
+\r
+  "Custom formats for individual tags.\r
+\r
+This gives a list that maps from tag names to lists of formatting\r
+expressions.  The car of each element gives a tag name and the\r
+cdr gives a list of Elisp expressions that modify the tag.  If\r
+the list is empty, the tag will simply be hidden.  Otherwise,\r
+each expression will be evaluated in order: for the first\r
+expression, the variable `tag' will be bound to the tag name; for\r
+each later expression, the variable `tag' will be bound to the\r
+result of the previous expression.  In this way, each expression\r
+can build on the formatting performed by the previous expression.\r
+The result of the last expression will displayed in place of the\r
+tag.\r
+\r
+For example, to replace a tag with another string, simply use\r
+that string as a formatting expression.  To change the foreground\r
+of a tag to red, use the expression\r
+  (propertize tag 'face '(:foreground \"red\"))\r
+\r
+See also `notmuch-tag-format-image', which can help replace tags\r
+with images."\r
+\r
+  :group 'notmuch-search\r
+  :group 'notmuch-show\r
+  :type '(alist :key-type (string :tag "Tag")\r
+               :extra-offset -3\r
+               :value-type\r
+               (radio :format "%v"\r
+                      (const :tag "Hidden" nil)\r
+                      (set :tag "Modified"\r
+                           (string :tag "Display as")\r
+                           (list :tag "Face" :extra-offset -4\r
+                                 (const :format "" :inline t\r
+                                        (propertize tag 'face))\r
+                                 (list :format "%v"\r
+                                       (const :format "" quote)\r
+                                       custom-face-edit))\r
+                           (list :format "%v" :extra-offset -4\r
+                                 (const :format "" :inline t\r
+                                        (notmuch-tag-format-image tag))\r
+                                 (choice :tag "Image"\r
+                                         (const :tag "Star" "star.svg")\r
+                                         (const :tag "Empty star"\r
+                                                "star-empty.svg")\r
+                                         (const :tag "Tag" "tag.svg")\r
+                                         (string :tag "Custom")))\r
+                           (sexp :tag "Custom")))))\r
+\r
+where I'm imagining notmuch-tag-format-image would be very similar to\r
+your existing image utilities, with an interface something like\r
+\r
+(defun notmuch-tag-format-image (tag image)\r
+  "Replace TAG with IMAGE, if available.\r
+\r
+Returns a propertized string that will display IMAGE in place of\r
+TAG.  If IMAGE is a relative path, it will be looked for in the\r
+standard notmuch image directory.  This is designed for use in\r
+`notmuch-tag-formats'."\r
+  ...)\r
+\r
+Thoughts?\r
+\r