mirror of https://github.com/djcb/mu.git
mu4e-headers: optimize header writing a bit
Try to make writing out the headers in the headers buffer slightly faster.
This commit is contained in:
parent
73f4c49364
commit
3715bb0c5e
|
@ -121,7 +121,7 @@ query) ignore the limit by pressing a C-u before invoking the
|
||||||
search.
|
search.
|
||||||
|
|
||||||
Note that there are a few complications when
|
Note that there are a few complications when
|
||||||
`mu4e-headers-include-related' is enabled: mu perform *two*
|
`mu4e-headers-include-related' is enabled: mu performs *two*
|
||||||
queries; the first one with this limit set, and then a second
|
queries; the first one with this limit set, and then a second
|
||||||
(unlimited) query for all messages that are related to the first
|
(unlimited) query for all messages that are related to the first
|
||||||
matches. We then limit this second result as well, favoring the
|
matches. We then limit this second result as well, favoring the
|
||||||
|
@ -643,7 +643,7 @@ show the subject of a thread only once, similar to e.g. 'mutt'."
|
||||||
(propertize (mu4e-get-mailing-list-shortname list) 'help-echo list)
|
(propertize (mu4e-get-mailing-list-shortname list) 'help-echo list)
|
||||||
""))
|
""))
|
||||||
|
|
||||||
(defun mu4e~headers-custom-field (msg field)
|
(defsubst mu4e~headers-custom-field-value (msg field)
|
||||||
"Show some custom header field, or raise an error if it is not
|
"Show some custom header field, or raise an error if it is not
|
||||||
found."
|
found."
|
||||||
(let* ((item (or (assoc field mu4e-header-info-custom)
|
(let* ((item (or (assoc field mu4e-header-info-custom)
|
||||||
|
@ -653,56 +653,65 @@ found."
|
||||||
field (cdr item)))))
|
field (cdr item)))))
|
||||||
(funcall func msg)))
|
(funcall func msg)))
|
||||||
|
|
||||||
(defun mu4e~headers-field-apply-basic-properties (msg field val _width)
|
(defsubst mu4e~headers-field-value (msg field)
|
||||||
(cl-case field
|
(let ((val (mu4e-message-field msg field)))
|
||||||
(:subject
|
(cl-case field
|
||||||
(concat ;; prefix subject with a thread indicator
|
(:subject
|
||||||
(mu4e~headers-thread-prefix (mu4e-message-field msg :thread))
|
(concat ;; prefix subject with a thread indicator
|
||||||
;; "["(plist-get (mu4e-message-field msg :thread) :path) "] "
|
(mu4e~headers-thread-prefix (mu4e-message-field msg :thread))
|
||||||
;; work-around: emacs' display gets really slow when lines are too long;
|
;; "["(plist-get (mu4e-message-field msg :thread) :path) "] "
|
||||||
;; so limit subject length to 600
|
;; work-around: emacs' display gets really slow when lines are too long;
|
||||||
(truncate-string-to-width val 600)))
|
;; so limit subject length to 600
|
||||||
(:thread-subject (mu4e~headers-thread-subject msg))
|
(truncate-string-to-width val 600)))
|
||||||
((:maildir :path :message-id) val)
|
(:thread-subject (mu4e~headers-thread-subject msg))
|
||||||
((:to :from :cc :bcc) (mu4e~headers-contact-str val))
|
((:maildir :path :message-id) val)
|
||||||
;; if we (ie. `user-mail-address' is the 'From', show
|
((:to :from :cc :bcc) (mu4e~headers-contact-str val))
|
||||||
;; 'To', otherwise show From
|
;; if we (ie. `user-mail-address' is the 'From', show
|
||||||
(:from-or-to (mu4e~headers-from-or-to msg))
|
;; 'To', otherwise show From
|
||||||
(:date (format-time-string mu4e-headers-date-format val))
|
(:from-or-to (mu4e~headers-from-or-to msg))
|
||||||
(:mailing-list (mu4e~headers-mailing-list val))
|
(:date (format-time-string mu4e-headers-date-format val))
|
||||||
(:human-date (propertize (mu4e~headers-human-date msg)
|
(:mailing-list (mu4e~headers-mailing-list val))
|
||||||
'help-echo (format-time-string
|
(:human-date (propertize (mu4e~headers-human-date msg)
|
||||||
mu4e-headers-long-date-format
|
'help-echo (format-time-string
|
||||||
(mu4e-msg-field msg :date))))
|
mu4e-headers-long-date-format
|
||||||
(:flags (propertize (mu4e~headers-flags-str val)
|
(mu4e-msg-field msg :date))))
|
||||||
'help-echo (format "%S" val)))
|
(:flags (propertize (mu4e~headers-flags-str val)
|
||||||
(:tags (propertize (mapconcat 'identity val ", ")))
|
'help-echo (format "%S" val)))
|
||||||
(:size (mu4e-display-size val))
|
(:tags (propertize (mapconcat 'identity val ", ")))
|
||||||
(t (mu4e~headers-custom-field msg field))))
|
(:size (mu4e-display-size val))
|
||||||
|
(t (mu4e~headers-custom-field-value msg field)))))
|
||||||
|
|
||||||
(defun mu4e~headers-field-truncate-to-width (_msg _field val width)
|
(defsubst mu4e~headers-truncate-field (val width)
|
||||||
"Truncate VAL to WIDTH."
|
"Truncate VAL to WIDTH."
|
||||||
(if width
|
(if width
|
||||||
(truncate-string-to-width val width 0 ?\s truncate-string-ellipsis)
|
(truncate-string-to-width val width 0 ?\s truncate-string-ellipsis)
|
||||||
val))
|
val))
|
||||||
|
|
||||||
(defvar mu4e~headers-field-handler-functions
|
|
||||||
'(mu4e~headers-field-apply-basic-properties
|
|
||||||
mu4e~headers-field-truncate-to-width))
|
|
||||||
|
|
||||||
(defun mu4e~headers-field-handler (f-w msg)
|
(defcustom mu4e-headers-field-properties-function nil
|
||||||
|
"Function that specifies custom text properties for a header field.
|
||||||
|
|
||||||
|
The function takes a message-plist and a field-id, and is expected to
|
||||||
|
return either nil or a property-list with text-properties to apply.
|
||||||
|
|
||||||
|
This allows for turning the list of message headers into an angry
|
||||||
|
fruit salad. Note that this function is called for each relevant
|
||||||
|
field of each message and thus should you should be careful to
|
||||||
|
avoid slowdowns."
|
||||||
|
:type 'function
|
||||||
|
:group 'mu4e-headers)
|
||||||
|
|
||||||
|
|
||||||
|
(defsubst mu4e~headers-field-handler (f-w msg)
|
||||||
"Create a description of the field of MSG described by F-W."
|
"Create a description of the field of MSG described by F-W."
|
||||||
(let* ((field (car f-w))
|
(let* ((field-id (car f-w))
|
||||||
(width (cdr f-w))
|
(width (cdr f-w))
|
||||||
(val (mu4e-message-field msg (car f-w))))
|
(val (mu4e~headers-field-value msg field-id))
|
||||||
(dolist (func mu4e~headers-field-handler-functions)
|
(val (if width (mu4e~headers-truncate-field val width) val)))
|
||||||
(setq val (funcall func msg field val width)))
|
|
||||||
val))
|
val))
|
||||||
|
|
||||||
(defvar mu4e~headers-line-handler-functions
|
|
||||||
'(mu4e~headers-line-apply-flag-face))
|
|
||||||
|
|
||||||
(defun mu4e~headers-line-apply-flag-face (msg line)
|
(defsubst mu4e~headers-apply-flags (msg fieldval)
|
||||||
"Adjust LINE's face property based on FLAGS."
|
"Adjust LINE's face property based on FLAGS."
|
||||||
(let* ((flags (mu4e-message-field msg :flags))
|
(let* ((flags (mu4e-message-field msg :flags))
|
||||||
(face (cond
|
(face (cond
|
||||||
|
@ -714,15 +723,18 @@ found."
|
||||||
((memq 'replied flags) 'mu4e-replied-face)
|
((memq 'replied flags) 'mu4e-replied-face)
|
||||||
((memq 'passed flags) 'mu4e-forwarded-face)
|
((memq 'passed flags) 'mu4e-forwarded-face)
|
||||||
(t 'mu4e-header-face))))
|
(t 'mu4e-header-face))))
|
||||||
;; hmmm, this only works with emacs 24.4+
|
(add-face-text-property 0 (length fieldval) face t fieldval)
|
||||||
(when (fboundp 'add-face-text-property)
|
fieldval))
|
||||||
(add-face-text-property 0 (length line) face t line))
|
|
||||||
line))
|
|
||||||
|
|
||||||
(defun mu4e~headers-line-handler (msg line)
|
(defsubst mu4e~message-header-line (msg)
|
||||||
(dolist (func mu4e~headers-line-handler-functions)
|
"Return a propertized description of MSG suitable for
|
||||||
(setq line (funcall func msg line)))
|
displaying in the header view."
|
||||||
line)
|
(unless (and mu4e-headers-hide-predicate
|
||||||
|
(funcall mu4e-headers-hide-predicate msg))
|
||||||
|
(mu4e~headers-apply-flags
|
||||||
|
msg
|
||||||
|
(mapconcat (lambda (f-w) (mu4e~headers-field-handler f-w msg))
|
||||||
|
mu4e-headers-fields " "))))
|
||||||
|
|
||||||
;; note: this function is very performance-sensitive
|
;; note: this function is very performance-sensitive
|
||||||
(defun mu4e~headers-header-handler (msg &optional point)
|
(defun mu4e~headers-header-handler (msg &optional point)
|
||||||
|
@ -730,21 +742,11 @@ found."
|
||||||
if provided, or at the end of the buffer otherwise."
|
if provided, or at the end of the buffer otherwise."
|
||||||
(when (buffer-live-p (mu4e-get-headers-buffer))
|
(when (buffer-live-p (mu4e-get-headers-buffer))
|
||||||
(with-current-buffer (mu4e-get-headers-buffer)
|
(with-current-buffer (mu4e-get-headers-buffer)
|
||||||
(let ((line (mu4e~message-header-description msg)))
|
(let ((line (mu4e~message-header-line msg)))
|
||||||
(when line
|
(when line
|
||||||
(mu4e~headers-add-header line (mu4e-message-field msg :docid)
|
(mu4e~headers-add-header line (mu4e-message-field msg :docid)
|
||||||
point msg))))))
|
point msg))))))
|
||||||
|
|
||||||
(defun mu4e~message-header-description (msg)
|
|
||||||
"Return a propertized description of MSG suitable for
|
|
||||||
displaying in the header view."
|
|
||||||
(unless (and mu4e-headers-hide-predicate
|
|
||||||
(funcall mu4e-headers-hide-predicate msg))
|
|
||||||
(let ((line (mapconcat
|
|
||||||
(lambda (f-w) (mu4e~headers-field-handler f-w msg))
|
|
||||||
mu4e-headers-fields " ")))
|
|
||||||
(mu4e~headers-line-handler msg line))))
|
|
||||||
|
|
||||||
(defconst mu4e~search-message "Searching...")
|
(defconst mu4e~search-message "Searching...")
|
||||||
(defconst mu4e~no-matches "No matching messages found")
|
(defconst mu4e~no-matches "No matching messages found")
|
||||||
(defconst mu4e~end-of-results "End of search results")
|
(defconst mu4e~end-of-results "End of search results")
|
||||||
|
|
Loading…
Reference in New Issue