Make the rx eval form use lexical binding when active

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.
This commit is contained in:
Mattias Engdegård 2025-02-07 18:52:26 +01:00
parent ba6779ab2a
commit 89f88f06a4
3 changed files with 13 additions and 2 deletions

View file

@ -1280,6 +1280,10 @@ name. Previously, Eshell only did this for MS-Windows systems. To
restore the old behavior, you can set 'eshell-pwd-convert-function' to
'identity'.
---
** The rx 'eval' form now uses the current elisp dialect for evaluation.
Previously, its argument was always evaluated using dynamic binding.
* Lisp Changes in Emacs 31.1

View 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)."

View file

@ -485,11 +485,18 @@
(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"))