aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTassilo Horn2020-07-17 20:59:04 +0200
committerTassilo Horn2020-07-17 20:59:04 +0200
commitbeaad910c2d1b188ee73084cf2a7efc3160d6b17 (patch)
tree9d67f61976c100fb69a55c60aa10b8571219f8be
parentba12555fda9cdd781b50e60d933aa6b8ba4464b9 (diff)
downloademacs-beaad910c2d1b188ee73084cf2a7efc3160d6b17.tar.gz
emacs-beaad910c2d1b188ee73084cf2a7efc3160d6b17.zip
bug-reference auto-setup for IRC, implementation for rcirc
* lisp/progmodes/bug-reference.el (bug-reference-setup-from-irc-alist): New defvar for configuring bug regexp and URL based on IRC channel and server names. (bug-reference--maybe-setup-from-irc): New defun doing the setup given channel and server. (bug-reference-try-setup-from-rcirc): New defun calling the above for rcirc buffers. (bug-reference--run-auto-setup): Enable the auto-setup for rcirc. * etc/NEWS: Extend entry describing bug-reference auto-setup.
-rw-r--r--etc/NEWS13
-rw-r--r--lisp/progmodes/bug-reference.el59
2 files changed, 64 insertions, 8 deletions
diff --git a/etc/NEWS b/etc/NEWS
index b3ad5623c8c..b8cb22c7f74 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -556,13 +556,14 @@ truncation, amongst other things.
556'bug-reference-prog-mode' have been activated, their respective hook 556'bug-reference-prog-mode' have been activated, their respective hook
557has been run and still 'bug-reference-bug-regexp' and 557has been run and still 'bug-reference-bug-regexp' and
558'bug-reference-url-format' aren't both set, it tries to guess 558'bug-reference-url-format' aren't both set, it tries to guess
559appropriate values for those two variables. There are two guessing 559appropriate values for those two variables. There are three guessing
560mechanisms so far: based on version control information of the current 560mechanisms so far: based on version control information of the current
561buffer's file, and based on newsgroup/mail-folder name and several 561buffer's file, based on newsgroup/mail-folder name and several news
562news and mail message headers in Gnus buffers. Both mechanisms are 562and mail message headers in Gnus buffers, and based on IRC channel and
563extensible with custom rules, see the variables 563server in rcirc buffers. All mechanisms are extensible with custom
564'bug-reference-setup-from-vc-alist' and 564rules, see the variables 'bug-reference-setup-from-vc-alist',
565'bug-reference-setup-from-mail-alist'. 565'bug-reference-setup-from-mail-alist', and
566'bug-reference-setup-from-irc-alist'.
566 567
567 568
568* New Modes and Packages in Emacs 28.1 569* New Modes and Packages in Emacs 28.1
diff --git a/lisp/progmodes/bug-reference.el b/lisp/progmodes/bug-reference.el
index b151e87f1c2..4f56c04d2c7 100644
--- a/lisp/progmodes/bug-reference.el
+++ b/lisp/progmodes/bug-reference.el
@@ -229,7 +229,6 @@ and apply it if applicable."
229 url config) 229 url config)
230 (throw 'found t))))))))) 230 (throw 'found t)))))))))
231 231
232;; TODO: Implement something similar for IRC with rcirc/ERC.
233(defvar bug-reference-setup-from-mail-alist 232(defvar bug-reference-setup-from-mail-alist
234 `((,(regexp-opt '("emacs" "auctex" "gnus" "tramp" "orgmode") 'words) 233 `((,(regexp-opt '("emacs" "auctex" "gnus" "tramp" "orgmode") 'words)
235 ,(regexp-opt '("@debbugs.gnu.org" "-devel@gnu.org" 234 ,(regexp-opt '("@debbugs.gnu.org" "-devel@gnu.org"
@@ -344,6 +343,61 @@ and set it if applicable."
344 (push val header-values)))))) 343 (push val header-values))))))
345 (bug-reference--maybe-setup-from-mail nil header-values))))))) 344 (bug-reference--maybe-setup-from-mail nil header-values)))))))
346 345
346(defvar bug-reference-setup-from-irc-alist
347 `((,(concat "#" (regexp-opt '("emacs" "gnus" "org-mode" "rcirc"
348 "erc") 'words))
349 "freenode"
350 "\\([Bb]ug ?#?\\)\\([0-9]+\\(?:#[0-9]+\\)?\\)"
351 "https://debbugs.gnu.org/%s"))
352 "An alist for setting up `bug-reference-mode' in IRC modes.
353
354This takes action if `bug-reference-mode' is enabled in IRC
355channels using one of Emacs' IRC clients (rcirc and ERC).
356Currently, only rcirc is supported.
357
358Each element has the form
359
360 (CHANNEL-REGEXP SERVER-REGEXP BUG-REGEXP URL-FORMAT)
361
362CHANNEL-REGEXP is a regexp matched against the current mail IRC
363channel name. SERVER-REGEXP is matched against the IRC server
364name. If any of those matches, BUG-REGEXP is set as
365`bug-reference-bug-regexp' and URL-FORMAT is set as
366`bug-reference-url-format'.")
367
368(defun bug-reference--maybe-setup-from-irc (channel server)
369 "Set up according to IRC CHANNEL or SERVER.
370CHANNEL is an IRC channel name and SERVER is that channel's
371server name.
372
373If any CHANNEL-REGEXP or SERVER-REGEXP of
374`bug-reference-setup-from-irc-alist' matches CHANNEL or SERVER,
375the corresponding BUG-REGEXP and URL-FORMAT are set."
376 (catch 'setup-done
377 (dolist (config bug-reference-setup-from-irc-alist)
378 (when (or
379 (and channel
380 (car config)
381 (string-match-p (car config) channel))
382 (and server
383 (nth 1 config)
384 (string-match-p (car config) server)))
385 (setq-local bug-reference-bug-regexp (nth 2 config))
386 (setq-local bug-reference-url-format (nth 3 config))
387 (throw 'setup-done t)))))
388
389(defun bug-reference-try-setup-from-rcirc ()
390 "Try setting up `bug-reference-mode' based on rcirc channel and server.
391Test each configuration in `bug-reference-setup-from-irc-alist'
392and set it if applicable."
393 (when (derived-mode-p 'rcirc-mode)
394 (bug-reference--maybe-setup-from-irc
395 rcirc-target
396 (and rcirc-server-buffer
397 (buffer-live-p rcirc-server-buffer)
398 (with-current-buffer rcirc-server-buffer
399 rcirc-server)))))
400
347(defun bug-reference--run-auto-setup () 401(defun bug-reference--run-auto-setup ()
348 (when (or bug-reference-mode 402 (when (or bug-reference-mode
349 bug-reference-prog-mode) 403 bug-reference-prog-mode)
@@ -355,7 +409,8 @@ and set it if applicable."
355 "Error during bug-reference auto-setup: %S" 409 "Error during bug-reference auto-setup: %S"
356 (catch 'setup 410 (catch 'setup
357 (dolist (f (list #'bug-reference-try-setup-from-vc 411 (dolist (f (list #'bug-reference-try-setup-from-vc
358 #'bug-reference-try-setup-from-gnus)) 412 #'bug-reference-try-setup-from-gnus
413 #'bug-reference-try-setup-from-rcirc))
359 (when (funcall f) 414 (when (funcall f)
360 (throw 'setup t)))))))) 415 (throw 'setup t))))))))
361 416