[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: rx and rx-to-string handle (regexp VAR) differently
From: |
Kévin Le Gouguec |
Subject: |
Re: rx and rx-to-string handle (regexp VAR) differently |
Date: |
Fri, 09 Jun 2023 08:20:11 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Michael Heerdegen <michael_heerdegen@web.de> writes:
> Platon Pronko <platon7pronko@gmail.com> writes:
>
>> rx-to-string docs explicitly say: "The arguments to ‘literal’ and
>> ‘regexp’ forms inside FORM must be constant strings."
>
> Is this a correct way to get what Kévin wants?
>
> #+begin_src emacs-lisp
> (setq foo-regexp "fo+")
> (rx-define foo (eval `(regexp ,foo-regexp)))
> #+end_src
Ah, nice catch! I had started messing around with rx's 'eval', but
figured I should sort out my understanding of 'regexp' before throwing
more indirection at the problem. It does seem like it fits my original
use-case better:
(eval-and-compile
(put 'foo 'rx-definition
'((eval
`(regexp ,foo-regexp))))
'foo)
AFAICT (from that expansion and some cursory testing) that does allow
for (rx-to-string '(seq foo)) to change whenever foo-regexp changes.
> This also works in both cases:
>
> #+begin_src emacs-lisp
> (setq foo-regexp '(regexp "fo+"))
> (rx-define foo (eval foo-regexp))
> #+end_src
Noted. Thanks a bunch for these hints!