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

From: Roland Winkler <[email-masked]>
Date: Tue, 08 Jul 2025 11:46:34 -0500

On Wed, Jul 02 2025, Eli Zaretskii wrote:
>> +  :set (lambda (symbol value)
>> +         (set-default symbol value)
>> +         (let ((fields (delete-dups (mapcar #'caar bibtex-generate-url-list))))
>> +           (set-default-toplevel-value
>> +            'bibtex-font-lock-url-regexp
>> +            ;; Assume that field names begin at the beginning of a line.
>> +            (concat "^[ \t]*"
>> +                    (regexp-opt fields 'paren)
>> +                    "[ \t\n]*=[ \t\n]*")))))

Small thing: What is the purpose of the intermediate let-binding?

The elisp manual says about setfunctions:

     If you specify this keyword, the variable’s documentation string
     should describe how to do the same job in hand-written Lisp code,
     either by invoking SETFUNCTION directly or by using ‘setopt’.

Isn't it then cleaner to define a helper function instead of using
a lambda expression?

>> -(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]*")
>> +(defvar bibtex-font-lock-url-regexp nil
>>    "Regexp for `bibtex-font-lock-url' derived from `bibtex-generate-url-list'.")

I was surprised when I tested the above that it sets
bibtex-font-lock-url-regexp even if the value of
bibtex-generate-url-list is defined outside defcustom, that is,
defcustom evaluates the above setfunction even when it ignores the
standard value for bibtex-generate-url-list.  This is sensible,
but I did not find it documented anywhere.