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