'bug-reference-prog-mode' have been activated, their respective hook
has been run and still 'bug-reference-bug-regexp' and
'bug-reference-url-format' aren't both set, it tries to guess
-appropriate values for those two variables. There are two guessing
+appropriate values for those two variables. There are three guessing
mechanisms so far: based on version control information of the current
-buffer's file, and based on newsgroup/mail-folder name and several
-news and mail message headers in Gnus buffers. Both mechanisms are
-extensible with custom rules, see the variables
-'bug-reference-setup-from-vc-alist' and
-'bug-reference-setup-from-mail-alist'.
+buffer's file, based on newsgroup/mail-folder name and several news
+and mail message headers in Gnus buffers, and based on IRC channel and
+server in rcirc buffers. All mechanisms are extensible with custom
+rules, see the variables 'bug-reference-setup-from-vc-alist',
+'bug-reference-setup-from-mail-alist', and
+'bug-reference-setup-from-irc-alist'.
\f
* New Modes and Packages in Emacs 28.1
url config)
(throw 'found t)))))))))
-;; TODO: Implement something similar for IRC with rcirc/ERC.
(defvar bug-reference-setup-from-mail-alist
`((,(regexp-opt '("emacs" "auctex" "gnus" "tramp" "orgmode") 'words)
,(regexp-opt '("@debbugs.gnu.org" "-devel@gnu.org"
(push val header-values))))))
(bug-reference--maybe-setup-from-mail nil header-values)))))))
+(defvar bug-reference-setup-from-irc-alist
+ `((,(concat "#" (regexp-opt '("emacs" "gnus" "org-mode" "rcirc"
+ "erc") 'words))
+ "freenode"
+ "\\([Bb]ug ?#?\\)\\([0-9]+\\(?:#[0-9]+\\)?\\)"
+ "https://debbugs.gnu.org/%s"))
+ "An alist for setting up `bug-reference-mode' in IRC modes.
+
+This takes action if `bug-reference-mode' is enabled in IRC
+channels using one of Emacs' IRC clients (rcirc and ERC).
+Currently, only rcirc is supported.
+
+Each element has the form
+
+ (CHANNEL-REGEXP SERVER-REGEXP BUG-REGEXP URL-FORMAT)
+
+CHANNEL-REGEXP is a regexp matched against the current mail IRC
+channel name. SERVER-REGEXP is matched against the IRC server
+name. If any of those matches, BUG-REGEXP is set as
+`bug-reference-bug-regexp' and URL-FORMAT is set as
+`bug-reference-url-format'.")
+
+(defun bug-reference--maybe-setup-from-irc (channel server)
+ "Set up according to IRC CHANNEL or SERVER.
+CHANNEL is an IRC channel name and SERVER is that channel's
+server name.
+
+If any CHANNEL-REGEXP or SERVER-REGEXP of
+`bug-reference-setup-from-irc-alist' matches CHANNEL or SERVER,
+the corresponding BUG-REGEXP and URL-FORMAT are set."
+ (catch 'setup-done
+ (dolist (config bug-reference-setup-from-irc-alist)
+ (when (or
+ (and channel
+ (car config)
+ (string-match-p (car config) channel))
+ (and server
+ (nth 1 config)
+ (string-match-p (car config) server)))
+ (setq-local bug-reference-bug-regexp (nth 2 config))
+ (setq-local bug-reference-url-format (nth 3 config))
+ (throw 'setup-done t)))))
+
+(defun bug-reference-try-setup-from-rcirc ()
+ "Try setting up `bug-reference-mode' based on rcirc channel and server.
+Test each configuration in `bug-reference-setup-from-irc-alist'
+and set it if applicable."
+ (when (derived-mode-p 'rcirc-mode)
+ (bug-reference--maybe-setup-from-irc
+ rcirc-target
+ (and rcirc-server-buffer
+ (buffer-live-p rcirc-server-buffer)
+ (with-current-buffer rcirc-server-buffer
+ rcirc-server)))))
+
(defun bug-reference--run-auto-setup ()
(when (or bug-reference-mode
bug-reference-prog-mode)
"Error during bug-reference auto-setup: %S"
(catch 'setup
(dolist (f (list #'bug-reference-try-setup-from-vc
- #'bug-reference-try-setup-from-gnus))
+ #'bug-reference-try-setup-from-gnus
+ #'bug-reference-try-setup-from-rcirc))
(when (funcall f)
(throw 'setup t))))))))