mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-22 02:48:08 +01:00
contrib: pick: tidy up pick-format-field
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 commit is contained in:
parent
c8f7b6e0c4
commit
cbbf53e4df
1 changed files with 21 additions and 28 deletions
|
@ -678,20 +678,16 @@ unchanged ADDRESS if parsing fails."
|
||||||
(defun notmuch-pick-format-field (field format-string msg)
|
(defun notmuch-pick-format-field (field format-string msg)
|
||||||
"Format a FIELD of MSG according to FORMAT-STRING and return string"
|
"Format a FIELD of MSG according to FORMAT-STRING and return string"
|
||||||
(let* ((headers (plist-get msg :headers))
|
(let* ((headers (plist-get msg :headers))
|
||||||
(match (plist-get msg :match))
|
(match (plist-get msg :match)))
|
||||||
formatted-field)
|
|
||||||
(cond
|
(cond
|
||||||
((listp field)
|
((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")
|
((string-equal field "date")
|
||||||
(let ((face (if match
|
(let ((face (if match
|
||||||
'notmuch-pick-match-date-face
|
'notmuch-pick-match-date-face
|
||||||
'notmuch-pick-no-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")
|
((string-equal field "tree")
|
||||||
(let ((tree-status (plist-get msg :tree-status))
|
(let ((tree-status (plist-get msg :tree-status))
|
||||||
|
@ -699,23 +695,23 @@ unchanged ADDRESS if parsing fails."
|
||||||
'notmuch-pick-match-tree-face
|
'notmuch-pick-match-tree-face
|
||||||
'notmuch-pick-no-match-tree-face)))
|
'notmuch-pick-no-match-tree-face)))
|
||||||
|
|
||||||
(setq formatted-field
|
|
||||||
(propertize (format format-string
|
(propertize (format format-string
|
||||||
(mapconcat #'identity (reverse tree-status) ""))
|
(mapconcat #'identity (reverse tree-status) ""))
|
||||||
'face face))))
|
'face face)))
|
||||||
|
|
||||||
((string-equal field "subject")
|
((string-equal field "subject")
|
||||||
(let ((bare-subject (notmuch-show-strip-re (plist-get headers :Subject)))
|
(let ((bare-subject (notmuch-show-strip-re (plist-get headers :Subject)))
|
||||||
|
(previous-subject notmuch-pick-previous-subject)
|
||||||
(face (if match
|
(face (if match
|
||||||
'notmuch-pick-match-subject-face
|
'notmuch-pick-match-subject-face
|
||||||
'notmuch-pick-no-match-subject-face)))
|
'notmuch-pick-no-match-subject-face)))
|
||||||
(setq formatted-field
|
|
||||||
|
(setq notmuch-pick-previous-subject bare-subject)
|
||||||
(propertize (format format-string
|
(propertize (format format-string
|
||||||
(if (string= notmuch-pick-previous-subject bare-subject)
|
(if (string= previous-subject bare-subject)
|
||||||
" ..."
|
" ..."
|
||||||
bare-subject))
|
bare-subject))
|
||||||
'face face))
|
'face face)))
|
||||||
(setq notmuch-pick-previous-subject bare-subject)))
|
|
||||||
|
|
||||||
((string-equal field "authors")
|
((string-equal field "authors")
|
||||||
(let ((author (notmuch-pick-clean-address (plist-get headers :From)))
|
(let ((author (notmuch-pick-clean-address (plist-get headers :From)))
|
||||||
|
@ -725,20 +721,17 @@ unchanged ADDRESS if parsing fails."
|
||||||
'notmuch-pick-no-match-author-face)))
|
'notmuch-pick-no-match-author-face)))
|
||||||
(when (> (length author) len)
|
(when (> (length author) len)
|
||||||
(setq author (substring author 0 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")
|
((string-equal field "tags")
|
||||||
(let ((tags (plist-get msg :tags))
|
(let ((tags (plist-get msg :tags))
|
||||||
(face (if match
|
(face (if match
|
||||||
'notmuch-pick-match-tag-face
|
'notmuch-pick-match-tag-face
|
||||||
'notmuch-pick-no-match-tag-face)))
|
'notmuch-pick-no-match-tag-face)))
|
||||||
(setq formatted-field
|
|
||||||
(propertize (format format-string
|
(propertize (format format-string
|
||||||
(mapconcat #'identity tags ", "))
|
(mapconcat #'identity tags ", "))
|
||||||
'face face)))))
|
'face face))))))
|
||||||
formatted-field))
|
|
||||||
|
|
||||||
(defun notmuch-pick-format-field-list (field-list msg)
|
(defun notmuch-pick-format-field-list (field-list msg)
|
||||||
"Format fields of MSG according to FIELD-LIST and return string"
|
"Format fields of MSG according to FIELD-LIST and return string"
|
||||||
|
|
Loading…
Reference in a new issue