mu4e-headers: whitespace/newline cleanups

This commit is contained in:
Dirk-Jan C. Binnema 2022-12-11 12:42:48 +02:00
parent 713ae1e98b
commit 6278d1f18a
1 changed files with 126 additions and 100 deletions

View File

@ -32,7 +32,8 @@
(require 'fringe)
(require 'hl-line)
(require 'mailcap)
(require 'mule-util) ;; seems _some_ people need this for truncate-string-ellipsis
(require 'mule-util) ;; seems _some_ people need this for
;; truncate-string-ellipsis
(require 'mu4e-update)
@ -142,7 +143,8 @@ Example that hides all trashed messages:
(member \='trashed (mu4e-message-field msg :flags)))).")
(defcustom mu4e-headers-visible-flags
'(draft flagged new passed replied trashed attach encrypted signed list personal)
'(draft flagged new passed replied trashed attach encrypted signed
list personal)
"An ordered list of flags to show in the headers buffer.
Each element is a symbol in the list.
@ -159,9 +161,9 @@ mostly covered by `new', and the display gets cluttered otherwise."
(const :tag "Attach" attach)
(const :tag "Encrypted" encrypted)
(const :tag "Signed" signed)
(const :tag "List" list)
(const :tag "Personal" personal)
(const :tag "Calendar" calendar))
(const :tag "List" list)
(const :tag "Personal" personal)
(const :tag "Calendar" calendar))
:group 'mu4e-headers)
(defcustom mu4e-headers-found-hook nil
@ -346,7 +348,7 @@ Optionally, show TEXT."
(with-current-buffer (mu4e-get-headers-buffer)
(mu4e--mark-clear)
(erase-buffer)
(when text
(when text
(goto-char (point-min))
(insert (propertize text 'face 'mu4e-system-face 'intangible t)))))))
@ -359,7 +361,7 @@ into a string."
(mapconcat
(lambda (contact)
(let ((name (mu4e-contact-name contact))
(email (mu4e-contact-email contact)))
(email (mu4e-contact-email contact)))
(or name email "?"))) contacts ", "))
(defun mu4e~headers-thread-prefix-map (type)
@ -374,7 +376,8 @@ into a string."
(connection (funcall get-prefix mu4e-headers-thread-connection-prefix))
(blank (funcall get-prefix mu4e-headers-thread-blank-prefix))
(orphan (funcall get-prefix mu4e-headers-thread-orphan-prefix))
(single-orphan (funcall get-prefix mu4e-headers-thread-single-orphan-prefix))
(single-orphan (funcall get-prefix
mu4e-headers-thread-single-orphan-prefix))
(duplicate (funcall get-prefix mu4e-headers-thread-duplicate-prefix))
(t "?"))))
@ -481,7 +484,8 @@ with DOCID which must be present in the headers buffer."
(if single-orphan 'single-orphan
(if (and orphan
(or first-child
(not (eq mu4e-headers-thread-mark-as-orphan 'first))))
(not (eq mu4e-headers-thread-mark-as-orphan
'first))))
'orphan
(if last-child 'last-child
(if first-child 'first-child
@ -507,14 +511,14 @@ function is for display. (This difference is significant, since
internally, the Maildir spec determines what the flags look like,
while our display may be different)."
(or (mapconcat
(lambda (flag)
(when (member flag mu4e-headers-visible-flags)
(if-let* ((mark (intern-soft
(format "mu4e-headers-%s-mark" (symbol-name flag))))
(cell (symbol-value mark)))
(if mu4e-use-fancy-chars (cdr cell) (car cell))
"")))
flags "")
(lambda (flag)
(when (member flag mu4e-headers-visible-flags)
(if-let* ((mark (intern-soft
(format "mu4e-headers-%s-mark" (symbol-name flag))))
(cell (symbol-value mark)))
(if mu4e-use-fancy-chars (cdr cell) (car cell))
"")))
flags "")
""))
;;; Special headers
@ -526,8 +530,8 @@ addresses, (as per `mu4e-personal-address-p'), show the To
address. Otherwise, show the From address, prefixed with the
appropriate `mu4e-headers-from-or-to-prefix'."
(let* ((from1 (car-safe (mu4e-message-field msg :from)))
(from1-addr (and from1 (mu4e-contact-email from1)))
(is-user (and from1-addr (mu4e-personal-address-p from1-addr))))
(from1-addr (and from1 (mu4e-contact-email from1)))
(is-user (and from1-addr (mu4e-personal-address-p from1-addr))))
(if is-user
(concat (cdr mu4e-headers-from-or-to-prefix)
(mu4e~headers-contact-str (mu4e-message-field msg :to)))
@ -591,8 +595,8 @@ found."
(truncate-string-to-width val 600)))
(:thread-subject ;; if not searching threads, fall back to :subject
(if mu4e-search-threads
(mu4e~headers-thread-subject msg)
(mu4e~headers-field-value msg :subject)))
(mu4e~headers-thread-subject msg)
(mu4e~headers-field-value msg :subject)))
((:maildir :path :message-id) val)
((:to :from :cc :bcc) (mu4e~headers-contact-str val))
;; if we (ie. `user-mail-address' is the 'From', show
@ -650,23 +654,26 @@ space propertized with a `display' text property which expands to
(let* ((field (car f-w))
(width (cdr f-w))
(val (mu4e~headers-field-value msg field))
(val (and val (if width (mu4e~headers-truncate-field field val width) val))))
(val (and val
(if width
(mu4e~headers-truncate-field field val width)
val))))
val))
(defsubst mu4e~headers-apply-flags (msg fieldval)
"Adjust FIELDVAL's face property based on flags in MSG."
(let* ((flags (plist-get msg :flags))
(meta (plist-get msg :meta))
(face (cond
((memq 'trashed flags) 'mu4e-trashed-face)
(meta (plist-get msg :meta))
(face (cond
((memq 'trashed flags) 'mu4e-trashed-face)
((memq 'draft flags) 'mu4e-draft-face)
((or (memq 'unread flags) (memq 'new flags))
'mu4e-unread-face)
((memq 'flagged flags) 'mu4e-flagged-face)
((plist-get meta :related) 'mu4e-related-face)
((plist-get meta :related) 'mu4e-related-face)
((memq 'replied flags) 'mu4e-replied-face)
((memq 'passed flags) 'mu4e-forwarded-face)
(t 'mu4e-header-face))))
(t 'mu4e-header-face))))
(add-face-text-property 0 (length fieldval) face t fieldval)
fieldval))
@ -684,7 +691,7 @@ displaying in the header view."
(defsubst mu4e~headers-insert-header (msg pos)
"Insert a header for MSG at point POS."
(when-let ((line (mu4e~message-header-line msg))
(docid (plist-get msg :docid)))
(docid (plist-get msg :docid)))
(goto-char pos)
(insert
(propertize
@ -716,7 +723,8 @@ docid is not found."
(defun mu4e~headers-view-this-message-p (docid)
"Is DOCID currently being viewed?"
(mu4e-get-view-buffers (lambda (_) (eq docid (plist-get mu4e~view-message :docid)))))
(mu4e-get-view-buffers
(lambda (_) (eq docid (plist-get mu4e~view-message :docid)))))
;; note: this function is very performance-sensitive
(defun mu4e~headers-append-handler (msglst)
@ -725,11 +733,11 @@ Do this at the end of the headers-buffer."
(when (buffer-live-p (mu4e-get-headers-buffer))
(with-current-buffer (mu4e-get-headers-buffer)
(save-excursion
(let ((inhibit-read-only t))
(seq-do
(lambda (msg)
(mu4e~headers-insert-header msg (point-max)))
msglst))))))
(let ((inhibit-read-only t))
(seq-do
(lambda (msg)
(mu4e~headers-insert-header msg (point-max)))
msglst))))))
(defun mu4e~headers-update-handler (msg is-move maybe-view)
@ -741,7 +749,7 @@ headers."
(let* ((docid (mu4e-message-field msg :docid))
(initial-message-at-point (mu4e~headers-docid-at-point))
(initial-column (current-column))
(inhibit-read-only t)
(inhibit-read-only t)
(point (mu4e~headers-docid-pos docid))
(markinfo (gethash docid mu4e--mark-map)))
(when point ;; is the message present in this list?
@ -772,8 +780,8 @@ headers."
;; longer matches the query, but this seem a good heuristic. if it
;; was only a flag-change, show the message with its updated flags.
(unless is-move
(save-excursion
(mu4e~headers-insert-header msg point)))
(save-excursion
(mu4e~headers-insert-header msg point)))
;; restore the mark, if any. See #2076.
(when (and markinfo (mu4e~headers-goto-docid docid))
@ -848,16 +856,16 @@ true, do *not* update the query history stack."
(defun mu4e~headers-benchmark-message (count)
"Get some report message for messaging search and rendering speed."
(if (and mu4e-headers-report-render-time
mu4e~headers-search-start
mu4e~headers-render-start
(> count 0))
mu4e~headers-search-start
mu4e~headers-render-start
(> count 0))
(let ((render-time-ms (* 1000(- (float-time) mu4e~headers-render-start)))
(search-time-ms (* 1000(- (float-time) mu4e~headers-search-start))))
(format (concat
"; search: %0.1f ms (%0.2f ms/msg)"
"; render: %0.1f ms (%0.2f ms/msg)")
search-time-ms (/ search-time-ms count)
render-time-ms (/ render-time-ms count)))
(search-time-ms (* 1000(- (float-time) mu4e~headers-search-start))))
(format (concat
"; search: %0.1f ms (%0.2f ms/msg)"
"; render: %0.1f ms (%0.2f ms/msg)")
search-time-ms (/ search-time-ms count)
render-time-ms (/ render-time-ms count)))
""))
(defun mu4e~headers-found-handler (count)
@ -871,7 +879,7 @@ after the end of the search results."
(str (if (zerop count) mu4e~no-matches mu4e~end-of-results))
(msg (format "Found %d matching message%s%s"
count (if (= 1 count) "" "s")
(mu4e~headers-benchmark-message count))))
(mu4e~headers-benchmark-message count))))
(insert (propertize str 'face 'mu4e-system-face 'intangible t))
(unless (zerop count)
@ -882,7 +890,8 @@ after the end of the search results."
(when mu4e--search-msgid-target
(if (eq (current-buffer) (window-buffer))
(mu4e-headers-goto-message-id mu4e--search-msgid-target)
(let* ((pos (mu4e-headers-goto-message-id mu4e--search-msgid-target)))
(let* ((pos (mu4e-headers-goto-message-id
mu4e--search-msgid-target)))
(when pos
(set-window-point (get-buffer-window nil t) pos)))))
(when (and mu4e--search-view-target (mu4e-message-at-point 'noerror))
@ -931,10 +940,10 @@ after the end of the search results."
(define-key map "j" 'mu4e~headers-jump-to-maildir)
(define-key map "O" 'mu4e-headers-change-sorting)
(define-key map "M" 'mu4e-headers-toggle-setting)
(define-key map "M" 'mu4e-headers-toggle-setting)
;; these are impossible to remember; use mu4e-headers-toggle-setting
;; instead :)
;; these are impossible to remember; use mu4e-headers-toggle-setting
;; instead :)
(define-key map "P" 'mu4e-headers-toggle-threading)
(define-key map "Q" 'mu4e-headers-toggle-full-search)
(define-key map "W" 'mu4e-headers-toggle-include-related)
@ -947,7 +956,7 @@ after the end of the search results."
(define-key map "t" 'mu4e-headers-mark-subthread)
(define-key map "T" 'mu4e-headers-mark-thread)
(define-key map "," #'mu4e-sexp-at-point)
(define-key map "," #'mu4e-sexp-at-point)
;; navigation between messages
(define-key map "p" 'mu4e-headers-prev)
@ -962,7 +971,8 @@ after the end of the search results."
(define-key map (kbd "C-+") 'mu4e-headers-split-view-grow)
(define-key map (kbd "C--") 'mu4e-headers-split-view-shrink)
(define-key map (kbd "<C-kp-add>") 'mu4e-headers-split-view-grow)
(define-key map (kbd "<C-kp-subtract>") 'mu4e-headers-split-view-shrink)
(define-key map (kbd "<C-kp-subtract>")
'mu4e-headers-split-view-shrink)
;; switching to view mode (if it's visible)
(define-key map "y" 'mu4e-select-other-view)
@ -986,10 +996,14 @@ after the end of the search results."
(define-key map (kbd "=") 'mu4e-headers-mark-for-untrash)
(define-key map (kbd "&") 'mu4e-headers-mark-custom)
(define-key map (kbd "*") 'mu4e-headers-mark-for-something)
(define-key map (kbd "<kp-multiply>") 'mu4e-headers-mark-for-something)
(define-key map (kbd "<insertchar>") 'mu4e-headers-mark-for-something)
(define-key map (kbd "<insert>") 'mu4e-headers-mark-for-something)
(define-key map (kbd "*")
'mu4e-headers-mark-for-something)
(define-key map (kbd "<kp-multiply>")
'mu4e-headers-mark-for-something)
(define-key map (kbd "<insertchar>")
'mu4e-headers-mark-for-something)
(define-key map (kbd "<insert>")
'mu4e-headers-mark-for-something)
(define-key map (kbd "#") 'mu4e-mark-resolve-deferred-marks)
@ -1104,7 +1118,7 @@ after the end of the search results."
(field (car item)) (width (cdr item))
(info (cdr (assoc field
(append mu4e-header-info mu4e-header-info-custom))))
(sortable (plist-get info :sortable))
(sortable (plist-get info :sortable))
;; if sortable, it is either t (when field is sortable itself)
;; or a symbol (if another field is used for sorting)
(this-field (when sortable (if (booleanp sortable) field sortable)))
@ -1143,8 +1157,8 @@ after the end of the search results."
some changes, `mu4e-headers-auto-update' is non-nil and there is
no user-interaction ongoing."
(when (and mu4e-headers-auto-update ;; must be set
mu4e-index-update-status
(not (zerop (plist-get mu4e-index-update-status :updated)))
mu4e-index-update-status
(not (zerop (plist-get mu4e-index-update-status :updated)))
;; NOTE: `mu4e-mark-marks-num' can return nil. Is that intended?
(zerop (or (mu4e-mark-marks-num) 0)) ;; non active marks
(not (active-minibuffer-window))) ;; no user input only
@ -1287,21 +1301,23 @@ message plist, or nil if not found."
(defvar mu4e~headers-mode-line-label "")
(defun mu4e~headers-update-mode-line ()
"Update mode-line settings."
(let* ((flagstr
(mapconcat
(lambda (flag-cell)
(if (car flag-cell)
(if mu4e-use-fancy-chars
(cddr flag-cell) (cadr flag-cell) ) ""))
`((,mu4e-search-full . ,mu4e-headers-full-label)
(,mu4e-headers-include-related . ,mu4e-headers-related-label)
(,mu4e-search-threads . ,mu4e-headers-threaded-label)
(,mu4e-headers-skip-duplicates . ,mu4e-headers-skip-duplicates-label))
""))
(name "mu4e-headers"))
(let* ((flagstr
(mapconcat
(lambda (flag-cell)
(if (car flag-cell)
(if mu4e-use-fancy-chars
(cddr flag-cell) (cadr flag-cell) ) ""))
`((,mu4e-search-full . ,mu4e-headers-full-label)
(,mu4e-headers-include-related . ,mu4e-headers-related-label)
(,mu4e-search-threads . ,mu4e-headers-threaded-label)
(,mu4e-headers-skip-duplicates
. ,mu4e-headers-skip-duplicates-label))
""))
(name "mu4e-headers"))
(setq mode-name name)
(setq mu4e~headers-mode-line-label (concat flagstr " " mu4e--search-last-query))
(setq mu4e~headers-mode-line-label
(concat flagstr " " mu4e--search-last-query))
(make-local-variable 'global-mode-string)
@ -1405,9 +1421,10 @@ matching messages with that mark."
(if (member field '(:to :from :cc :bcc :reply-to))
(cl-find-if (lambda (contact)
(let ((name (mu4e-contact-name contact))
(email (mu4e-contact-email contact)))
(email (mu4e-contact-email contact)))
(or (and name (string-match pattern name))
(and email (string-match pattern email))))) value)
(and email (string-match pattern email)))))
value)
(string-match pattern (or value ""))))))))
(defun mu4e-headers-mark-custom ()
@ -1501,7 +1518,8 @@ user)."
(or field
(mu4e-read-option "Sortfield: " mu4e~headers-sort-field-choices)))
;; note: 'sortable' is either a boolean (meaning: if non-nil, this is
;; sortable field), _or_ another field (meaning: sort by this other field).
;; sortable field), _or_ another field (meaning: sort by this other
;; field).
(sortable (plist-get (cdr (assoc field mu4e-header-info)) :sortable))
;; error check
(sortable
@ -1533,21 +1551,22 @@ When prefix-argument DONT-REFRESH is non-nill, do not refresh the
last search with the new setting."
(interactive "P")
(let* ((toggles '(("fFull-search" . mu4e-search-full)
("rInclude-related" . mu4e-headers-include-related)
("tShow threads" . mu4e-search-threads)
("uSkip duplicates" . mu4e-headers-skip-duplicates)))
(toggles (seq-map
(lambda (cell)
(cons
(concat (car cell) (format" (%s)"
(if (symbol-value (cdr cell)) "on" "off")))
(cdr cell))) toggles))
(choice (mu4e-read-option "Toggle setting " toggles)))
("rInclude-related" . mu4e-headers-include-related)
("tShow threads" . mu4e-search-threads)
("uSkip duplicates" . mu4e-headers-skip-duplicates)))
(toggles (seq-map
(lambda (cell)
(cons
(concat (car cell)
(format" (%s)"
(if (symbol-value (cdr cell)) "on" "off")))
(cdr cell))) toggles))
(choice (mu4e-read-option "Toggle setting " toggles)))
(when choice
(set choice (not (symbol-value choice)))
(mu4e-message "Set `%s' to %s" (symbol-name choice) (symbol-value choice))
(unless dont-refresh
(mu4e-search-rerun)))))
(mu4e-search-rerun)))))
(defun mu4e~headers-toggle (name togglevar dont-refresh)
@ -1595,9 +1614,9 @@ _not_ refresh the last search with the new setting for threading."
(unless (eq major-mode 'mu4e-headers-mode)
(mu4e-error "Must be in mu4e-headers-mode (%S)" major-mode))
(let* ((msg (mu4e-message-at-point))
(path (mu4e-message-field msg :path))
(_exists (or (file-readable-p path)
(mu4e-warn "No message at %s" path)))
(path (mu4e-message-field msg :path))
(_exists (or (file-readable-p path)
(mu4e-warn "No message at %s" path)))
(docid (or (mu4e-message-field msg :docid)
(mu4e-warn "No message at point")))
(mark-as-read
@ -1622,12 +1641,12 @@ return nil."
(condition-case _err
(prog1
(let (line-move-visual)
(and (line-move arg) 0))
(and (line-move arg) 0))
;; Skip invisible text at BOL possibly hidden by
;; the end of another invisible overlay covering
;; previous EOL.
(move-to-column 2))
((beginning-of-buffer end-of-buffer)
((beginning-of-buffer end-of-buffer)
1))))
(let* ((succeeded (zerop (goto-next-line lines)))
(docid (mu4e~headers-docid-at-point)))
@ -1637,7 +1656,8 @@ return nil."
;; update all windows showing the headers buffer
(walk-windows
(lambda (win)
(when (eq (window-buffer win) (mu4e-get-headers-buffer (buffer-name)))
(when (eq (window-buffer win)
(mu4e-get-headers-buffer (buffer-name)))
(set-window-point win (point))))
nil t)
;; If the assigned (and buffer-local) `mu4e~headers-view-win'
@ -1649,8 +1669,8 @@ return nil."
;; attempt to highlight the new line, display the message
(mu4e~headers-highlight docid)
(if succeeded
docid
nil)))))
docid
nil)))))
(defun mu4e-headers-next (&optional n)
"Move point to the next message header.
@ -1701,7 +1721,8 @@ given, offer to edit the search query before executing it."
(list maildir current-prefix-arg)))
(when maildir
(let* ((query (format "maildir:\"%s\"" maildir))
(query (if edit (mu4e-search-read-query "Refine query: " query) query)))
(query (if edit
(mu4e-search-read-query "Refine query: " query) query)))
(mu4e-mark-handle-when-leaving)
(mu4e-search query))))
@ -1741,7 +1762,8 @@ pass ACTIONFUNC, which is a function that takes a msg-plist
argument."
(interactive)
(let ((msg (mu4e-message-at-point))
(afunc (or actionfunc (mu4e-read-option "Action: " mu4e-headers-actions))))
(afunc (or actionfunc
(mu4e-read-option "Action: " mu4e-headers-actions))))
(funcall afunc msg)))
(defun mu4e-headers-mark-and-next (mark)
@ -1779,14 +1801,18 @@ other windows."
(when mu4e-dim-when-loading
(setq mu4e--loading-overlay-bg
(let ((overlay (make-overlay (point-min) (point-max))))
(overlay-put overlay 'face `(:foreground "gray22" :background
,(face-attribute 'default :background)))
(overlay-put overlay 'face
`(:foreground "gray22" :background
,(face-attribute 'default
:background)))
(overlay-put overlay 'priority 9998)
overlay)))
(setq mu4e--loading-overlay-text
(let ((overlay (make-overlay (point-min) (point-min))))
(overlay-put overlay 'priority 9999)
(overlay-put overlay 'before-string (propertize "Loading…\n" 'face 'mu4e-header-title-face))
(overlay-put overlay 'before-string
(propertize "Loading…\n"
'face 'mu4e-header-title-face))
overlay)))
(when mu4e--loading-overlay-bg
(delete-overlay mu4e--loading-overlay-bg))