emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master beaad91: bug-reference auto-setup for IRC, implementation for rci


From: Tassilo Horn
Subject: master beaad91: bug-reference auto-setup for IRC, implementation for rcirc
Date: Fri, 17 Jul 2020 15:03:46 -0400 (EDT)

branch: master
commit beaad910c2d1b188ee73084cf2a7efc3160d6b17
Author: Tassilo Horn <tsdh@gnu.org>
Commit: Tassilo Horn <tsdh@gnu.org>

    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.
---
 etc/NEWS                        | 13 ++++-----
 lisp/progmodes/bug-reference.el | 59 +++++++++++++++++++++++++++++++++++++++--
 2 files changed, 64 insertions(+), 8 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index b3ad562..b8cb22c 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -556,13 +556,14 @@ truncation, amongst other things.
 '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'.
 
 
 * New Modes and Packages in Emacs 28.1
diff --git a/lisp/progmodes/bug-reference.el b/lisp/progmodes/bug-reference.el
index b151e87..4f56c04 100644
--- a/lisp/progmodes/bug-reference.el
+++ b/lisp/progmodes/bug-reference.el
@@ -229,7 +229,6 @@ and apply it if applicable."
                            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"
@@ -344,6 +343,61 @@ and set it if applicable."
                       (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)
@@ -355,7 +409,8 @@ and set it if applicable."
           "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))))))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]