GNU bug report logs -
#78798
bibtex-font-lock-url-regexp should re-eval after setting bibtex-generate-url-list
Previous Next
To reply to this bug, email your comments to 78798 AT debbugs.gnu.org.
There is no need to reopen the bug first.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78798
; Package
emacs
.
(Sun, 15 Jun 2025 12:09:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
MAN ONE <pRoMMMModE <at> outlook.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Sun, 15 Jun 2025 12:09:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Currently `bibtex-font-lock-url-regexp` only eval once when loading bibtex.el, this means setting `bibtex-generate-url-list` to a new value after loading bibtex.el has no effect.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78798
; Package
emacs
.
(Wed, 02 Jul 2025 02:50:03 GMT)
Full text and
rfc822 format available.
Message #8 received at 78798 <at> debbugs.gnu.org (full text, mbox):
Hi, I made a small patch to resolve the bug, in my own testing it works so I would like to submit it.
-------------------------------------------------------------------------
diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el
index 2bef0573bed..5ed5e625b7e 100644
--- a/lisp/textmodes/bibtex.el
+++ b/lisp/textmodes/bibtex.el
@@ -1495,7 +1495,16 @@ bibtex-generate-url-list
(choice (string :tag "Replacement")
(integer :tag "Sub-match")
(function :tag "Filter")))))))
- :risky t)
+ :risky t
+ :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]*")))))
(defcustom bibtex-cite-matcher-alist
'(("\\\\cite[ \t\n]*{\\([^}]+\\)}" . 1))
@@ -1838,11 +1847,7 @@ 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]*")
+(defvar bibtex-font-lock-url-regexp nil
"Regexp for `bibtex-font-lock-url' derived from `bibtex-generate-url-list'.")
(defvar bibtex-string-empty-key nil
------------------------------------------------------------------------------
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78798
; Package
emacs
.
(Wed, 02 Jul 2025 11:46:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 78798 <at> debbugs.gnu.org (full text, mbox):
> From: MAN ONE <pRoMMMModE <at> outlook.com>
> Date: Wed, 2 Jul 2025 02:48:57 +0000
> msip_labels:
>
> Hi, I made a small patch to resolve the bug, in my own testing it works so I would like to submit it.
>
> -------------------------------------------------------------------------
> diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el
> index 2bef0573bed..5ed5e625b7e 100644
> --- a/lisp/textmodes/bibtex.el
> +++ b/lisp/textmodes/bibtex.el
> @@ -1495,7 +1495,16 @@ bibtex-generate-url-list
> (choice (string :tag "Replacement")
> (integer :tag "Sub-match")
> (function :tag "Filter")))))))
> - :risky t)
> + :risky t
> + :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]*")))))
>
> (defcustom bibtex-cite-matcher-alist
> '(("\\\\cite[ \t\n]*{\\([^}]+\\)}" . 1))
> @@ -1838,11 +1847,7 @@ 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]*")
> +(defvar bibtex-font-lock-url-regexp nil
> "Regexp for `bibtex-font-lock-url' derived from `bibtex-generate-url-list'.")
>
> (defvar bibtex-string-empty-key nil
> ------------------------------------------------------------------------------
Roland and Stefan, any comments?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78798
; Package
emacs
.
(Tue, 08 Jul 2025 19:58:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 78798 <at> debbugs.gnu.org (full text, mbox):
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.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78798
; Package
emacs
.
(Wed, 09 Jul 2025 03:44:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 78798 <at> debbugs.gnu.org (full text, mbox):
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.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78798
; Package
emacs
.
(Sat, 19 Jul 2025 07:48:02 GMT)
Full text and
rfc822 format available.
Message #20 received at 78798 <at> debbugs.gnu.org (full text, mbox):
> From: MAN ONE <pRoMMMModE <at> outlook.com>
> CC: "78798 <at> debbugs.gnu.org" <78798 <at> debbugs.gnu.org>, Eli Zaretskii
> <eliz <at> gnu.org>, "monnier <at> iro.umontreal.ca" <monnier <at> iro.umontreal.ca>
> Date: Wed, 9 Jul 2025 03:43:40 +0000
>
> Perhaps this one is better?
Roland?
> =============================
> --- 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.
>
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78798
; Package
emacs
.
(Sun, 20 Jul 2025 06:05:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 78798 <at> debbugs.gnu.org (full text, mbox):
On Sat, Jul 19 2025, Eli Zaretskii wrote:
>> From: MAN ONE <pRoMMMModE <at> outlook.com>
>> CC: "78798 <at> debbugs.gnu.org" <78798 <at> debbugs.gnu.org>, Eli Zaretskii
>> <eliz <at> gnu.org>, "monnier <at> iro.umontreal.ca" <monnier <at> iro.umontreal.ca>
>> Date: Wed, 9 Jul 2025 03:43:40 +0000
>>
>> Perhaps this one is better?
>
> Roland?
I installed a patch, but I was surprised that it turned out rather
complicated. Maybe I am missing something.
If the value of a user variable foo is used to initialize a helper
variable bar, then defcustom for foo can define a setfunction that will
set bar. But this function must be defined before the defcustom. But
this makes the compiler complain that the setfunction uses the undefined
var foo. And if bar is declared after foo, this gives more warnings.
Also, for bibtex-generate-url-list it makes sense to have a buffer-local
value, so that the setfunction (when called "by hand") should either set
the default or the buffer-local value of bibtex-font-lock-url-regexp.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78798
; Package
emacs
.
(Sun, 20 Jul 2025 06:09:02 GMT)
Full text and
rfc822 format available.
Message #26 received at 78798 <at> debbugs.gnu.org (full text, mbox):
> From: Roland Winkler <winkler <at> gnu.org>
> Cc: MAN ONE <pRoMMMModE <at> outlook.com>, 78798 <at> debbugs.gnu.org,
> monnier <at> iro.umontreal.ca
> Date: Sun, 20 Jul 2025 01:03:49 -0500
>
> If the value of a user variable foo is used to initialize a helper
> variable bar, then defcustom for foo can define a setfunction that will
> set bar. But this function must be defined before the defcustom. But
> this makes the compiler complain that the setfunction uses the undefined
> var foo. And if bar is declared after foo, this gives more warnings.
The usual way of working around that is to have
(defvar foo)
before defining the set-function.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78798
; Package
emacs
.
(Sun, 20 Jul 2025 06:18:02 GMT)
Full text and
rfc822 format available.
Message #29 received at 78798 <at> debbugs.gnu.org (full text, mbox):
> Cc: 78798 <at> debbugs.gnu.org, monnier <at> iro.umontreal.ca, pRoMMMModE <at> outlook.com
> Date: Sun, 20 Jul 2025 09:08:28 +0300
> From: Eli Zaretskii <eliz <at> gnu.org>
>
> > From: Roland Winkler <winkler <at> gnu.org>
> > Cc: MAN ONE <pRoMMMModE <at> outlook.com>, 78798 <at> debbugs.gnu.org,
> > monnier <at> iro.umontreal.ca
> > Date: Sun, 20 Jul 2025 01:03:49 -0500
> >
> > If the value of a user variable foo is used to initialize a helper
> > variable bar, then defcustom for foo can define a setfunction that will
> > set bar. But this function must be defined before the defcustom. But
> > this makes the compiler complain that the setfunction uses the undefined
> > var foo. And if bar is declared after foo, this gives more warnings.
>
> The usual way of working around that is to have
>
> (defvar foo)
>
> before defining the set-function.
There's also another way: the set-function gets as its 1st argument
the symbol of the variable, so it doesn't need to refer to the
variable by its explicit name, it could do that via the symbol
instead.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78798
; Package
emacs
.
(Sun, 20 Jul 2025 07:38:01 GMT)
Full text and
rfc822 format available.
Message #32 received at 78798 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/html, inline)]
Reply sent
to
Eli Zaretskii <eliz <at> gnu.org>
:
You have taken responsibility.
(Tue, 22 Jul 2025 11:21:01 GMT)
Full text and
rfc822 format available.
Notification sent
to
MAN ONE <pRoMMMModE <at> outlook.com>
:
bug acknowledged by developer.
(Tue, 22 Jul 2025 11:21:01 GMT)
Full text and
rfc822 format available.
Message #37 received at 78798-done <at> debbugs.gnu.org (full text, mbox):
> Date: Sun, 20 Jul 2025 07:37:20 UTC
> From: pRoMMMModE <prommmmode <at> outlook.com>
> Cc: 78798 <at> debbugs.gnu.org, monnier <at> iro.umontreal.ca
>
> Hi Roland, I just tried your commit on master branch, and it resolved the problem. Anyway, I think this issue
> can be closed now.
Thanks, closing.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78798
; Package
emacs
.
(Sat, 26 Jul 2025 19:53:01 GMT)
Full text and
rfc822 format available.
Message #40 received at 78798 <at> debbugs.gnu.org (full text, mbox):
On Sun, Jul 20 2025, Eli Zaretskii wrote:
>> If the value of a user variable foo is used to initialize a helper
>> variable bar, then defcustom for foo can define a setfunction that will
>> set bar. But this function must be defined before the defcustom. But
>> this makes the compiler complain that the setfunction uses the undefined
>> var foo. And if bar is declared after foo, this gives more warnings.
>
> The usual way of working around that is to have
>
> (defvar foo)
>
> before defining the set-function.
Of cource, thanks! I do not know why I did not remember this in the
context of actually defining / settting foo. I changed the patch
accordingly.
> There's also another way: the set-function gets as its 1st argument
> the symbol of the variable, so it doesn't need to refer to the
> variable by its explicit name, it could do that via the symbol
> instead.
I want to keep set-function as simple as possible if this is something
users may want to call in their init file. So I think your first
suggestions is better suited.
This bug report was last modified 21 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.