* bug#8531: 24.0.50; shell-quote-argument shouldn't escape special characters
2011-04-21 7:23 bug#8531: 24.0.50; shell-quote-argument shouldn't escape special characters Thierry Volpiatto
@ 2011-04-21 10:33 ` Eli Zaretskii
2011-04-21 12:10 ` Thierry Volpiatto
2014-12-08 9:34 ` bug#8531: 24.0.50; samer
` (3 subsequent siblings)
4 siblings, 1 reply; 29+ messages in thread
From: Eli Zaretskii @ 2011-04-21 10:33 UTC (permalink / raw)
To: Thierry Volpiatto; +Cc: 8531
> From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
> Date: Thu, 21 Apr 2011 09:23:13 +0200
>
> (shell-quote-argument "Vidéos")
> ==> "Vid\\éos"
>
> eshell:
> ls (shell-quote-argument "Vidéos")
> Vid\éos: No such file or directory
Looks like a problem in Eshell: I have no problem with using the
result of shell-quote-argument in "M-!".
^ permalink raw reply [flat|nested] 29+ messages in thread
* bug#8531: 24.0.50; shell-quote-argument shouldn't escape special characters
2011-04-21 10:33 ` Eli Zaretskii
@ 2011-04-21 12:10 ` Thierry Volpiatto
2011-04-21 13:04 ` Eli Zaretskii
0 siblings, 1 reply; 29+ messages in thread
From: Thierry Volpiatto @ 2011-04-21 12:10 UTC (permalink / raw)
To: bug-gnu-emacs
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
>> Date: Thu, 21 Apr 2011 09:23:13 +0200
>>
>> (shell-quote-argument "Vidéos")
>> ==> "Vid\\éos"
>>
>> eshell:
>> ls (shell-quote-argument "Vidéos")
>> Vid\éos: No such file or directory
>
> Looks like a problem in Eshell:
No it is the same in M-x shell
> I have no problem with using the
> result of shell-quote-argument in "M-!".
Which result?
Which command?
I am speaking of escaping accentued characters "é, à etc..."
Why `shell-quote-argument' escape such characters?
--
A+ Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997
^ permalink raw reply [flat|nested] 29+ messages in thread
* bug#8531: 24.0.50; shell-quote-argument shouldn't escape special characters
2011-04-21 12:10 ` Thierry Volpiatto
@ 2011-04-21 13:04 ` Eli Zaretskii
2011-04-21 13:31 ` Thierry Volpiatto
0 siblings, 1 reply; 29+ messages in thread
From: Eli Zaretskii @ 2011-04-21 13:04 UTC (permalink / raw)
To: Thierry Volpiatto; +Cc: bug-gnu-emacs
> From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
> Date: Thu, 21 Apr 2011 14:10:49 +0200
>
> > I have no problem with using the
> > result of shell-quote-argument in "M-!".
> Which result?
> Which command?
The command was "ls Vid\éos". It displayed the files in that
directory.
> I am speaking of escaping accentued characters "é, à etc..."
Yes, so am I.
> Why `shell-quote-argument' escape such characters?
Because it wants to play safe. In a Posix shell, any non-special
character preceded with a backslash stands for itself, I'm sure you
know that. Backslash-escaping anything that is not in the Posix
character set avoids too much knowledge about the underlying shell's
special characters, and should be harmless if the escaped characters
are not special.
^ permalink raw reply [flat|nested] 29+ messages in thread
* bug#8531: 24.0.50; shell-quote-argument shouldn't escape special characters
2011-04-21 13:04 ` Eli Zaretskii
@ 2011-04-21 13:31 ` Thierry Volpiatto
2011-04-21 13:58 ` Eli Zaretskii
0 siblings, 1 reply; 29+ messages in thread
From: Thierry Volpiatto @ 2011-04-21 13:31 UTC (permalink / raw)
To: bug-gnu-emacs
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
>> Date: Thu, 21 Apr 2011 14:10:49 +0200
>>
>> > I have no problem with using the
>> > result of shell-quote-argument in "M-!".
>> Which result?
>> Which command?
>
> The command was "ls Vid\éos". It displayed the files in that
> directory.
Yes, but ls "Vid\éos" fail.
The point is being able to do something like this:
(shell-command (format "ls %s" (shell-quote-argument (read-string "Fname: "))))
instead of e.g
(shell-command (format "ls '%s'" (read-string "Fname: ")))
>> I am speaking of escaping accentued characters "é, à etc..."
>
> Yes, so am I.
Ok.
>> Why `shell-quote-argument' escape such characters?
>
> Because it wants to play safe. In a Posix shell, any non-special
> character preceded with a backslash stands for itself, I'm sure you
> know that. Backslash-escaping anything that is not in the Posix
> character set avoids too much knowledge about the underlying shell's
> special characters, and should be harmless if the escaped characters
> are not special.
Oh yes, i remember now that "é etc.." are not in posix character set,
thanks.
--
A+ Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997
^ permalink raw reply [flat|nested] 29+ messages in thread
* bug#8531: 24.0.50; shell-quote-argument shouldn't escape special characters
2011-04-21 13:31 ` Thierry Volpiatto
@ 2011-04-21 13:58 ` Eli Zaretskii
2011-04-21 16:34 ` Thierry Volpiatto
0 siblings, 1 reply; 29+ messages in thread
From: Eli Zaretskii @ 2011-04-21 13:58 UTC (permalink / raw)
To: Thierry Volpiatto; +Cc: bug-gnu-emacs
> From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
> Date: Thu, 21 Apr 2011 15:31:41 +0200
>
> > The command was "ls Vid\éos". It displayed the files in that
> > directory.
> Yes, but ls "Vid\éos" fail.
Where did the quotes come from? shell-quote-argument doesn't add
extra quotes.
> The point is being able to do something like this:
> (shell-command (format "ls %s" (shell-quote-argument (read-string "Fname: "))))
>
> instead of e.g
> (shell-command (format "ls '%s'" (read-string "Fname: ")))
The former works for me without any changes. Are you sure you use the
default version of shell-quote-argument?
^ permalink raw reply [flat|nested] 29+ messages in thread
* bug#8531: 24.0.50; shell-quote-argument shouldn't escape special characters
2011-04-21 13:58 ` Eli Zaretskii
@ 2011-04-21 16:34 ` Thierry Volpiatto
2011-04-21 23:14 ` Glenn Morris
0 siblings, 1 reply; 29+ messages in thread
From: Thierry Volpiatto @ 2011-04-21 16:34 UTC (permalink / raw)
To: bug-gnu-emacs
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
>> Date: Thu, 21 Apr 2011 15:31:41 +0200
>>
>> > The command was "ls Vid\éos". It displayed the files in that
>> > directory.
>> Yes, but ls "Vid\éos" fail.
>
> Where did the quotes come from? shell-quote-argument doesn't add
> extra quotes.
>
>> The point is being able to do something like this:
>> (shell-command (format "ls %s" (shell-quote-argument (read-string "Fname: "))))
>>
>> instead of e.g
>> (shell-command (format "ls '%s'" (read-string "Fname: ")))
>
> The former works for me without any changes. Are you sure you use the
> default version of shell-quote-argument?
Yes you're right, sorry, i was inserting ~/Vidéos.
So yes the problem is related only to eshell.
--
A+ Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997
^ permalink raw reply [flat|nested] 29+ messages in thread
* bug#8531: 24.0.50; shell-quote-argument shouldn't escape special characters
2011-04-21 16:34 ` Thierry Volpiatto
@ 2011-04-21 23:14 ` Glenn Morris
2011-04-22 5:53 ` Eli Zaretskii
2011-04-22 6:03 ` Thierry Volpiatto
0 siblings, 2 replies; 29+ messages in thread
From: Glenn Morris @ 2011-04-21 23:14 UTC (permalink / raw)
To: Thierry Volpiatto; +Cc: 8531
Thierry Volpiatto wrote:
> So yes the problem is related only to eshell.
Why do you want/need to call shell-quote-argument inside eshell?
^ permalink raw reply [flat|nested] 29+ messages in thread
* bug#8531: 24.0.50; shell-quote-argument shouldn't escape special characters
2011-04-21 23:14 ` Glenn Morris
@ 2011-04-22 5:53 ` Eli Zaretskii
2011-04-22 7:10 ` Glenn Morris
2011-04-22 6:03 ` Thierry Volpiatto
1 sibling, 1 reply; 29+ messages in thread
From: Eli Zaretskii @ 2011-04-22 5:53 UTC (permalink / raw)
To: Glenn Morris; +Cc: 8531, thierry.volpiatto
> From: Glenn Morris <rgm@gnu.org>
> Date: Thu, 21 Apr 2011 19:14:58 -0400
> Cc: 8531@debbugs.gnu.org
>
> Thierry Volpiatto wrote:
>
> > So yes the problem is related only to eshell.
>
> Why do you want/need to call shell-quote-argument inside eshell?
He doesn't. But a literal Vid\éos (with the backslash typed by hand)
doesn't work with Eshell, either. Doesn't Eshell support the standard
shell feature whereby a non-special character escaped by a backslash
stands for itself?
^ permalink raw reply [flat|nested] 29+ messages in thread
* bug#8531: 24.0.50; shell-quote-argument shouldn't escape special characters
2011-04-22 5:53 ` Eli Zaretskii
@ 2011-04-22 7:10 ` Glenn Morris
2011-04-22 8:03 ` Eli Zaretskii
0 siblings, 1 reply; 29+ messages in thread
From: Glenn Morris @ 2011-04-22 7:10 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 8531, thierry.volpiatto
Eli Zaretskii wrote:
> He doesn't. But a literal Vid\éos (with the backslash typed by hand)
> doesn't work with Eshell, either. Doesn't Eshell support the standard
> shell feature whereby a non-special character escaped by a backslash
> stands for itself?
From reading the comments in eshell-parse-backslash, no.
^ permalink raw reply [flat|nested] 29+ messages in thread
* bug#8531: 24.0.50; shell-quote-argument shouldn't escape special characters
2011-04-22 7:10 ` Glenn Morris
@ 2011-04-22 8:03 ` Eli Zaretskii
0 siblings, 0 replies; 29+ messages in thread
From: Eli Zaretskii @ 2011-04-22 8:03 UTC (permalink / raw)
To: Glenn Morris; +Cc: 8531, thierry.volpiatto
> From: Glenn Morris <rgm@gnu.org>
> Cc: thierry.volpiatto@gmail.com, 8531@debbugs.gnu.org
> Date: Fri, 22 Apr 2011 03:10:39 -0400
>
> Eli Zaretskii wrote:
>
> > Doesn't Eshell support the standard shell feature whereby a
> > non-special character escaped by a backslash stands for itself?
>
> From reading the comments in eshell-parse-backslash, no.
IMO, the reasons stated in those comments for not supporting escaped
non-special characters are bad a design decision. Eshell should only
do that on Windows, and even then there should be a user option for
such behavior, the default being that the directory separator is a
forward slash.
IOW, Eshell should behave like a Posix shell, even on Windows.
^ permalink raw reply [flat|nested] 29+ messages in thread
* bug#8531: 24.0.50; shell-quote-argument shouldn't escape special characters
2011-04-21 23:14 ` Glenn Morris
2011-04-22 5:53 ` Eli Zaretskii
@ 2011-04-22 6:03 ` Thierry Volpiatto
2011-04-22 6:15 ` Eli Zaretskii
1 sibling, 1 reply; 29+ messages in thread
From: Thierry Volpiatto @ 2011-04-22 6:03 UTC (permalink / raw)
To: Glenn Morris; +Cc: 8531
Glenn Morris <rgm@gnu.org> writes:
> Thierry Volpiatto wrote:
>
>> So yes the problem is related only to eshell.
>
> Why do you want/need to call shell-quote-argument inside eshell?
For compatibility with Windows filenames:
--8<---------------cut here---------------start------------->8---
(goto-char (point-max))
(insert
(format "cd '%s'" anything-ff-default-directory))
(eshell-send-input)))
--8<---------------cut here---------------end--------------->8---
As there is no evaluation inside the quotes,
this actually works fine, but before that, i wrote it with
shell-quote-argument, which was working fine excepted with accentued char.
--
A+ Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997
^ permalink raw reply [flat|nested] 29+ messages in thread
* bug#8531: 24.0.50; shell-quote-argument shouldn't escape special characters
2011-04-22 6:03 ` Thierry Volpiatto
@ 2011-04-22 6:15 ` Eli Zaretskii
2011-04-22 9:21 ` Thierry Volpiatto
0 siblings, 1 reply; 29+ messages in thread
From: Eli Zaretskii @ 2011-04-22 6:15 UTC (permalink / raw)
To: Thierry Volpiatto; +Cc: 8531
> From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
> Date: Fri, 22 Apr 2011 08:03:30 +0200
> Cc: 8531@debbugs.gnu.org
>
> Glenn Morris <rgm@gnu.org> writes:
>
> > Thierry Volpiatto wrote:
> >
> >> So yes the problem is related only to eshell.
> >
> > Why do you want/need to call shell-quote-argument inside eshell?
> For compatibility with Windows filenames:
You mean, file names with embedded white space? If not, what other
compatibility issues are there?
^ permalink raw reply [flat|nested] 29+ messages in thread
* bug#8531: 24.0.50; shell-quote-argument shouldn't escape special characters
2011-04-22 6:15 ` Eli Zaretskii
@ 2011-04-22 9:21 ` Thierry Volpiatto
0 siblings, 0 replies; 29+ messages in thread
From: Thierry Volpiatto @ 2011-04-22 9:21 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 8531
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
>> Date: Fri, 22 Apr 2011 08:03:30 +0200
>> Cc: 8531@debbugs.gnu.org
>>
>> Glenn Morris <rgm@gnu.org> writes:
>>
>> > Thierry Volpiatto wrote:
>> >
>> >> So yes the problem is related only to eshell.
>> >
>> > Why do you want/need to call shell-quote-argument inside eshell?
>> For compatibility with Windows filenames:
>
> You mean, file names with embedded white space?
Yes.
> If not, what other compatibility issues are there?
Nothing else for the moment.
--
A+ Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997
^ permalink raw reply [flat|nested] 29+ messages in thread
* bug#8531: 24.0.50;
2011-04-21 7:23 bug#8531: 24.0.50; shell-quote-argument shouldn't escape special characters Thierry Volpiatto
2011-04-21 10:33 ` Eli Zaretskii
@ 2014-12-08 9:34 ` samer
2014-12-08 18:46 ` Stefan Monnier
2014-12-08 16:48 ` bug#8531: 24.0.50; shell-quote-argument shouldn't escape special characters samer
` (2 subsequent siblings)
4 siblings, 1 reply; 29+ messages in thread
From: samer @ 2014-12-08 9:34 UTC (permalink / raw)
To: 8531
Hi,
I found this bug on debbugs thanks to Lars' getting started guide. This
change simplifies the code by making the behavior that used occur for
newlines following a backslash, returning the character literal after
the backslash, the behavior that occurs for _all_ non-special
characters.
This is my first contribution to emacs, so don't hesitate to correct
anything nonstandard in the patch I've included. I'm interested in doing
more work on eshell, too. What eshell bugs would benefit from a fresh
pair of eyes?
Best,
Samer
Patch for esh-arg.el:
***
/home/samer/build/emacs120714/share/emacs/25.0.50/lisp/eshell/esh-arg.el.gz.old
---
/home/samer/build/emacs120714/share/emacs/25.0.50/lisp/eshell/esh-arg.el.gz
***************
*** 89,95 ****
(goto-char (match-end 0))
(eshell-finish-arg)))))
! ;; backslash before a special character means escape it
'eshell-parse-backslash
;; text beginning with ' is a literally quoted
--- 89,96 ----
(goto-char (match-end 0))
(eshell-finish-arg)))))
! ;; backslash before a character escapes it if the character is
! ;; special, and returns the character literal if it is non-special
'eshell-parse-backslash
;; text beginning with ' is a literally quoted
***************
*** 282,294 ****
"A stub function that generates an error if a floating operator is
found."
(error "Unhandled operator in input text"))
- (defsubst eshell-looking-at-backslash-return (pos)
- "Test whether a backslash-return sequence occurs at POS."
- (and (eq (char-after pos) ?\\)
- (or (= (1+ pos) (point-max))
- (and (eq (char-after (1+ pos)) ?\n)
- (= (+ pos 2) (point-max))))))
-
(defun eshell-quote-backslash (string &optional index)
"Intelligently backslash the character occurring in STRING at INDEX.
If the character is itself a backslash, it needs no escaping."
--- 283,288 ----
***************
*** 305,313 ****
(string ?\\ char)))))
(defun eshell-parse-backslash ()
! "Parse a single backslash (\) character, which might mean escape.
! It only means escape if the character immediately following is a
! special character that is not itself a backslash."
(when (eq (char-after) ?\\)
(if (eshell-looking-at-backslash-return (point))
(throw 'eshell-incomplete ?\\)
--- 299,309 ----
(string ?\\ char)))))
(defun eshell-parse-backslash ()
! "Parse a single backslash (\) character to escape the character
after.
! If the character immediately following the backslash is a special
! character, it returns the escaped version of that character.
! Else, the character has no meaning and is returned as the literal
! character. This conforms with the behavior of bash."
(when (eq (char-after) ?\\)
(if (eshell-looking-at-backslash-return (point))
(throw 'eshell-incomplete ?\\)
***************
*** 321,338 ****
(forward-char 2)
(list 'eshell-escape-arg
(char-to-string (char-before))))
- ;; allow \\<RET> to mean a literal "\" character followed by a
- ;; normal return, rather than a backslash followed by a line
- ;; continuation (i.e., "\\ + \n" rather than "\ + \\n"). This
- ;; is necessary because backslashes in Eshell are not special
- ;; unless they either precede something special, or precede a
- ;; backslash that precedes something special. (Mainly this is
- ;; done to make using backslash on Windows systems more
- ;; natural-feeling).
- (if (eshell-looking-at-backslash-return (1+ (point)))
- (forward-char))
(forward-char)
! "\\"))))
(defun eshell-parse-literal-quote ()
"Parse a literally quoted string. Nothing has special meaning!"
--- 317,325 ----
(forward-char 2)
(list 'eshell-escape-arg
(char-to-string (char-before))))
(forward-char)
! (forward-char)
! (char-before)))))
(defun eshell-parse-literal-quote ()
"Parse a literally quoted string. Nothing has special meaning!"
Diff finished. Mon Dec 8 01:23:11 2014
***
/home/samer/build/emacs120714/share/emacs/25.0.50/lisp/eshell/esh-arg.el.gz.old
---
/home/samer/build/emacs120714/share/emacs/25.0.50/lisp/eshell/esh-arg.el.gz
***************
*** 89,95 ****
(goto-char (match-end 0))
(eshell-finish-arg)))))
! ;; backslash before a special character means escape it
'eshell-parse-backslash
;; text beginning with ' is a literally quoted
--- 89,96 ----
(goto-char (match-end 0))
(eshell-finish-arg)))))
! ;; backslash before a character escapes it if the character is
! ;; special, and returns the character literal if it is non-special
'eshell-parse-backslash
;; text beginning with ' is a literally quoted
***************
*** 282,294 ****
"A stub function that generates an error if a floating operator is
found."
(error "Unhandled operator in input text"))
- (defsubst eshell-looking-at-backslash-return (pos)
- "Test whether a backslash-return sequence occurs at POS."
- (and (eq (char-after pos) ?\\)
- (or (= (1+ pos) (point-max))
- (and (eq (char-after (1+ pos)) ?\n)
- (= (+ pos 2) (point-max))))))
-
(defun eshell-quote-backslash (string &optional index)
"Intelligently backslash the character occurring in STRING at INDEX.
If the character is itself a backslash, it needs no escaping."
--- 283,288 ----
***************
*** 305,313 ****
(string ?\\ char)))))
(defun eshell-parse-backslash ()
! "Parse a single backslash (\) character, which might mean escape.
! It only means escape if the character immediately following is a
! special character that is not itself a backslash."
(when (eq (char-after) ?\\)
(if (eshell-looking-at-backslash-return (point))
(throw 'eshell-incomplete ?\\)
--- 299,309 ----
(string ?\\ char)))))
(defun eshell-parse-backslash ()
! "Parse a single backslash (\) character to escape the character
after.
! If the character immediately following the backslash is a special
! character, it returns the escaped version of that character.
! Else, the character has no meaning and is returned as the literal
! character. This conforms with the behavior of bash."
(when (eq (char-after) ?\\)
(if (eshell-looking-at-backslash-return (point))
(throw 'eshell-incomplete ?\\)
***************
*** 321,338 ****
(forward-char 2)
(list 'eshell-escape-arg
(char-to-string (char-before))))
- ;; allow \\<RET> to mean a literal "\" character followed by a
- ;; normal return, rather than a backslash followed by a line
- ;; continuation (i.e., "\\ + \n" rather than "\ + \\n"). This
- ;; is necessary because backslashes in Eshell are not special
- ;; unless they either precede something special, or precede a
- ;; backslash that precedes something special. (Mainly this is
- ;; done to make using backslash on Windows systems more
- ;; natural-feeling).
- (if (eshell-looking-at-backslash-return (1+ (point)))
- (forward-char))
(forward-char)
! "\\"))))
(defun eshell-parse-literal-quote ()
"Parse a literally quoted string. Nothing has special meaning!"
--- 317,325 ----
(forward-char 2)
(list 'eshell-escape-arg
(char-to-string (char-before))))
(forward-char)
! (forward-char)
! (char-before)))))
(defun eshell-parse-literal-quote ()
"Parse a literally quoted string. Nothing has special meaning!"
^ permalink raw reply [flat|nested] 29+ messages in thread
* bug#8531: 24.0.50;
2014-12-08 9:34 ` bug#8531: 24.0.50; samer
@ 2014-12-08 18:46 ` Stefan Monnier
2014-12-09 0:15 ` samer
0 siblings, 1 reply; 29+ messages in thread
From: Stefan Monnier @ 2014-12-08 18:46 UTC (permalink / raw)
To: samer; +Cc: 8531
> I found this bug on debbugs thanks to Lars' getting started guide. This
> change simplifies the code by making the behavior that used occur for
> newlines following a backslash, returning the character literal after the
> backslash, the behavior that occurs for _all_ non-special characters.
This looks OK, thanks. Please include an entry for etc/NEWS mentioning
the change in behavior and a description for the ChangeLog file.
Stefan
^ permalink raw reply [flat|nested] 29+ messages in thread
* bug#8531: 24.0.50;
2014-12-08 18:46 ` Stefan Monnier
@ 2014-12-09 0:15 ` samer
2014-12-09 0:41 ` Lars Magne Ingebrigtsen
0 siblings, 1 reply; 29+ messages in thread
From: samer @ 2014-12-09 0:15 UTC (permalink / raw)
To: Stefan Monnier
Forgot to CC debbugs in my previous email:
This is the full patch, generated with magit because I couldn't commit
this to a private branch (I get "Empty change log entry" even though
I've changed both ChangeLog files. I don't know awk, do you have any
idea why I would get that error?)
Best,
Samer
Changes from master to working tree
4 files changed, 26 insertions(+), 22 deletions(-)
etc/ChangeLog | 4 ++++
etc/NEWS | 6 ++++++
lisp/ChangeLog | 7 +++++++
lisp/eshell/esh-arg.el | 31 +++++++++----------------------
Modified etc/ChangeLog
diff --git a/etc/ChangeLog b/etc/ChangeLog
index 309c01f..3e76256 100644
--- a/etc/ChangeLog
+++ b/etc/ChangeLog
@@ -1,3 +1,7 @@
+2014-12-08 Samer Masterson <samer@dark-horse>
+
+ * NEWS: Mention change in backslash expand behavior for eshell.
+
2014-12-08 Lars Magne Ingebrigtsen <larsi@gnus.org>
* NEWS: Mention the new eww `S' command.
Modified etc/NEWS
diff --git a/etc/NEWS b/etc/NEWS
index 56036f8..e6d9aab 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -192,6 +192,12 @@ result of the calculation into the current buffer.
*** New minor mode global-eldoc-mode
*** eldoc-documentation-function now defaults to nil
+** eshell
+
+*** Backslash (\) expands to the character literal after it if that
+character is non-special (e.g. 'b\in' expands to 'bin', because 'i' is
+not a special character). This behavior conforms with bash.
+
** eww
+++
Modified lisp/ChangeLog
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 2669e07..0ec9b35 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
+2014-12-08 Samer Masterson <samer@samertm.com>
+
+ * eshell/esh-arg.el (eshell-parse-backslash): Return the literal
+ character after the backslash if the character is non-special
+ (bug#8531).
+ (eshell-looking-at-backslash-return): Unused, remove.
+
2014-12-08 Lars Magne Ingebrigtsen <larsi@gnus.org>
* net/nsm.el (nsm-check-protocol): Test for RC4 on `high'.
Modified lisp/eshell/esh-arg.el
diff --git a/lisp/eshell/esh-arg.el b/lisp/eshell/esh-arg.el
index 704de57..33ff384 100644
--- a/lisp/eshell/esh-arg.el
+++ b/lisp/eshell/esh-arg.el
@@ -89,7 +89,8 @@ yield the values intended."
(goto-char (match-end 0))
(eshell-finish-arg)))))
- ;; backslash before a special character means escape it
+ ;; backslash before a character escapes it if the character is
+ ;; special, and returns the character literal if it is non-special
'eshell-parse-backslash
;; text beginning with ' is a literally quoted
@@ -282,13 +283,6 @@ Point is left at the end of the arguments."
"A stub function that generates an error if a floating operator is
found."
(error "Unhandled operator in input text"))
-(defsubst eshell-looking-at-backslash-return (pos)
- "Test whether a backslash-return sequence occurs at POS."
- (and (eq (char-after pos) ?\\)
- (or (= (1+ pos) (point-max))
- (and (eq (char-after (1+ pos)) ?\n)
- (= (+ pos 2) (point-max))))))
-
(defun eshell-quote-backslash (string &optional index)
"Intelligently backslash the character occurring in STRING at INDEX.
If the character is itself a backslash, it needs no escaping."
@@ -305,9 +299,11 @@ If the character is itself a backslash, it needs no
escaping."
(string ?\\ char)))))
(defun eshell-parse-backslash ()
- "Parse a single backslash (\) character, which might mean escape.
-It only means escape if the character immediately following is a
-special character that is not itself a backslash."
+ "Parse a single backslash (\) character to escape the character
after.
+If the character immediately following the backslash is a special
+character, it returns the escaped version of that character.
+Else, the character has no meaning and is returned as the literal
+character. This conforms with the behavior of bash."
(when (eq (char-after) ?\\)
(if (eshell-looking-at-backslash-return (point))
(throw 'eshell-incomplete ?\\)
@@ -321,18 +317,9 @@ special character that is not itself a backslash."
(forward-char 2)
(list 'eshell-escape-arg
(char-to-string (char-before))))
- ;; allow \\<RET> to mean a literal "\" character followed by a
- ;; normal return, rather than a backslash followed by a line
- ;; continuation (i.e., "\\ + \n" rather than "\ + \\n"). This
- ;; is necessary because backslashes in Eshell are not special
- ;; unless they either precede something special, or precede a
- ;; backslash that precedes something special. (Mainly this is
- ;; done to make using backslash on Windows systems more
- ;; natural-feeling).
- (if (eshell-looking-at-backslash-return (1+ (point)))
- (forward-char))
(forward-char)
- "\\"))))
+ (forward-char)
+ (char-before)))))
(defun eshell-parse-literal-quote ()
"Parse a literally quoted string. Nothing has special meaning!"
^ permalink raw reply related [flat|nested] 29+ messages in thread
* bug#8531: 24.0.50;
2014-12-09 0:15 ` samer
@ 2014-12-09 0:41 ` Lars Magne Ingebrigtsen
2014-12-09 2:11 ` samer
0 siblings, 1 reply; 29+ messages in thread
From: Lars Magne Ingebrigtsen @ 2014-12-09 0:41 UTC (permalink / raw)
To: samer; +Cc: 8531
samer <samer@samertm.com> writes:
> Forgot to CC debbugs in my previous email:
Looks good, I think. Do you have FSF copyright assignment papers on file?
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 29+ messages in thread
* bug#8531: 24.0.50;
2014-12-09 0:41 ` Lars Magne Ingebrigtsen
@ 2014-12-09 2:11 ` samer
2014-12-09 2:14 ` Lars Magne Ingebrigtsen
2014-12-09 22:11 ` samer
0 siblings, 2 replies; 29+ messages in thread
From: samer @ 2014-12-09 2:11 UTC (permalink / raw)
To: Lars Magne Ingebrigtsen; +Cc: 8531
On 2014-12-08 16:41, Lars Magne Ingebrigtsen wrote:
> samer <samer@samertm.com> writes:
>
>> Forgot to CC debbugs in my previous email:
>
> Looks good, I think. Do you have FSF copyright assignment papers on
> file?
I don't, but I would be willing to assign my copyright to the FSF. How
can we start that process?
Best,
Samer
^ permalink raw reply [flat|nested] 29+ messages in thread
* bug#8531: 24.0.50;
2014-12-09 2:11 ` samer
@ 2014-12-09 2:14 ` Lars Magne Ingebrigtsen
2014-12-09 22:11 ` samer
1 sibling, 0 replies; 29+ messages in thread
From: Lars Magne Ingebrigtsen @ 2014-12-09 2:14 UTC (permalink / raw)
To: 8531
samer <samer@samertm.com> writes:
> I don't, but I would be willing to assign my copyright to the FSF. How
> can we start that process?
I've sent the assignment form off-list.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 29+ messages in thread
* bug#8531: 24.0.50;
2014-12-09 2:11 ` samer
2014-12-09 2:14 ` Lars Magne Ingebrigtsen
@ 2014-12-09 22:11 ` samer
2014-12-09 22:21 ` Lars Magne Ingebrigtsen
1 sibling, 1 reply; 29+ messages in thread
From: samer @ 2014-12-09 22:11 UTC (permalink / raw)
To: Lars Magne Ingebrigtsen; +Cc: 8531
I've sent an email to assign@gnu.org. What is the next step for getting
this patch merged into Emacs?
Best,
Samer
^ permalink raw reply [flat|nested] 29+ messages in thread
* bug#8531: 24.0.50;
2014-12-09 22:11 ` samer
@ 2014-12-09 22:21 ` Lars Magne Ingebrigtsen
2014-12-09 22:30 ` samer
0 siblings, 1 reply; 29+ messages in thread
From: Lars Magne Ingebrigtsen @ 2014-12-09 22:21 UTC (permalink / raw)
To: samer; +Cc: 8531
samer <samer@samertm.com> writes:
> I've sent an email to assign@gnu.org. What is the next step for
> getting this patch merged into Emacs?
The copyright clerk will get in touch with you. Once the paperwork is
finalised, follow up to this bug report, and we can get your patches
installed.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 29+ messages in thread
* bug#8531: 24.0.50;
2014-12-09 22:21 ` Lars Magne Ingebrigtsen
@ 2014-12-09 22:30 ` samer
0 siblings, 0 replies; 29+ messages in thread
From: samer @ 2014-12-09 22:30 UTC (permalink / raw)
To: Lars Magne Ingebrigtsen; +Cc: 8531
Alright, thanks!
Best,
Samer
On 2014-12-09 14:21, Lars Magne Ingebrigtsen wrote:
> samer <samer@samertm.com> writes:
>
>> I've sent an email to assign@gnu.org. What is the next step for
>> getting this patch merged into Emacs?
>
> The copyright clerk will get in touch with you. Once the paperwork is
> finalised, follow up to this bug report, and we can get your patches
> installed.
^ permalink raw reply [flat|nested] 29+ messages in thread
* bug#8531: 24.0.50; shell-quote-argument shouldn't escape special characters
2011-04-21 7:23 bug#8531: 24.0.50; shell-quote-argument shouldn't escape special characters Thierry Volpiatto
2011-04-21 10:33 ` Eli Zaretskii
2014-12-08 9:34 ` bug#8531: 24.0.50; samer
@ 2014-12-08 16:48 ` samer
2015-02-24 10:51 ` bug#8531: 24.0.50; Samer Masterson
2015-03-15 11:58 ` Samer Masterson
4 siblings, 0 replies; 29+ messages in thread
From: samer @ 2014-12-08 16:48 UTC (permalink / raw)
To: 8531
Hi,
I found this bug on debbugs thanks to Lars' getting started guide. This
change simplifies the code by making the behavior that used occur for
newlines following a backslash, returning the character literal after
the backslash, the behavior that occurs for _all_ non-special
characters.
This is my first contribution to emacs, so don't hesitate to correct
anything nonstandard in the patch I've included. I'm interested in doing
more work on eshell, too. What eshell bugs would benefit from a fresh
pair of eyes?
Also, I sent this email to 8531@debbugs.gnu.org five hours and I didn't
see my email on debbugs. Apologies for the duplication if that email
actually went through.
Best,
Samer
Patch for esh-arg.el:
***
/home/samer/build/emacs120714/share/emacs/25.0.50/lisp/eshell/esh-arg.el.gz.old
---
/home/samer/build/emacs120714/share/emacs/25.0.50/lisp/eshell/esh-arg.el.gz
***************
*** 89,95 ****
(goto-char (match-end 0))
(eshell-finish-arg)))))
! ;; backslash before a special character means escape it
'eshell-parse-backslash
;; text beginning with ' is a literally quoted
--- 89,96 ----
(goto-char (match-end 0))
(eshell-finish-arg)))))
! ;; backslash before a character escapes it if the character is
! ;; special, and returns the character literal if it is non-special
'eshell-parse-backslash
;; text beginning with ' is a literally quoted
***************
*** 282,294 ****
"A stub function that generates an error if a floating operator is
found."
(error "Unhandled operator in input text"))
- (defsubst eshell-looking-at-backslash-return (pos)
- "Test whether a backslash-return sequence occurs at POS."
- (and (eq (char-after pos) ?\\)
- (or (= (1+ pos) (point-max))
- (and (eq (char-after (1+ pos)) ?\n)
- (= (+ pos 2) (point-max))))))
-
(defun eshell-quote-backslash (string &optional index)
"Intelligently backslash the character occurring in STRING at INDEX.
If the character is itself a backslash, it needs no escaping."
--- 283,288 ----
***************
*** 305,313 ****
(string ?\\ char)))))
(defun eshell-parse-backslash ()
! "Parse a single backslash (\) character, which might mean escape.
! It only means escape if the character immediately following is a
! special character that is not itself a backslash."
(when (eq (char-after) ?\\)
(if (eshell-looking-at-backslash-return (point))
(throw 'eshell-incomplete ?\\)
--- 299,309 ----
(string ?\\ char)))))
(defun eshell-parse-backslash ()
! "Parse a single backslash (\) character to escape the character
after.
! If the character immediately following the backslash is a special
! character, it returns the escaped version of that character.
! Else, the character has no meaning and is returned as the literal
! character. This conforms with the behavior of bash."
(when (eq (char-after) ?\\)
(if (eshell-looking-at-backslash-return (point))
(throw 'eshell-incomplete ?\\)
***************
*** 321,338 ****
(forward-char 2)
(list 'eshell-escape-arg
(char-to-string (char-before))))
- ;; allow \\<RET> to mean a literal "\" character followed by a
- ;; normal return, rather than a backslash followed by a line
- ;; continuation (i.e., "\\ + \n" rather than "\ + \\n"). This
- ;; is necessary because backslashes in Eshell are not special
- ;; unless they either precede something special, or precede a
- ;; backslash that precedes something special. (Mainly this is
- ;; done to make using backslash on Windows systems more
- ;; natural-feeling).
- (if (eshell-looking-at-backslash-return (1+ (point)))
- (forward-char))
(forward-char)
! "\\"))))
(defun eshell-parse-literal-quote ()
"Parse a literally quoted string. Nothing has special meaning!"
--- 317,325 ----
(forward-char 2)
(list 'eshell-escape-arg
(char-to-string (char-before))))
(forward-char)
! (forward-char)
! (char-before)))))
(defun eshell-parse-literal-quote ()
"Parse a literally quoted string. Nothing has special meaning!"
Diff finished. Mon Dec 8 01:23:11 2014
***
/home/samer/build/emacs120714/share/emacs/25.0.50/lisp/eshell/esh-arg.el.gz.old
---
/home/samer/build/emacs120714/share/emacs/25.0.50/lisp/eshell/esh-arg.el.gz
***************
*** 89,95 ****
(goto-char (match-end 0))
(eshell-finish-arg)))))
! ;; backslash before a special character means escape it
'eshell-parse-backslash
;; text beginning with ' is a literally quoted
--- 89,96 ----
(goto-char (match-end 0))
(eshell-finish-arg)))))
! ;; backslash before a character escapes it if the character is
! ;; special, and returns the character literal if it is non-special
'eshell-parse-backslash
;; text beginning with ' is a literally quoted
***************
*** 282,294 ****
"A stub function that generates an error if a floating operator is
found."
(error "Unhandled operator in input text"))
- (defsubst eshell-looking-at-backslash-return (pos)
- "Test whether a backslash-return sequence occurs at POS."
- (and (eq (char-after pos) ?\\)
- (or (= (1+ pos) (point-max))
- (and (eq (char-after (1+ pos)) ?\n)
- (= (+ pos 2) (point-max))))))
-
(defun eshell-quote-backslash (string &optional index)
"Intelligently backslash the character occurring in STRING at INDEX.
If the character is itself a backslash, it needs no escaping."
--- 283,288 ----
***************
*** 305,313 ****
(string ?\\ char)))))
(defun eshell-parse-backslash ()
! "Parse a single backslash (\) character, which might mean escape.
! It only means escape if the character immediately following is a
! special character that is not itself a backslash."
(when (eq (char-after) ?\\)
(if (eshell-looking-at-backslash-return (point))
(throw 'eshell-incomplete ?\\)
--- 299,309 ----
(string ?\\ char)))))
(defun eshell-parse-backslash ()
! "Parse a single backslash (\) character to escape the character
after.
! If the character immediately following the backslash is a special
! character, it returns the escaped version of that character.
! Else, the character has no meaning and is returned as the literal
! character. This conforms with the behavior of bash."
(when (eq (char-after) ?\\)
(if (eshell-looking-at-backslash-return (point))
(throw 'eshell-incomplete ?\\)
***************
*** 321,338 ****
(forward-char 2)
(list 'eshell-escape-arg
(char-to-string (char-before))))
- ;; allow \\<RET> to mean a literal "\" character followed by a
- ;; normal return, rather than a backslash followed by a line
- ;; continuation (i.e., "\\ + \n" rather than "\ + \\n"). This
- ;; is necessary because backslashes in Eshell are not special
- ;; unless they either precede something special, or precede a
- ;; backslash that precedes something special. (Mainly this is
- ;; done to make using backslash on Windows systems more
- ;; natural-feeling).
- (if (eshell-looking-at-backslash-return (1+ (point)))
- (forward-char))
(forward-char)
! "\\"))))
(defun eshell-parse-literal-quote ()
"Parse a literally quoted string. Nothing has special meaning!"
--- 317,325 ----
(forward-char 2)
(list 'eshell-escape-arg
(char-to-string (char-before))))
(forward-char)
! (forward-char)
! (char-before)))))
(defun eshell-parse-literal-quote ()
"Parse a literally quoted string. Nothing has special meaning!"
^ permalink raw reply [flat|nested] 29+ messages in thread
* bug#8531: 24.0.50;
2011-04-21 7:23 bug#8531: 24.0.50; shell-quote-argument shouldn't escape special characters Thierry Volpiatto
` (2 preceding siblings ...)
2014-12-08 16:48 ` bug#8531: 24.0.50; shell-quote-argument shouldn't escape special characters samer
@ 2015-02-24 10:51 ` Samer Masterson
2015-03-03 15:52 ` Eli Zaretskii
2015-03-15 11:58 ` Samer Masterson
4 siblings, 1 reply; 29+ messages in thread
From: Samer Masterson @ 2015-02-24 10:51 UTC (permalink / raw)
To: 8531
[-- Attachment #1: Type: text/plain, Size: 4646 bytes --]
Hi,
My copyright papers have been processed. Can we apply this to master?
Best,
Samer
Changes from master to working tree
4 files changed, 26 insertions(+), 22 deletions(-)
etc/ChangeLog | 4 ++++
etc/NEWS | 6 ++++++
lisp/ChangeLog | 7 +++++++
lisp/eshell/esh-arg.el | 31 +++++++++----------------------
Modified etc/ChangeLog
diff --git a/etc/ChangeLog b/etc/ChangeLog
index 309c01f..3e76256 100644
--- a/etc/ChangeLog
+++ b/etc/ChangeLog
@@ -1,3 +1,7 @@
+2014-12-08 Samer Masterson <samer <at> dark-horse>
+
+ * NEWS: Mention change in backslash expand behavior for eshell.
+
2014-12-08 Lars Magne Ingebrigtsen <larsi <at> gnus.org>
* NEWS: Mention the new eww `S' command.
Modified etc/NEWS
diff --git a/etc/NEWS b/etc/NEWS
index 56036f8..e6d9aab 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -192,6 +192,12 @@ result of the calculation into the current buffer.
*** New minor mode global-eldoc-mode
*** eldoc-documentation-function now defaults to nil
+** eshell
+
+*** Backslash (\) expands to the character literal after it if that
+character is non-special (e.g. 'b\in' expands to 'bin', because 'i' is
+not a special character). This behavior conforms with bash.
+
** eww
+++
Modified lisp/ChangeLog
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 2669e07..0ec9b35 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
+2014-12-08 Samer Masterson <samer <at> samertm.com>
+
+ * eshell/esh-arg.el (eshell-parse-backslash): Return the literal
+ character after the backslash if the character is non-special
+ (bug#8531).
+ (eshell-looking-at-backslash-return): Unused, remove.
+
2014-12-08 Lars Magne Ingebrigtsen <larsi <at> gnus.org>
* net/nsm.el (nsm-check-protocol): Test for RC4 on `high'.
Modified lisp/eshell/esh-arg.el
diff --git a/lisp/eshell/esh-arg.el b/lisp/eshell/esh-arg.el
index 704de57..33ff384 100644
--- a/lisp/eshell/esh-arg.el
+++ b/lisp/eshell/esh-arg.el
@@ -89,7 +89,8 @@ yield the values intended."
(goto-char (match-end 0))
(eshell-finish-arg)))))
- ;; backslash before a special character means escape it
+ ;; backslash before a character escapes it if the character is
+ ;; special, and returns the character literal if it is non-special
'eshell-parse-backslash
;; text beginning with ' is a literally quoted
@@ -282,13 +283,6 @@ Point is left at the end of the arguments."
"A stub function that generates an error if a floating operator is
found."
(error "Unhandled operator in input text"))
-(defsubst eshell-looking-at-backslash-return (pos)
- "Test whether a backslash-return sequence occurs at POS."
- (and (eq (char-after pos) ?\\)
- (or (= (1+ pos) (point-max))
- (and (eq (char-after (1+ pos)) ?\n)
- (= (+ pos 2) (point-max))))))
-
(defun eshell-quote-backslash (string &optional index)
"Intelligently backslash the character occurring in STRING at INDEX.
If the character is itself a backslash, it needs no escaping."
@@ -305,9 +299,11 @@ If the character is itself a backslash, it needs no
escaping."
(string ?\\ char)))))
(defun eshell-parse-backslash ()
- "Parse a single backslash (\) character, which might mean escape.
-It only means escape if the character immediately following is a
-special character that is not itself a backslash."
+ "Parse a single backslash (\) character to escape the character
after.
+If the character immediately following the backslash is a special
+character, it returns the escaped version of that character.
+Else, the character has no meaning and is returned as the literal
+character. This conforms with the behavior of bash."
(when (eq (char-after) ?\\)
(if (eshell-looking-at-backslash-return (point))
(throw 'eshell-incomplete ?\\)
@@ -321,18 +317,9 @@ special character that is not itself a backslash."
(forward-char 2)
(list 'eshell-escape-arg
(char-to-string (char-before))))
- ;; allow \\<RET> to mean a literal "\" character followed by a
- ;; normal return, rather than a backslash followed by a line
- ;; continuation (i.e., "\\ + \n" rather than "\ + \\n"). This
- ;; is necessary because backslashes in Eshell are not special
- ;; unless they either precede something special, or precede a
- ;; backslash that precedes something special. (Mainly this is
- ;; done to make using backslash on Windows systems more
- ;; natural-feeling).
- (if (eshell-looking-at-backslash-return (1+ (point)))
- (forward-char))
(forward-char)
- "\\"))))
+ (forward-char)
+ (char-before)))))
(defun eshell-parse-literal-quote ()
"Parse a literally quoted string. Nothing has special meaning!"
[-- Attachment #2: Type: text/html, Size: 8584 bytes --]
^ permalink raw reply related [flat|nested] 29+ messages in thread
* bug#8531: 24.0.50;
2015-02-24 10:51 ` bug#8531: 24.0.50; Samer Masterson
@ 2015-03-03 15:52 ` Eli Zaretskii
[not found] ` <1425472710.1450.3@mail.samertm.com>
0 siblings, 1 reply; 29+ messages in thread
From: Eli Zaretskii @ 2015-03-03 15:52 UTC (permalink / raw)
To: Samer Masterson; +Cc: 8531
> Date: Tue, 24 Feb 2015 02:51:29 -0800
> From: Samer Masterson <samer@samertm.com>
>
> Changes from master to working tree
> 4 files changed, 26 insertions(+), 22 deletions(-)
> etc/ChangeLog | 4 ++++
> etc/NEWS | 6 ++++++
> lisp/ChangeLog | 7 +++++++
> lisp/eshell/esh-arg.el | 31 +++++++++----------------------
>
> Modified etc/ChangeLog
> diff --git a/etc/ChangeLog b/etc/ChangeLog
> index 309c01f..3e76256 100644
> --- a/etc/ChangeLog
> +++ b/etc/ChangeLog
> @@ -1,3 +1,7 @@
> +2014-12-08 Samer Masterson <samer <at> dark-horse>
> +
> + * NEWS: Mention change in backslash expand behavior for eshell.
> +
> 2014-12-08 Lars Magne Ingebrigtsen <larsi <at> gnus.org>
>
> * NEWS: Mention the new eww `S' command.
> Modified etc/NEWS
> diff --git a/etc/NEWS b/etc/NEWS
> index 56036f8..e6d9aab 100644
> --- a/etc/NEWS
> +++ b/etc/NEWS
> @@ -192,6 +192,12 @@ result of the calculation into the current buffer.
> *** New minor mode global-eldoc-mode
> *** eldoc-documentation-function now defaults to nil
>
> +** eshell
> +
> +*** Backslash (\) expands to the character literal after it if that
> +character is non-special (e.g. 'b\in' expands to 'bin', because 'i' is
> +not a special character). This behavior conforms with bash.
Thanks.
First, please leave 2 blanks between sentences (we use the US English
conventions for that).
More importantly, this patch doesn't really fix the original bug, does
it? Apologies if I missed something.
^ permalink raw reply [flat|nested] 29+ messages in thread
* bug#8531: 24.0.50;
2011-04-21 7:23 bug#8531: 24.0.50; shell-quote-argument shouldn't escape special characters Thierry Volpiatto
` (3 preceding siblings ...)
2015-02-24 10:51 ` bug#8531: 24.0.50; Samer Masterson
@ 2015-03-15 11:58 ` Samer Masterson
2015-04-09 2:32 ` Stefan Monnier
4 siblings, 1 reply; 29+ messages in thread
From: Samer Masterson @ 2015-03-15 11:58 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 8531
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 7410 bytes --]
Hi,
This is the updated patch. Thanks in advance for the review.
Just to clarify, the bug is that
$ ls Vid\éos
doesn't do the right thing in eshell (it preserves the backslash if
the character after it is non-special). This diverges from POSIX and
Bash.
New behavior:
Outside of a double quoted string, the backslash escapes the following
charater if that character is special. Otherwise it simply returns the
character afterwards (the backslash is ignored).
I expanded `eshell-parse-backslash's behavior to match Bash for quoted
strings as well. Inside a double quoted string, the backslash escapes
the following character if that character is special, otherwise the
backslash is preserved.
Best,
Samer
Patch below:
[PATCH] Fix bug#8531
* eshell/esh-arg.el (eshell-parse-argument-hook): Update comment.
(eshell-parse-backslash): Return escaped character after backslash
if it is special. Otherwise, if the backslash is not in a quoted
string, ignore the backslash and return the character after; if
the backslash is in a quoted string, return the backslash and the
character after. (bug#8531)
* automated/eshell.el (eshell-test/escape-nonspecial)
(eshell-test/escape-nonspecial-unicode)
(eshell-test/escape-nonspecial-quoted)
(eshell-test/escape-special-quoted): Add tests for new
`eshell-parse-backslash' behavior. (bug#8531)
---
lisp/ChangeLog | 9 +++++++++
lisp/eshell/esh-arg.el | 49 +++++++++++++++++++++---------------------------
test/ChangeLog | 8 ++++++++
test/automated/eshell.el | 31 ++++++++++++++++++++++++++++++
4 files changed, 69 insertions(+), 28 deletions(-)
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index a9cf1b0..209382d 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,12 @@
+2015-03-15 Samer Masterson <samer@samertm.com>
+
+ * eshell/esh-arg.el (eshell-parse-argument-hook): Update comment.
+ (eshell-parse-backslash): Return escaped character after backslash
+ if it is special. Otherwise, if the backslash is not in a quoted
+ string, ignore the backslash and return the character after; if
+ the backslash is in a quoted string, return the backslash and the
+ character after. (bug#8531)
+
2015-03-14 Michael R. Mauger <michael@mauger.com>
* progmodes/sql.el: Version 3.5
diff --git a/lisp/eshell/esh-arg.el b/lisp/eshell/esh-arg.el
index 5c7d7ca..a5f697f 100644
--- a/lisp/eshell/esh-arg.el
+++ b/lisp/eshell/esh-arg.el
@@ -89,7 +89,7 @@ yield the values intended."
(goto-char (match-end 0))
(eshell-finish-arg)))))
- ;; backslash before a special character means escape it
+ ;; parse backslash and the character after
'eshell-parse-backslash
;; text beginning with ' is a literally quoted
@@ -305,34 +305,27 @@ If the character is itself a backslash, it needs no escaping."
(string ?\\ char)))))
(defun eshell-parse-backslash ()
- "Parse a single backslash (\) character, which might mean escape.
-It only means escape if the character immediately following is a
-special character that is not itself a backslash."
+ "Parse a single backslash (\\) character and the character after.
+If the character after the backslash is special, always ignore
+the backslash and return the escaped character.
+
+Otherwise, if the backslash is not in quoted string, the
+backslash is ignored and the character after is returned. If the
+backslash is in a quoted string, the backslash and the character
+after are both returned."
(when (eq (char-after) ?\\)
- (if (eshell-looking-at-backslash-return (point))
- (throw 'eshell-incomplete ?\\)
- (if (and (not (eq (char-after (1+ (point))) ?\\))
- (if eshell-current-quoted
- (memq (char-after (1+ (point)))
- eshell-special-chars-inside-quoting)
- (memq (char-after (1+ (point)))
- eshell-special-chars-outside-quoting)))
- (progn
- (forward-char 2)
- (list 'eshell-escape-arg
- (char-to-string (char-before))))
- ;; allow \\<RET> to mean a literal "\" character followed by a
- ;; normal return, rather than a backslash followed by a line
- ;; continuation (i.e., "\\ + \n" rather than "\ + \\n"). This
- ;; is necessary because backslashes in Eshell are not special
- ;; unless they either precede something special, or precede a
- ;; backslash that precedes something special. (Mainly this is
- ;; done to make using backslash on Windows systems more
- ;; natural-feeling).
- (if (eshell-looking-at-backslash-return (1+ (point)))
- (forward-char))
- (forward-char)
- "\\"))))
+ (when (eshell-looking-at-backslash-return (point))
+ (throw 'eshell-incomplete ?\\))
+ (forward-char 2) ; Move one char past the backslash.
+ ;; If the char is in a quote, backslash only has special meaning
+ ;; if it is escaping a special char.
+ (if eshell-current-quoted
+ (if (memq (char-before) eshell-special-chars-inside-quoting)
+ (list 'eshell-escape-arg (char-to-string (char-before)))
+ (concat "\\" (char-to-string (char-before))))
+ (if (memq (char-before) eshell-special-chars-outside-quoting)
+ (list 'eshell-escape-arg (char-to-string (char-before)))
+ (char-to-string (char-before))))))
(defun eshell-parse-literal-quote ()
"Parse a literally quoted string. Nothing has special meaning!"
diff --git a/test/ChangeLog b/test/ChangeLog
index 6a474e1..ff2cd60 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,11 @@
+2015-03-15 Samer Masterson <samer@samertm.com>
+
+ * automated/eshell.el (eshell-test/escape-nonspecial)
+ (eshell-test/escape-nonspecial-unicode)
+ (eshell-test/escape-nonspecial-quoted)
+ (eshell-test/escape-special-quoted): Add tests for new
+ `eshell-parse-backslash' behavior. (bug#8531)
+
2015-03-10 Jackson Ray Hamilton <jackson@jacksonrayhamilton.com>
* indent/js-indent-init-dynamic.js: Fix spelling error.
diff --git a/test/automated/eshell.el b/test/automated/eshell.el
index d51355f..81898db 100644
--- a/test/automated/eshell.el
+++ b/test/automated/eshell.el
@@ -166,6 +166,37 @@ e.g. \"{(+ 1 2)} 3\" => 3"
(eshell-command-result-p "+ 1 2; + $_ 4"
"3\n6\n")))
+(ert-deftest eshell-test/escape-nonspecial ()
+ "Test that \"\\c\" and \"c\" are equivalent when \"c\" is not a
+special character."
+ (with-temp-eshell
+ (eshell-command-result-p "echo he\\llo"
+ "hello\n")))
+
+(ert-deftest eshell-test/escape-nonspecial-unicode ()
+ "Test that \"\\c\" and \"c\" are equivalent when \"c\" is a
+unicode character (unicode characters are nonspecial by
+definition)."
+ (with-temp-eshell
+ (eshell-command-result-p "echo Vid\\éos"
+ "Vidéos\n")))
+
+(ert-deftest eshell-test/escape-nonspecial-quoted ()
+ "Test that the backslash is preserved for escaped nonspecial
+chars"
+ (with-temp-eshell
+ (eshell-command-result-p "echo \"h\\i\""
+ ;; Backslashes are doubled for regexp.
+ "h\\\\i\n")))
+
+(ert-deftest eshell-test/escape-special-quoted ()
+ "Test that the backslash is not preserved for escaped special
+chars"
+ (with-temp-eshell
+ (eshell-command-result-p "echo \"h\\\\i\""
+ ;; Backslashes are doubled for regexp.
+ "h\\\\i\n")))
+
(ert-deftest eshell-test/command-running-p ()
"Modeline should show no command running"
(with-temp-eshell
^ permalink raw reply related [flat|nested] 29+ messages in thread