* double backslash problem in elisp
@ 2009-08-21 9:43 Xah Lee
2009-08-21 10:11 ` Teemu Likonen
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Xah Lee @ 2009-08-21 9:43 UTC (permalink / raw)
To: help-gnu-emacs
this is really a strang error.
eval this:
(replace-regexp-in-string "/" "\\" "//169.254.153.147/xah/Documents/
alice artwork scans/")
i get this error:
Debugger entered--Lisp error: (error "Invalid use of `\\' in
replacement text")
replace-match("\\" nil nil "/" nil)
replace-regexp-in-string("/" "\\" "//169.254.153.147/xah/Documents/
alice artwork scans/")
eval((replace-regexp-in-string "/" "\\" "//169.254.153.147/xah/
Documents/alice artwork scans/"))
eval-last-sexp-1(nil)
eval-last-sexp(nil)
call-interactively(eval-last-sexp nil nil)
any idea why?
double backslash should mean single backslash as far as i knows...
basically am trying to prepare a path to feed to w32-shell-execute.
Xah
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: double backslash problem in elisp
2009-08-21 9:43 double backslash problem in elisp Xah Lee
@ 2009-08-21 10:11 ` Teemu Likonen
2009-08-22 1:18 ` Kevin Rodgers
[not found] ` <mailman.5099.1250903947.2239.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 6+ messages in thread
From: Teemu Likonen @ 2009-08-21 10:11 UTC (permalink / raw)
To: help-gnu-emacs
On 2009-08-21 02:43 (-0700), Xah Lee wrote:
> this is really a strang error.
>
> eval this:
> (replace-regexp-in-string "/" "\\" "//169.254.153.147/xah/Documents/
> alice artwork scans/")
>
>
> i get this error:
>
> Debugger entered--Lisp error: (error "Invalid use of `\\' in
> replacement text")
> any idea why?
Because backslash already has back-reference meaning in replace strings
(\&, \1, \2 ...). Hence a single backslash is illegal. So, you want a
single backslash literally in the replace string. First you put double
backslash to escape the special meaning in Lisp strings ("\\"), then you
must double it to escape the special meaning in regexp replace strings
("\\\\").
Alternatively you can give non-nil LITERAL argument for
replace-regexp-in-string; this takes out the special regexp meaning. So
these are the options:
(replace-regexp-in-string "/" "\\\\" "string")
(replace-regexp-in-string "/" "\\" "string" nil t)
> basically am trying to prepare a path to feed to w32-shell-execute.
Note that you may need shell-quote-argument too.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: double backslash problem in elisp
2009-08-21 9:43 double backslash problem in elisp Xah Lee
2009-08-21 10:11 ` Teemu Likonen
@ 2009-08-22 1:18 ` Kevin Rodgers
[not found] ` <mailman.5099.1250903947.2239.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 6+ messages in thread
From: Kevin Rodgers @ 2009-08-22 1:18 UTC (permalink / raw)
To: help-gnu-emacs
Xah Lee wrote:
> double backslash should mean single backslash as far as i knows...
Yes, double backslash within "..." means a single backslash character
within that string.
But a backslash character within a regexp (i.e. a string interpreted by
a function such as replace-regexp-in-string as a regexp) is an escape
character in the regexp syntax. So it cannot stand on its own.
<grrr>Really Xah, for all your chest-puffing about your experience
in the field of programming, you really surprise me sometimes with
questions like this.</grrr>
--
Kevin Rodgers
Denver, Colorado, USA
^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <mailman.5099.1250903947.2239.help-gnu-emacs@gnu.org>]
* Re: double backslash problem in elisp
[not found] ` <mailman.5099.1250903947.2239.help-gnu-emacs@gnu.org>
@ 2009-08-22 2:42 ` Xah Lee
2009-08-22 21:39 ` Kevin Rodgers
2009-08-22 21:01 ` John A Pershing Jr
1 sibling, 1 reply; 6+ messages in thread
From: Xah Lee @ 2009-08-22 2:42 UTC (permalink / raw)
To: help-gnu-emacs
On Aug 21, 6:18 pm, Kevin Rodgers <kevin.d.rodg...@gmail.com> wrote:
> Xah Lee wrote:
> > double backslash should mean single backslash as far as i knows...
>
> Yes, double backslash within "..." means a single backslash character
> within that string.
>
> But a backslash character within a regexp (i.e. a string interpreted by
> a function such as replace-regexp-in-string as a regexp) is an escape
> character in the regexp syntax. So it cannot stand on its own.
>
> <grrr>Really Xah, for all your chest-puffing about your experience
> in the field of programming, you really surprise me sometimes with
> questions like this.</grrr>
well i reddit the master regex cover to cover in 1998, and have Larry
Wall's sig to prove it.
• Pathetically Elational Regex Language
http://xahlee.org/UnixResource_dir/perlr.html
☺
i swear i replied to this thread with something useful this morn...
but cant' find it now. Maybe it went private mail by mistake...
Xah
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: double backslash problem in elisp
[not found] ` <mailman.5099.1250903947.2239.help-gnu-emacs@gnu.org>
2009-08-22 2:42 ` Xah Lee
@ 2009-08-22 21:01 ` John A Pershing Jr
1 sibling, 0 replies; 6+ messages in thread
From: John A Pershing Jr @ 2009-08-22 21:01 UTC (permalink / raw)
To: help-gnu-emacs
Kevin Rodgers <kevin.d.rodgers@gmail.com> writes:
> <grrr>Really Xah, for all your chest-puffing about your experience in
> the field of programming, you really surprise me sometimes with
> questions like this.</grrr>
Give the guy a break. *Especially* for someone with many years of
experience, presumably including bash, elisp, C, Java, grep, sed, etc.,
it's hard to keep straight how many times a backslash needs to be
escaped in which context to get the desired result. Hell, I've been
doing this stuff for nearly 40 years, and I still have to experiment at
times to get the backslashes correct.
-jp
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-08-22 21:39 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-21 9:43 double backslash problem in elisp Xah Lee
2009-08-21 10:11 ` Teemu Likonen
2009-08-22 1:18 ` Kevin Rodgers
[not found] ` <mailman.5099.1250903947.2239.help-gnu-emacs@gnu.org>
2009-08-22 2:42 ` Xah Lee
2009-08-22 21:39 ` Kevin Rodgers
2009-08-22 21:01 ` John A Pershing Jr
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).