mirror of https://github.com/djcb/mu.git
Add support for bug-reference auto-setup in mu4e-view-mode
The bug-reference mode in Emacs 28 has support for several kinds of auto-setup, one of them being for mail customizable by the variable `bug-reference-setup-from-mail-alist`. Add mu4e support for that so that users can simply do (add-hook 'mu4e-view-mode-hook #'bug-reference-mode) and have it working. Also squash one byte-compiler warning about the (at compile-time) undefined variable `gnus-article-buffer`. * mu4e/mu4e-utils.el (mu4e-view--try-setup-bug-reference-mode): New function.
This commit is contained in:
parent
cefd66159a
commit
b7fb722df6
|
@ -540,6 +540,7 @@ Or go to the top level if there is none."
|
|||
(with-current-buffer (mu4e-get-headers-buffer)
|
||||
mu4e~headers-last-query)))
|
||||
|
||||
(defvar gnus-article-buffer) ;; Fix byte-compiler warning.
|
||||
(defun mu4e-get-view-buffer ()
|
||||
"Get the view buffer, if any."
|
||||
(get-buffer
|
||||
|
@ -1342,6 +1343,38 @@ string will be shortened to fit if its length exceeds
|
|||
(insert (propertize "Loading message..."
|
||||
'face 'mu4e-system-face 'intangible t))))
|
||||
|
||||
;;
|
||||
;; Bug Reference mode support
|
||||
;;
|
||||
|
||||
;; This is Emacs 28 stuff but there is no need to guard it with some (f)boundp
|
||||
;; checks (which would return nil if bug-reference.el is not loaded before
|
||||
;; mu4e) since the function definition doesn't hurt and `add-hook' works fine
|
||||
;; for not yet defined variables (by creating them).
|
||||
(declare-function bug-reference-maybe-setup-from-mail "ext:bug-reference")
|
||||
(defun mu4e-view--try-setup-bug-reference-mode ()
|
||||
"Try to guess bug-reference setup from the current mu4e mail.
|
||||
Looks at the maildir and the mail headers List, List-Id, Maildir,
|
||||
To, From, Cc, and Subject and tries to guess suitable values for
|
||||
`bug-reference-bug-regexp' and `bug-reference-url-format' by
|
||||
matching the maildir name against GROUP-REGEXP and each header
|
||||
value against HEADER-REGEXP in
|
||||
`bug-reference-setup-from-mail-alist'."
|
||||
(when (derived-mode-p 'mu4e-view-mode)
|
||||
(let (header-values)
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(dolist (field '("list" "list-id" "to" "from" "cc" "subject"))
|
||||
(let ((val (mail-fetch-field field)))
|
||||
(when val
|
||||
(push val header-values)))))
|
||||
(bug-reference-maybe-setup-from-mail
|
||||
(mail-fetch-field "maildir")
|
||||
header-values))))
|
||||
|
||||
(add-hook 'bug-reference-auto-setup-functions
|
||||
#'mu4e-view--try-setup-bug-reference-mode)
|
||||
|
||||
;;; _
|
||||
(provide 'mu4e-utils)
|
||||
;;; mu4e-utils.el ends here
|
||||
|
|
Loading…
Reference in New Issue