]> git.eshelyaron.com Git - emacs.git/commitdiff
Allow URL-FORMAT as string and function in bug-reference-setup-from-vc-alist
authorTassilo Horn <tsdh@gnu.org>
Wed, 12 Feb 2025 09:33:08 +0000 (10:33 +0100)
committerEshel Yaron <me@eshelyaron.com>
Wed, 12 Feb 2025 10:53:07 +0000 (11:53 +0100)
That's a slight simplification resulting from bug#72735.

* lisp/progmodes/bug-reference.el (bug-reference-setup-from-vc-alist):
Rename URL-FORMAT-FN to URL-FORMAT and mention it may be string or
function.
* (bug-reference-maybe-setup-from-vc): Handle the new case where
bug-url-fmt is just a string rather than a function.

(cherry picked from commit b5404a205c1a1aa858dc430ffaa32a35c744e244)

lisp/progmodes/bug-reference.el

index b25c5255f4cf626bb307baca7681c12de5cb5b5e..874fa012512098280a4687b5108c05e250090523 100644 (file)
@@ -225,10 +225,14 @@ subexpression 10."
   (when (string-match url-rx url)
     (setq-local bug-reference-bug-regexp bug-rx)
     (setq-local bug-reference-url-format
-                (let (groups)
-                  (dotimes (i (/ (length (match-data)) 2))
-                    (push (match-string i url) groups))
-                  (funcall bug-url-fmt (nreverse groups))))))
+                (if (functionp bug-url-fmt)
+                    ;; Collect the regex matches in a list and call
+                    ;; bug-url-fmt with it.
+                    (let (groups)
+                      (dotimes (i (/ (length (match-data)) 2))
+                        (push (match-string i url) groups))
+                      (funcall bug-url-fmt (nreverse groups)))
+                  bug-url-fmt))))
 
 (defvar bug-reference--setup-from-vc-alist nil
   "An alist for setting up `bug-reference-mode' based on VC URL.
@@ -366,13 +370,14 @@ generated from `bug-reference-forge-alist'."
 (defvar bug-reference-setup-from-vc-alist nil
   "An alist for setting up `bug-reference-mode' based on VC URL.
 
-Each element has the form (URL-REGEXP BUG-REGEXP URL-FORMAT-FN).
+Each element has the form (URL-REGEXP BUG-REGEXP URL-FORMAT).
 
-URL-REGEXP is matched against the version control URL of the
-current buffer's file.  If it matches, BUG-REGEXP is set as
-`bug-reference-bug-regexp'.  URL-FORMAT-FN is a function of one
-argument that receives a list of the groups 0 to N of matching
-URL-REGEXP against the VCS URL and returns the value to be set as
+URL-REGEXP is matched against the version control URL of the current
+buffer's file.  If it matches, BUG-REGEXP is set as
+`bug-reference-bug-regexp'.  URL-FORMAT is either a string, the
+`bug-reference-url-format' to be used, or a function of one argument
+that receives a list of the groups 0 to N of matching URL-REGEXP against
+the VCS URL and returns the value to be set as
 `bug-reference-url-format'.")
 
 (defun bug-reference-try-setup-from-vc ()