[PATCH] contrib: pick: tidy up pick-format-field
authorMark Walters <markwalters1009@gmail.com>
Sun, 15 Sep 2013 08:41:17 +0000 (09:41 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:57:08 +0000 (09:57 -0800)
c5/b26ec94454cb9c946b5d9d51108bb354aad222 [new file with mode: 0644]

diff --git a/c5/b26ec94454cb9c946b5d9d51108bb354aad222 b/c5/b26ec94454cb9c946b5d9d51108bb354aad222
new file mode 100644 (file)
index 0000000..1ca0f8e
--- /dev/null
@@ -0,0 +1,170 @@
+Return-Path: <markwalters1009@gmail.com>\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 EEC3E431FAF\r
+       for <notmuch@notmuchmail.org>; Sun, 15 Sep 2013 01:41:33 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 2.7\r
+X-Spam-Level: **\r
+X-Spam-Status: No, score=2.7 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+       FREEMAIL_REPLY=2.499, 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 6X1h99QfZ1bK for <notmuch@notmuchmail.org>;\r
+       Sun, 15 Sep 2013 01:41:29 -0700 (PDT)\r
+Received: from mail-we0-f181.google.com (mail-we0-f181.google.com\r
+       [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id EFDAB431FAE\r
+       for <notmuch@notmuchmail.org>; Sun, 15 Sep 2013 01:41:28 -0700 (PDT)\r
+Received: by mail-we0-f181.google.com with SMTP id p61so2603167wes.12\r
+       for <notmuch@notmuchmail.org>; Sun, 15 Sep 2013 01:41:27 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=from:to:cc:subject:date:message-id;\r
+       bh=ZFsqk8G9LCm49EMLIkkiDrGS0CpBaKsXlwLRurAZ3Z4=;\r
+       b=c6nbvuqQ3nCMO8t3BltWGczy2ubfJRFafMMRTh4PUWVERiGWiQrcYqcDE4ieoie6Do\r
+       f16lyxUFvIjjUAJ8FGt6P9BA/+fcGUf4Omsq9uAq5KgIuN0xMVcfmu49icxM9bq5VSWs\r
+       36jTS3PzTMLqzfKZHC6qLWgKzCtG+v8s4aB16Q7PLHrHC8QU7YqCvAAnWOknzuap54aQ\r
+       QKxOMt8D6HSBeebL3TVZeN5ag7o2d75cUs0Z0GIjiunia/Hf1zOnDEFTlaIfB3Z5kLr7\r
+       Im/+AxOAOq5+b2uC7K7wyUOFi8ytEz6VfZBao5CdILddvsIW4KWpsfglSh+Dcd8q6Nmo\r
+       cvpQ==\r
+X-Received: by 10.180.208.97 with SMTP id md1mr8875758wic.41.1379234487901;\r
+       Sun, 15 Sep 2013 01:41:27 -0700 (PDT)\r
+Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
+       by mx.google.com with ESMTPSA id e5sm15007301wiy.2.1969.12.31.16.00.00\r
+       (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+       Sun, 15 Sep 2013 01:41:27 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] contrib: pick: tidy up pick-format-field\r
+Date: Sun, 15 Sep 2013 09:41:17 +0100\r
+Message-Id: <1379234477-14089-1-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\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: Sun, 15 Sep 2013 08:41:34 -0000\r
+\r
+Previously this function used a temporary variable to store the return\r
+value but we can just use the return value of the cond statement\r
+directly.\r
+\r
+The only tiny subtlety is that in one case (subject) we need to\r
+slightly reorder the logic to make sure the formatted-field is the\r
+last thing computed.\r
+---\r
+This follows Tomi's suggestion in id:m2ob7vg24n.fsf@guru.guru-group.fi                                                                                     and simplifies the code here slightly. This patch applies on top of                                                                                        the series at                                                                                                                                              id:1378092488-32050-1-git-send-email-markwalters1009@gmail.com                                                                                             \r
+\r
+(It also includes one small whitespace fix-up for the face for the tags)\r
+\r
+\r
+ contrib/notmuch-pick/notmuch-pick.el |   49 ++++++++++++++-------------------\r
+ 1 files changed, 21 insertions(+), 28 deletions(-)\r
+\r
+diff --git a/contrib/notmuch-pick/notmuch-pick.el b/contrib/notmuch-pick/notmuch-pick.el\r
+index cba9549..17fe395 100644\r
+--- a/contrib/notmuch-pick/notmuch-pick.el\r
++++ b/contrib/notmuch-pick/notmuch-pick.el\r
+@@ -682,20 +682,16 @@ unchanged ADDRESS if parsing fails."\r
+ (defun notmuch-pick-format-field (field format-string msg)\r
+   "Format a FIELD of MSG according to FORMAT-STRING and return string"\r
+   (let* ((headers (plist-get msg :headers))\r
+-      (match (plist-get msg :match))\r
+-      formatted-field)\r
++       (match (plist-get msg :match)))\r
+     (cond\r
+      ((listp field)\r
+-      (setq formatted-field\r
+-          (format format-string (notmuch-pick-format-field-list field msg))))\r
++      (format format-string (notmuch-pick-format-field-list field msg)))\r
\r
+      ((string-equal field "date")\r
+       (let ((face (if match\r
+                     'notmuch-pick-match-date-face\r
+                   'notmuch-pick-no-match-date-face)))\r
+-      (setq formatted-field\r
+-            (propertize (format format-string (plist-get msg :date_relative))\r
+-                        'face face))))\r
++      (propertize (format format-string (plist-get msg :date_relative)) 'face face)))\r
\r
+      ((string-equal field "tree")\r
+       (let ((tree-status (plist-get msg :tree-status))\r
+@@ -703,23 +699,23 @@ unchanged ADDRESS if parsing fails."\r
+                     'notmuch-pick-match-tree-face\r
+                   'notmuch-pick-no-match-tree-face)))\r
\r
+-      (setq formatted-field\r
+-            (propertize (format format-string\r
+-                                (mapconcat #'identity (reverse tree-status) ""))\r
+-                        'face face))))\r
++      (propertize (format format-string\r
++                          (mapconcat #'identity (reverse tree-status) ""))\r
++                  'face face)))\r
\r
+      ((string-equal field "subject")\r
+       (let ((bare-subject (notmuch-show-strip-re (plist-get headers :Subject)))\r
++          (previous-subject notmuch-pick-previous-subject)\r
+           (face (if match\r
+                     'notmuch-pick-match-subject-face\r
+                   'notmuch-pick-no-match-subject-face)))\r
+-      (setq formatted-field\r
+-            (propertize (format format-string\r
+-                                (if (string= notmuch-pick-previous-subject bare-subject)\r
+-                                    " ..."\r
+-                                  bare-subject))\r
+-                        'face face))\r
+-      (setq notmuch-pick-previous-subject bare-subject)))\r
++\r
++      (setq notmuch-pick-previous-subject bare-subject)\r
++      (propertize (format format-string\r
++                          (if (string= previous-subject bare-subject)\r
++                              " ..."\r
++                            bare-subject))\r
++                  'face face)))\r
\r
+      ((string-equal field "authors")\r
+       (let ((author (notmuch-pick-clean-address (plist-get headers :From)))\r
+@@ -729,20 +725,17 @@ unchanged ADDRESS if parsing fails."\r
+                   'notmuch-pick-no-match-author-face)))\r
+       (when (> (length author) len)\r
+         (setq author (substring author 0 len)))\r
+-      (setq formatted-field\r
+-            (propertize (format format-string author)\r
+-                        'face face))))\r
++      (propertize (format format-string author) 'face face)))\r
\r
+      ((string-equal field "tags")\r
+       (let ((tags (plist-get msg :tags))\r
+           (face (if match\r
+-                        'notmuch-pick-match-tag-face\r
+-                      'notmuch-pick-no-match-tag-face)))\r
+-      (setq formatted-field\r
+-            (propertize (format format-string\r
+-                                (mapconcat #'identity tags ", "))\r
+-                        'face face)))))\r
+-    formatted-field))\r
++                    'notmuch-pick-match-tag-face\r
++                  'notmuch-pick-no-match-tag-face)))\r
++      (propertize (format format-string\r
++                          (mapconcat #'identity tags ", "))\r
++                  'face face))))))\r
++\r
\r
+ (defun notmuch-pick-format-field-list (field-list msg)\r
+   "Format fields of MSG according to FIELD-LIST and return string"\r
+-- \r
+1.7.9.1\r
+\r