]> git.eshelyaron.com Git - emacs.git/commitdiff
Make the rx `eval` form use lexical binding when active
authorMattias EngdegÄrd <mattiase@acm.org>
Fri, 7 Feb 2025 17:52:26 +0000 (18:52 +0100)
committerEshel Yaron <me@eshelyaron.com>
Tue, 18 Feb 2025 08:52:57 +0000 (09:52 +0100)
Previously, it always used dynamic binding.

* lisp/emacs-lisp/rx.el (rx--expand-eval): Heed `lexical-binding`.
* test/lisp/emacs-lisp/rx-tests.el (rx-tests--x, rx-tests--get-x)
(rx-eval): Add test case.
* etc/NEWS: Announce.

(cherry picked from commit 89f88f06a4667a01612704e57f8af43ca19b82c0)

lisp/emacs-lisp/rx.el
test/lisp/emacs-lisp/rx-tests.el

index 8fbe35220f1a87b8db052704411b1c2bf69990d0..c512d42cd1570c228d59e771a5919d2c6312453c 100644 (file)
@@ -1072,7 +1072,7 @@ Return (REGEXP . PRECEDENCE)."
   "Expand `eval' arguments.  Return a new rx form."
   (unless (and body (null (cdr body)))
     (error "rx `eval' form takes exactly one argument"))
-  (eval (car body)))
+  (eval (car body) lexical-binding))
 
 (defun rx--translate-eval (body)
   "Translate the `eval' form.  Return (REGEXP . PRECEDENCE)."
index bd11be7bc7255d7a887b519209f477bada07f860..a485b0f29e197265cb97df3bd779f5b28f9032a5 100644 (file)
     (should (equal (rx "" (regexp x) (eval ""))
                    "a*"))))
 
+(eval-when-compile
+  (defvar rx-tests--x "LEX")
+  (defun rx-tests--get-x () rx-tests--x))
+
 (ert-deftest rx-eval ()
   (should (equal (rx (eval (list 'syntax 'symbol)))
                  "\\s_"))
   (should (equal (rx "a" (eval (concat)) "b")
-                 "ab")))
+                 "ab"))
+  (should (equal (rx (eval (funcall (lambda (rx-tests--x) (rx-tests--get-x))
+                                    "DYN")))
+                 "LEX")))
 
 (ert-deftest rx-literal ()
   (should (equal (rx (literal "$a"))