* rx of (any SET...)
@ 2022-08-17 15:43 Michael Albinus
2022-08-17 17:13 ` [External] : " Drew Adams
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Michael Albinus @ 2022-08-17 15:43 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
I have the regexp
--8<---------------cut here---------------start------------->8---
(concat "[^" (bound-and-true-p mm-7bit-chars) "]")
--8<---------------cut here---------------end--------------->8---
I want to write it in rx notation, but I fail. I know how to use xr for
reverse engineering, but I'd like to keep the variable mm-7bit-chars in
the rx notation, and not to replace it by the literal string.
How would this look like?
Best regards, Michael.
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [External] : rx of (any SET...)
2022-08-17 15:43 rx of (any SET...) Michael Albinus
@ 2022-08-17 17:13 ` Drew Adams
2022-08-17 18:19 ` Michael Albinus
2022-08-17 20:34 ` Michael Heerdegen
2022-08-17 20:42 ` Harald Jörg
2 siblings, 1 reply; 8+ messages in thread
From: Drew Adams @ 2022-08-17 17:13 UTC (permalink / raw)
To: Michael Albinus, help-gnu-emacs@gnu.org
> I have the regexp
> (concat "[^" (bound-and-true-p mm-7bit-chars) "]")
Dunno about rx. But what happens when `mm-7bit-chars'
isn't bound and true? Your string is then "[^]", not
a valid regexp. (Maybe you take care of that elsewhere?)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [External] : rx of (any SET...)
2022-08-17 17:13 ` [External] : " Drew Adams
@ 2022-08-17 18:19 ` Michael Albinus
0 siblings, 0 replies; 8+ messages in thread
From: Michael Albinus @ 2022-08-17 18:19 UTC (permalink / raw)
To: Drew Adams; +Cc: help-gnu-emacs@gnu.org
Drew Adams <drew.adams@oracle.com> writes:
Hi Drew,
> Dunno about rx. But what happens when `mm-7bit-chars'
> isn't bound and true? Your string is then "[^]", not
> a valid regexp. (Maybe you take care of that elsewhere?)
In practice, it always works. This is because this check is used in
tramp-bug, while composing the message. And while composing the message,
package mm-bodies is already loaded. Using bound-and-true-p is just for
pacifying the byte compiler.
This code snippet is 20 years old. Time to replace bound-and-true-p by
(defvar mm-7bit-chars)
But the question remains: how to express (concat "[^" mm-7bit-chars "]")
in rx notation?
Best regards, Michael.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: rx of (any SET...)
2022-08-17 15:43 rx of (any SET...) Michael Albinus
2022-08-17 17:13 ` [External] : " Drew Adams
@ 2022-08-17 20:34 ` Michael Heerdegen
2022-08-17 21:37 ` Michael Heerdegen
2022-08-17 20:42 ` Harald Jörg
2 siblings, 1 reply; 8+ messages in thread
From: Michael Heerdegen @ 2022-08-17 20:34 UTC (permalink / raw)
To: help-gnu-emacs
Michael Albinus <michael.albinus@gmx.de> writes:
> (concat "[^" (bound-and-true-p mm-7bit-chars) "]")
>
> I want to write it in rx notation, but I fail. I know how to use xr for
> reverse engineering, but I'd like to keep the variable mm-7bit-chars in
> the rx notation, and not to replace it by the literal string.
C-h f rx RET:
| (regexp EXPR) Match the string regexp from evaluating EXPR at run time.
That's exactly what you are looking for...correct?
(the other) Michael
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: rx of (any SET...)
2022-08-17 20:34 ` Michael Heerdegen
@ 2022-08-17 21:37 ` Michael Heerdegen
2022-08-18 0:59 ` Michael Heerdegen
0 siblings, 1 reply; 8+ messages in thread
From: Michael Heerdegen @ 2022-08-17 21:37 UTC (permalink / raw)
To: help-gnu-emacs
Michael Heerdegen <michael_heerdegen@web.de> writes:
> | (regexp EXPR) Match the string regexp from evaluating EXPR at run time.
>
> That's exactly what you are looking for...correct?
But ok, you have a string that contains a list of chars, so I too have
no better idea than
(rx (regexp (concat "[^" (bound-and-true-p mm-7bit-chars) "]")))
or to use the function instead:
(rx-to-string `(not (any ,@mm-7bit-chars)))
What makes sense depends on the context.
Michael.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: rx of (any SET...)
2022-08-17 21:37 ` Michael Heerdegen
@ 2022-08-18 0:59 ` Michael Heerdegen
0 siblings, 0 replies; 8+ messages in thread
From: Michael Heerdegen @ 2022-08-18 0:59 UTC (permalink / raw)
To: help-gnu-emacs
Michael Heerdegen <michael_heerdegen@web.de> writes:
> (rx (regexp (concat "[^" (bound-and-true-p mm-7bit-chars) "]")))
Even using `rx-define' is not so helpful (its expanding mechanism is
different from e.g. defmacro):
#+begin_src emacs-lisp
(rx-define any-char (&rest string) (regex (concat "[" string "]")))
(rx-define not-any-char (&rest string) (regex (concat "[^" string "]")))
#+end_src
Will not work inside `not'. Thus two definitions.
Ok, in the end I could not really help at all...
Michael.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: rx of (any SET...)
2022-08-17 15:43 rx of (any SET...) Michael Albinus
2022-08-17 17:13 ` [External] : " Drew Adams
2022-08-17 20:34 ` Michael Heerdegen
@ 2022-08-17 20:42 ` Harald Jörg
2022-08-18 9:44 ` Michael Albinus
2 siblings, 1 reply; 8+ messages in thread
From: Harald Jörg @ 2022-08-17 20:42 UTC (permalink / raw)
To: Michael Albinus; +Cc: help-gnu-emacs
Michael Albinus writes:
> Hi,
>
> I have the regexp
>
> (concat "[^" (bound-and-true-p mm-7bit-chars) "]")
>
> I want to write it in rx notation, but I fail. I know how to use xr for
> reverse engineering, but I'd like to keep the variable mm-7bit-chars in
> the rx notation, and not to replace it by the literal string.
>
> How would this look like?
I found that variables can be included in rx forms with some form of
eval, or by using rx-to-string, which is a function and not a macro.
With the value of mm-7bit-chars at macro expansion time:
(rx (eval `(not (any ,mm-7bit-chars))))
With the value of mm-7bit-chars at runtime:
(eval `(rx (not (any ,mm-7bit-chars))))
(rx-to-string `(not (any ,mm-7bit-chars)))
--
Cheers,
haj
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: rx of (any SET...)
2022-08-17 20:42 ` Harald Jörg
@ 2022-08-18 9:44 ` Michael Albinus
0 siblings, 0 replies; 8+ messages in thread
From: Michael Albinus @ 2022-08-18 9:44 UTC (permalink / raw)
To: Harald Jörg; +Cc: help-gnu-emacs
Harald Jörg <haj@posteo.de> writes:
Hi Harald,
> I found that variables can be included in rx forms with some form of
> eval, or by using rx-to-string, which is a function and not a macro.
>
> With the value of mm-7bit-chars at macro expansion time:
> (rx (eval `(not (any ,mm-7bit-chars))))
>
> With the value of mm-7bit-chars at runtime:
> (eval `(rx (not (any ,mm-7bit-chars))))
> (rx-to-string `(not (any ,mm-7bit-chars)))
Thanks, that does the trick!
> Cheers,
> haj
Best regards, Michael.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-08-18 9:44 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-17 15:43 rx of (any SET...) Michael Albinus
2022-08-17 17:13 ` [External] : " Drew Adams
2022-08-17 18:19 ` Michael Albinus
2022-08-17 20:34 ` Michael Heerdegen
2022-08-17 21:37 ` Michael Heerdegen
2022-08-18 0:59 ` Michael Heerdegen
2022-08-17 20:42 ` Harald Jörg
2022-08-18 9:44 ` Michael Albinus
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).