From 6648305fcefff43864335b526c2f7f288e6f6198 Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Wed, 12 Feb 2025 10:33:08 +0100 Subject: [PATCH] Allow URL-FORMAT as string and function in bug-reference-setup-from-vc-alist 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 | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lisp/progmodes/bug-reference.el b/lisp/progmodes/bug-reference.el index b25c5255f4c..874fa012512 100644 --- a/lisp/progmodes/bug-reference.el +++ b/lisp/progmodes/bug-reference.el @@ -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 () -- 2.39.5