Subject: bug#78798: bibtex-font-lock-url-regexp should re-eval after setting bibtex-generate-url-list

From: MAN ONE <[email-masked]>
Date: Wed, 9 Jul 2025 03:43:40 +0000

Perhaps this one is better?

=============================
--- a/lisp/textmodes/bibtex.el
+++ b/lisp/textmodes/bibtex.el
@@ -39,7 +39,14 @@
 ;;; Code:
 
 (require 'iso8601)
-
+(eval-and-compile
+  (defun bibtex--generate-url-list (symbol value)
+    "Set the default value of `bibtex-generate-url-list' and populate `bibtex-font-lock-url-regexp'."
+    (set-default symbol value)
+    (setq bibtex-font-lock-url-regexp
+          (concat "^[ \t]*"           ; Assume that field names begin at the beginning of a line.
+                  (regexp-opt (delete-dups (mapcar #'caar value)) 'paren)
+                  "[ \t\n]*=[ \t\n]*"))))
 
 ;; User Options:
 
@@ -1495,7 +1502,8 @@ bibtex-generate-url-list
                                (choice (string :tag "Replacement")
 				       (integer :tag "Sub-match")
                                        (function :tag "Filter")))))))
-  :risky t)
+  :risky t
+  :set 'bibtex--generate-url-list)
 
 (defcustom bibtex-cite-matcher-alist
   '(("\\\\cite[ \t\n]*{\\([^}]+\\)}" . 1))
@@ -1838,12 +1846,10 @@ bibtex-font-lock-keywords
               bibtex-cite-matcher-alist))
   "Default expressions to highlight in BibTeX mode.")
 
-(defvar bibtex-font-lock-url-regexp
-  ;; Assume that field names begin at the beginning of a line.
-  (concat "^[ \t]*"
-          (regexp-opt (delete-dups (mapcar #'caar bibtex-generate-url-list)) t)
-          "[ \t\n]*=[ \t\n]*")
-  "Regexp for `bibtex-font-lock-url' derived from `bibtex-generate-url-list'.")
+(defvar bibtex-font-lock-url-regexp nil
+  "Regexp for `bibtex-font-lock-url'.
+Auto-generated from `bibtex-generate-url-list'.
+To change its value, customize `bibtex-generate-url-list'.")
 
 (defvar bibtex-string-empty-key nil
   "If non-nil, `bibtex-parse-string' accepts empty key.")
=====================================

In bibtex.el there are muliple variable like `bibtex-font-lock-url-regexp`, defined 
as nil then populated by other customizables, honestly I don't know if it's 
good or not but it certainly takes a non-trivial patch to remove those variables.