* Changing regexp to single \ for message printing
@ 2024-07-13 9:30 Heime
2024-07-13 14:44 ` Heime
2024-07-17 2:53 ` Stefan Monnier via Users list for the GNU Emacs text editor
0 siblings, 2 replies; 4+ messages in thread
From: Heime @ 2024-07-13 9:30 UTC (permalink / raw)
To: Heime via Users list for the GNU Emacs text editor
I would like to have a function that takes a regexp such as
"\\(\\s-*\\[\\-\\] \\)\\(.*\\)"
that removes the extra \ in \\ but also add the necessary \ characters
to get another string that when used in message will print the regexp
string with the single \.
I have tried to do the conversion myself but cannot get things quite right
with "\\(\\s-*\\\[\\\-\\\] \\\)\\\(.*\\\)\" because it is giving me
"\(\s-*M-x \-\ \)\(.*\)"
Whereas I need to get
(message regexp-display-string)
\(\s-*\[\-\] \)\(.*\)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Changing regexp to single \ for message printing
2024-07-13 9:30 Changing regexp to single \ for message printing Heime
@ 2024-07-13 14:44 ` Heime
2024-07-17 2:38 ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-07-17 2:53 ` Stefan Monnier via Users list for the GNU Emacs text editor
1 sibling, 1 reply; 4+ messages in thread
From: Heime @ 2024-07-13 14:44 UTC (permalink / raw)
To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor
On Saturday, July 13th, 2024 at 9:30 PM, Heime <heimeborgia@protonmail.com> wrote:
> I would like to have a function that takes a regexp such as
>
> "\\(\\s-\\[\\-\\] \\)\\(.\\)"
>
> that removes the extra \ in \\ but also add the necessary \ characters
> to get another string that when used in message will print the regexp
> string with the single \.
>
> I have tried to do the conversion myself but cannot get things quite right
> with "\\(\\s-\\\[\\\-\\\] \\\)\\\(.\\\)\" because it is giving me
>
> "\(\s-M-x \-\ \)\(.\)"
>
> Whereas I need to get
>
> (message regexp-display-string)
>
> \(\s-\[\-\] \)\(.\)
For instance, consider
( message "1. First Capturing Group \\(\\s-*\\[\\-\\]\\s-*\\)" )
It does not produce
1. First Capturing Group \(\s-*\[\-\]\s-*\)
An M-x is being introduced, and the opening [ and closing ] square brackets are
nowhere to be seen. What is going on ?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Changing regexp to single \ for message printing
2024-07-13 9:30 Changing regexp to single \ for message printing Heime
2024-07-13 14:44 ` Heime
@ 2024-07-17 2:53 ` Stefan Monnier via Users list for the GNU Emacs text editor
1 sibling, 0 replies; 4+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2024-07-17 2:53 UTC (permalink / raw)
To: help-gnu-emacs
> I would like to have a function that takes a regexp such as
>
> "\\(\\s-*\\[\\-\\] \\)\\(.*\\)"
Nitpick, the above is the source representation of a string intended to
be used as a regexp. The actual string (regexp) that this represents is:
\(\s-*\[\-\] \)\(.*\)
> (message regexp-display-string)
The first argument to `message` should virtually *always* be an
immediate string rather than a reference to a variable or some
computed value.
IOW, always do
(message "<blabla>" regexp-display-string)
unless you *really* know what you're doing and why you're doing it.
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-07-17 2:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-13 9:30 Changing regexp to single \ for message printing Heime
2024-07-13 14:44 ` Heime
2024-07-17 2:38 ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-07-17 2:53 ` Stefan Monnier via Users list for the GNU Emacs text editor
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.