* mu4e: turn header-info into cons-pairs

This commit is contained in:
djcb 2012-07-10 19:15:13 +03:00
parent 1ea5961d2a
commit 710cd609b1
3 changed files with 29 additions and 29 deletions

View File

@ -102,8 +102,9 @@ some custom function. Each of the list members has the following format:
(NAME PREDICATE-FUNC PARAM-FUNC) (NAME PREDICATE-FUNC PARAM-FUNC)
* NAME is the name of the predicate function, and the first character * NAME is the name of the predicate function, and the first character
is the shortcut (so keep those unique). is the shortcut (so keep those unique).
* PREDICATE-FUNC is a function that takes two parameters, MSG and (optionally) PARAM, * PREDICATE-FUNC is a function that takes two parameters, MSG
and should return non-nil when there's a match. and (optionally) PARAM, and should return non-nil when there's a
match.
* PARAM-FUNC is function that is evaluated once, and its value is then passed to * PARAM-FUNC is function that is evaluated once, and its value is then passed to
PREDICATE-FUNC as PARAM. This is useful for getting user-input.") PREDICATE-FUNC as PARAM. This is useful for getting user-input.")
@ -531,7 +532,7 @@ after the end of the search results."
(+ mu4e~mark-fringe-len (floor (fringe-columns 'left t))) ?\s) (+ mu4e~mark-fringe-len (floor (fringe-columns 'left t))) ?\s)
(mapcar (mapcar
(lambda (item) (lambda (item)
(let* ((info (cadr (assoc (car item) mu4e-header-info))) (let* ((info (cdr (assoc (car item) mu4e-header-info)))
(name (plist-get info :shortname)) (name (plist-get info :shortname))
(help (plist-get info :help)) (help (plist-get info :help))
(width (cdr item))) (width (cdr item)))

View File

@ -337,61 +337,59 @@ headers)."
:group 'mu4e-faces) :group 'mu4e-faces)
;; headers info ;; headers info
(defconst mu4e-header-info (defconst mu4e-header-info
'( (:attachments . '( (:attachments .
( :name "Attachments" ( :name "Attachments"
:shortname "Atts" :shortname "Atts"
:help "Message attachments")) :help "Message attachments"))
(:bcc . (:bcc .
( :name "Bcc" ( :name "Bcc"
:shortname "Bcc" :shortname "Bcc"
:help "Blind Carbon-Copy recipients for the message" :help "Blind Carbon-Copy recipients for the message"
:sortable t)) :sortable t))
(:cc (:cc .
( :name "Cc" ( :name "Cc"
:shortname "Cc" :shortname "Cc"
:help "Carbon-Copy recipients for the message" :help "Carbon-Copy recipients for the message"
:sortable t)) :sortable t))
(:date (:date .
( :name "Date" ( :name "Date"
:shortname "Date" :shortname "Date"
:help "Date/time when the message was written" :help "Date/time when the message was written"
:sortable t)) :sortable t))
(:flags (:flags .
( :name "Flags" ( :name "Flags"
:shortname "Flgs" :shortname "Flgs"
:help "Flags for the message" :help "Flags for the message"
:sortable t)) :sortable t))
(:from (:from .
( :name "From" ( :name "From"
:shortname "From" :shortname "From"
:help "The sender of the message" :help "The sender of the message"
:sortable t)) :sortable t))
(:from-or-to (:from-or-to .
( :name "From/To" ( :name "From/To"
:shortname "From/To" :shortname "From/To"
:help "Sender of the message if it's not me; otherwise :help "Sender of the message if it's not me; otherwise
the recipient" the recipient"
:sortable t)) :sortable t))
(:maildir (:maildir .
( :name "Maildir" ( :name "Maildir"
:shortname "Maildir" :shortname "Maildir"
:help "Maildir for this message" :help "Maildir for this message"
:sortable t)) :sortable t))
(:path (:path .
( :name "Path" ( :name "Path"
:shortname "Path" :shortname "Path"
:help "Full filesystem path to the message" :help "Full filesystem path to the message"
:sortable t)) :sortable t))
(:subject (:subject .
( :name "Subject" ( :name "Subject"
:shortname "S" :shortname "Subject"
:help "Subject of the message" :help "Subject of the message"
:sortable t)) :sortable t))
(:to (:to .
( :name "To" ( :name "To"
:shortname "T" :shortname "T"
:help "Recipient of the message" :help "Recipient of the message"

View File

@ -167,10 +167,10 @@ plist."
(:flags (mu4e~view-construct-header field (:flags (mu4e~view-construct-header field
(if fieldval (format "%S" fieldval) ""))) (if fieldval (format "%S" fieldval) "")))
;; contact fields ;; contact fields
(:to (mu4e~view-construct-contacts msg field)) (:to (mu4e~view-construct-contacts-header msg field))
(:from (mu4e~view-construct-contacts msg field)) (:from (mu4e~view-construct-contacts-header msg field))
(:cc (mu4e~view-construct-contacts msg field)) (:cc (mu4e~view-construct-contacts-header msg field))
(:bcc (mu4e~view-construct-contacts msg field)) (:bcc (mu4e~view-construct-contacts-header msg field))
;; if we (`user-mail-address' are the From, show To, otherwise, ;; if we (`user-mail-address' are the From, show To, otherwise,
;; show From ;; show From
@ -178,8 +178,8 @@ plist."
(let* ((from (plist-get msg :from)) (let* ((from (plist-get msg :from))
(from (and from (cdar from)))) (from (and from (cdar from))))
(if (and from (string-match mu4e-user-mail-address-regexp from)) (if (and from (string-match mu4e-user-mail-address-regexp from))
(mu4e~view-construct-contacts msg :to) (mu4e~view-construct-contacts-header msg :to)
(mu4e~view-construct-contacts msg :from)))) (mu4e~view-construct-contacts-header msg :from))))
;; date ;; date
(:date (:date
(let ((datestr (let ((datestr
@ -192,7 +192,7 @@ plist."
(sizestr (when size (format "%d bytes" size)))) (sizestr (when size (format "%d bytes" size))))
(if sizestr (mu4e~view-construct-header field sizestr)))) (if sizestr (mu4e~view-construct-header field sizestr))))
;; attachments ;; attachments
(:attachments (mu4e~view-construct-attachments msg)) (:attachments (mu4e~view-construct-attachments-header msg))
(t (mu4e-error "Unsupported field: %S" field))))) (t (mu4e-error "Unsupported field: %S" field)))))
mu4e-view-fields "") mu4e-view-fields "")
"\n" "\n"
@ -237,12 +237,12 @@ marking if it still had that."
;; no use in trying to set flags again ;; no use in trying to set flags again
(mu4e~view-mark-as-read-maybe)))))) (mu4e~view-mark-as-read-maybe))))))
(defun mu4e~view-construct-header (field val &optional dont-propertize-val) (defun mu4e~view-construct-header (field val &optional dont-propertize-val)
"Return header field FIELD (as in `mu4e-header-info') with value "Return header field FIELD (as in `mu4e-header-info') with value
VAL if VAL is non-nil. If DONT-PROPERTIZE-VAL is non-nil, do not VAL if VAL is non-nil. If DONT-PROPERTIZE-VAL is non-nil, do not
add text-properties to VAL." add text-properties to VAL."
(let* ((info (cadr (assoc field mu4e-header-info))) (let* ((info (cdr (assoc field mu4e-header-info)))
(key (plist-get info :name)) (key (plist-get info :name))
(help (plist-get info :help))) (help (plist-get info :help)))
(if (and val (> (length val) 0)) (if (and val (> (length val) 0))
@ -263,7 +263,7 @@ add text-properties to VAL."
(buffer-string)) (buffer-string))
""))) "")))
(defun mu4e~view-construct-contacts (msg field) (defun mu4e~view-construct-contacts-header (msg field)
"Add a header for a contact field (ie., :to, :from, :cc, :bcc)." "Add a header for a contact field (ie., :to, :from, :cc, :bcc)."
(mu4e~view-construct-header field (mu4e~view-construct-header field
(mapconcat (mapconcat
@ -288,7 +288,7 @@ is nil, and otherwise open it."
(mu4e-view-open-attachment msg attachnum) (mu4e-view-open-attachment msg attachnum)
(mu4e-view-save-attachment-single msg attachnum))))) (mu4e-view-save-attachment-single msg attachnum)))))
(defun mu4e~view-construct-attachments (msg) (defun mu4e~view-construct-attachments-header (msg)
"Display attachment information; the field looks like something like: "Display attachment information; the field looks like something like:
:parts ((:index 1 :name \"test123.doc\" :parts ((:index 1 :name \"test123.doc\"
:mime-type \"application/msword\" :attachment t :size 1234) :mime-type \"application/msword\" :attachment t :size 1234)
@ -332,7 +332,8 @@ is nil, and otherwise open it."
'face 'mu4e-view-header-key-face))))))) 'face 'mu4e-view-header-key-face)))))))
attachments ", "))) attachments ", ")))
(unless (zerop id) (unless (zerop id)
(mu4e~view-construct-header (format "Attachments(%d)" id) attstr t)))) (mu4e~view-construct-header
:attachments (format "%s (%d)" attstr id) t))))
(defun mu4e-view-for-each-part (msg func) (defun mu4e-view-for-each-part (msg func)
"Apply FUNC to each part in MSG. FUNC should be a function taking two arguments; "Apply FUNC to each part in MSG. FUNC should be a function taking two arguments;