unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] contrib: pick: tidy up pick-format-field
@ 2013-09-15  8:41 Mark Walters
  2013-09-16 20:15 ` Tomi Ollila
  2013-09-23 10:39 ` David Bremner
  0 siblings, 2 replies; 3+ messages in thread
From: Mark Walters @ 2013-09-15  8:41 UTC (permalink / raw)
  To: notmuch

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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] contrib: pick: tidy up pick-format-field
  2013-09-15  8:41 [PATCH] contrib: pick: tidy up pick-format-field Mark Walters
@ 2013-09-16 20:15 ` Tomi Ollila
  2013-09-23 10:39 ` David Bremner
  1 sibling, 0 replies; 3+ messages in thread
From: Tomi Ollila @ 2013-09-16 20:15 UTC (permalink / raw)
  To: Mark Walters, notmuch

On Sun, Sep 15 2013, Mark Walters <markwalters1009@gmail.com> wrote:

> 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

LGTM

Tomi

> 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(-)
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] contrib: pick: tidy up pick-format-field
  2013-09-15  8:41 [PATCH] contrib: pick: tidy up pick-format-field Mark Walters
  2013-09-16 20:15 ` Tomi Ollila
@ 2013-09-23 10:39 ` David Bremner
  1 sibling, 0 replies; 3+ messages in thread
From: David Bremner @ 2013-09-23 10:39 UTC (permalink / raw)
  To: Mark Walters, notmuch

Mark Walters <markwalters1009@gmail.com> writes:

> 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.

pushed.

d

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-09-23 10:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-15  8:41 [PATCH] contrib: pick: tidy up pick-format-field Mark Walters
2013-09-16 20:15 ` Tomi Ollila
2013-09-23 10:39 ` David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).