Skip to content

Commit

Permalink
Add bug-reference-mode-force-auto-setup
Browse files Browse the repository at this point in the history
* lisp/progmodes/bug-reference.el
(bug-reference-try-setup-from-rmail): Match the Rmail mbox filename
against GROUP-REGEXP in bug-reference-setup-from-mail-alist.
(bug-reference-mode-force-auto-setup): New function which forces
auto-setup even if bug-reference-bug-regexp and
bug-reference-url-format are already set.
  • Loading branch information
tsdh committed May 16, 2021
1 parent 069c2fb commit b6d02dc
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions lisp/progmodes/bug-reference.el
Expand Up @@ -344,9 +344,11 @@ and set it if applicable."

(defun bug-reference-try-setup-from-rmail ()
"Try setting up `bug-reference-mode' from the current rmail mail.
Looks at the headers List-Id, To, From, and Cc and tries to guess
suitable values for `bug-reference-bug-regexp' and
`bug-reference-url-format'."
Guesses suitable `bug-reference-bug-regexp' and
`bug-reference-url-format' values by matching the current Rmail
file's name against GROUP-REGEXP and the values of List-Id, To,
From, and Cc against HEADER-REGEXP in
`bug-reference-setup-from-mail-alist'."
(with-demoted-errors
"Error in bug-reference-try-setup-from-rmail: %S"
(when (and bug-reference-mode
Expand All @@ -358,7 +360,8 @@ suitable values for `bug-reference-bug-regexp' and
(let ((val (mail-fetch-field field)))
(when val
(push val header-values)))))
(bug-reference--maybe-setup-from-mail nil header-values)))))
(bug-reference--maybe-setup-from-mail
(buffer-file-name) header-values)))))

(defvar bug-reference-setup-from-irc-alist
`((,(concat "#" (regexp-opt '("emacs" "gnus" "org-mode" "rcirc"
Expand Down Expand Up @@ -482,6 +485,18 @@ guesswork is based on these variables:
(widen)
(bug-reference-unfontify (point-min) (point-max)))))

(defun bug-reference-mode-force-auto-setup ()
"Enable `bug-reference-mode' and force auto-setup.
Enabling `bug-reference-mode' runs its auto-setup only if
`bug-reference-bug-regexp' and `bug-reference-url-format' are not
set already. This function sets the latter to `nil'
buffer-locally, so that the auto-setup will always run.
This is mostly intended for MUA modes like `rmail-mode' where the
same buffer is re-used for different contexts."
(setq-local bug-reference-url-format nil)
(bug-reference-mode))

;;;###autoload
(define-minor-mode bug-reference-prog-mode
"Like `bug-reference-mode', but only buttonize in comments and strings."
Expand Down

0 comments on commit b6d02dc

Please sign in to comment.