mu4e-view: update field handling

Restrict fields in mu4e-view-fields. Make the defcustom a bit more
helpful by checking for valid fields.

Add :labels to default fields

Remove some unused code.
This commit is contained in:
Dirk-Jan C. Binnema
2026-04-11 11:04:04 +03:00
committed by Seth Ladygo
parent 0aff86690a
commit b33f1450f0
5 changed files with 38 additions and 16 deletions

View File

@ -68,7 +68,7 @@
"A list of header fields to show in the headers buffer.
Each element has the form (HEADER . WIDTH), where HEADER is one of
the available headers (see `mu4e-header-info') and WIDTH is the
respective width in characters.
respective width in characters
A width of nil means \"unrestricted\", and this is best reserved
for the rightmost (last) field. Note that emacs may become very
@ -83,16 +83,11 @@ altogether."
mu4e-header-info)
(restricted-sexp
:tag "User-specified header"
:match-alternatives (mu4e--headers-header-p)))
:match-alternatives (mu4e--valid-header-p)))
(choice (integer :tag "width")
(const :tag "unrestricted width" nil))))
:group 'mu4e-headers)
(defun mu4e--headers-header-p (symbol)
"Is SYMBOL a valid mu4e header?
This means its either one of the build-in or user-specified headers."
(assoc symbol (append mu4e-header-info mu4e-header-info-custom)))
(defcustom mu4e-headers-date-format "%x"
"Date format to use in the headers view.
In the format of `format-time-string'."

View File

@ -379,6 +379,13 @@ Note that when using the gnus-based view, you only have access to
a limited set of message fields: only the ones used in the
header-view, not including, for instance, the message body.")
(defun mu4e--valid-header-p (symbol)
"Is SYMBOL a valid mu4e header?
This means its either one of the build-in or user-specified headers."
(assoc symbol (append mu4e-header-info mu4e-header-info-custom)))
;;; Internals
(defvar-local mu4e~headers-view-win nil

View File

@ -61,17 +61,27 @@ Otherwise, don't move to the next message."
:group 'mu4e-view)
(defcustom mu4e-view-fields
'(:from :to :cc :subject :flags :date :maildir :mailing-list :tags)
"Header fields to display in the message view buffer.
'(:from :to :cc :subject :flags :date
:maildir :mailing-list :tags :labels)
"Mu4e header fields to display in the message view buffer.
For the complete list of available headers, see
`mu4e-header-info'.
Note, you can use this to add fields that are not otherwise
shown; you can further tweak the other fields using e.g.,
`gnus-visible-headers' and `gnus-ignored-headers' - see the gnus
documentation for details."
:type '(repeat symbol)
In addition to the mu4e fields, Gnus _also_ can show fields; See
`gnus-visible-headers' and `gnus-ignored-headers'. A special case
is the Attachments: header: see
`gnus-mime-display-attachment-buttons-in-header', and
`gnus-mime-button-line-format' for tweaking the appearance."
:type `(repeat (choice
,@(mapcar (lambda (h)
(list 'const :tag
(plist-get (cdr h) :help)
(car h)))
mu4e-header-info)
(restricted-sexp
:tag "User-specified header"
:match-alternatives (mu4e--valid-header-p))))
:group 'mu4e-view)
(defcustom mu4e-view-actions
@ -579,7 +589,6 @@ activates URLs (in plain-text mode only)."
(charset (and charset (intern charset)))
(mu4e--view-rendering t) ;; needed if e.g. an ics file is buttonized
(gnus-article-emulate-mime nil) ;; avoid perf problems
(gnus-mime-button-line-format "%{%([%p. %n]%)%}%e\n")
(gnus-newsgroup-charset
(if (and charset (coding-system-p charset)) charset
(detect-coding-region (point-min) (point-max) t)))
@ -696,7 +705,6 @@ render. After inserting, highlight the headers."
;; otherwise they are handled by Gnus.
(when-let* ((raw (and raw-headers (cdr (assq field raw-headers)))))
(mu4e--view-gnus-insert-header field raw)))
((or ':attachments ':signature ':decryption)) ;; skip
(_
(mu4e--view-gnus-insert-header-custom msg field)))))
;; Highlight the header block we just inserted

View File

@ -1416,6 +1416,9 @@ from the built-in fields, you can also create custom fields using
end of a message,it automatically takes you to the next one. If you want
to prevent this behavior, set @code{mu4e-view-scroll-to-next} to
@code{nil}.
@item Since attachments are also shown in the message-body, you can suppress the @t{Attachments:} headder;
by customizing @code{gnus-mime-display-attachment-buttons-in-header} or tweak
the appearance through @code{gnus-mime-button-line-format}
@end itemize
@node MSGV Keybindings