Subject: bug#40409: 27.0.90; void variable n-reb

From: Noam Postavsky <[email-masked]>
Date: Sat, 04 Apr 2020 12:52:25 -0400

tags 40409 + patch
quit

Serghei Iakovlev <[email-masked]> writes:

> Hello,
>
> This is reproducible using 'emacs -Q':
>
> - Open Emacs
> - M-x re-builder RED
> - Take a look at *Messages* buffer:
>
>   Error running timer ‘jit-lock--debug-fontify’: (void-variable n-reb)

The code causing this was added by [1: c1234ca9c3] (from Bug#6347), so
it's a regression since 26.3.

The problem seems to be that the initial binding of n-reb is missing,
and also that the code assumes dynamic binding (using symbol-value and
set on n-reb).  I would suggest the following patch:

>From 421c7741b9d32c8898da9ecfea7b5198c97a2b43 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <[email-masked]>
Date: Sat, 4 Apr 2020 12:00:41 -0400
Subject: [PATCH] Fix void-variable n-reb in re-builder (Bug#40409)

* lisp/emacs-lisp/re-builder.el (reb-while): Take the current value of
the counter instead of its name.
(reb-mark-non-matching-parenthesis): dynamic-binding Bind n-reb to 0
at the start.
---
 lisp/emacs-lisp/re-builder.el | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/lisp/emacs-lisp/re-builder.el b/lisp/emacs-lisp/re-builder.el
index 580e91483d..0e1618e010 100644
--- a/lisp/emacs-lisp/re-builder.el
+++ b/lisp/emacs-lisp/re-builder.el
@@ -767,22 +767,21 @@ reb-string-font-lock-keywords
      (reb-mark-non-matching-parenthesis))
     nil)))
 
-(defsubst reb-while (limit counter where)
-  (let ((count (symbol-value counter)))
-    (if (= count limit)
-        (progn
-          (message "Reached (while limit=%s, where=%s)" limit where)
-          nil)
-      (set counter (1+ count)))))
+(defsubst reb-while (limit current where)
+  (if (< current limit)
+      (1+ current)
+    (message "Reached (while limit=%s, where=%s)" limit where)
+    nil))
 
 (defun reb-mark-non-matching-parenthesis (bound)
   ;; We have a small string, check the whole of it, but wait until
   ;; everything else is fontified.
   (when (>= bound (point-max))
-    (let (left-pars
+    (let ((n-reb 0)
+          left-pars
           faces-here)
       (goto-char (point-min))
-      (while (and (reb-while 100 'n-reb "mark-par")
+      (while (and (setq n-reb (reb-while 100 n-reb "mark-par"))
                   (not (eobp)))
         (skip-chars-forward "^()")
         (unless (eobp)
-- 
2.11.0

If that is too big for emacs-27, the absolute mimimum fix would be:

modified   lisp/emacs-lisp/re-builder.el
@@ -779,7 +779,9 @@ reb-mark-non-matching-parenthesis
   ;; We have a small string, check the whole of it, but wait until
   ;; everything else is fontified.
   (when (>= bound (point-max))
-    (let (left-pars
+    (defvar n-reb)
+    (let ((n-reb 0)
+          left-pars
           faces-here)
       (goto-char (point-min))
       (while (and (reb-while 100 'n-reb "mark-par")

[1: c1234ca9c3]: 2019-06-27 19:08:42 +0200
  Add more fontification to regexp builder mode
  https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=c1234ca9c3703cd8bae3912f3e0a1948bae3aed1