Subject: Re: bug#8531: 24.0.50;

From: samer <[email-masked]>
Date: Mon, 08 Dec 2014 01:34:12 -0800

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!"