]> git.eshelyaron.com Git - emacs.git/commitdiff
In Eshell, allow an escaped newline at the end of a command
authorJim Porter <jporterbugs@gmail.com>
Sun, 28 Jan 2024 23:49:03 +0000 (15:49 -0800)
committerEshel Yaron <me@eshelyaron.com>
Wed, 31 Jan 2024 20:15:23 +0000 (21:15 +0100)
Normally, "echo<RET>" runs the command "echo".  Likewise,
"echo\<RET><RET>" should too: we escape the first newline, and then
the second one is unescaped and should send the command input to
Eshell.  Previously, you had to press RET a third time, but now it
works as expected.

* lisp/eshell/esh-arg.el (eshell-looking-at-backslash-return): Make
obsolete.
(eshell-parse-backslash): A backslash sequence is only incomplete if
there's nothing at all after it.

* test/lisp/eshell/esh-arg-tests.el (esh-arg-test/escape/newline)
(esh-arg-test/escape-quoted/newline): Remove inaccurate comment;
escaped newlines are always special.
(esh-arg-test/escape/trailing-newline): New test.

(cherry picked from commit 1f5a13d5843306af2e6a74fbdfd6d00af8804a23)

lisp/eshell/esh-arg.el
test/lisp/eshell/esh-arg-tests.el

index 1880cc038854563665689fef5e97ce2fe1084e12..97ddac58629960675ff8029a06758dd87630f91d 100644 (file)
@@ -440,6 +440,7 @@ Point is left at the end of the arguments."
 
 (defsubst eshell-looking-at-backslash-return (pos)
   "Test whether a backslash-return sequence occurs at POS."
+  (declare (obsolete nil "30.1"))
   (and (eq (char-after pos) ?\\)
        (or (= (1+ pos) (point-max))
           (and (eq (char-after (1+ pos)) ?\n)
@@ -464,8 +465,8 @@ 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) ?\\)
-    (when (eshell-looking-at-backslash-return (point))
-        (throw 'eshell-incomplete "\\"))
+    (when (= (1+ (point)) (point-max))
+      (throw 'eshell-incomplete "\\"))
     (forward-char 2) ; Move one char past the backslash.
     (let ((special-chars (if eshell-current-quoted
                              eshell-special-chars-inside-quoting
index b626cf10bf137b9a42b38c5b62a702a0e099f8c0..b748c5ab4c0d28117cab96d0f75d4580ae94d4c3 100644 (file)
@@ -60,13 +60,17 @@ chars."
                                 "he\\\\llo\n")))
 
 (ert-deftest esh-arg-test/escape/newline ()
-  "Test that an escaped newline is equivalent to the empty string.
-When newlines are *nonspecial*, an escaped newline should be
-treated as just a newline."
+  "Test that an escaped newline is equivalent to the empty string."
   (with-temp-eshell
    (eshell-match-command-output "echo hi\\\nthere"
                                 "hithere\n")))
 
+(ert-deftest esh-arg-test/escape/trailing-newline ()
+  "Test that an escaped newline is equivalent to the empty string."
+  (with-temp-eshell
+   (eshell-match-command-output "echo hi\\\n"
+                                "hi\n")))
+
 (ert-deftest esh-arg-test/escape/newline-conditional ()
   "Test invocation of an if/else statement using line continuations."
   (let ((eshell-test-value t))
@@ -95,9 +99,7 @@ chars."
                                 "\\\"hi\\\\\n")))
 
 (ert-deftest esh-arg-test/escape-quoted/newline ()
-  "Test that an escaped newline is equivalent to the empty string.
-When newlines are *nonspecial*, an escaped newline should be
-treated literally, as a backslash and a newline."
+  "Test that an escaped newline is equivalent to the empty string."
   (with-temp-eshell
    (eshell-match-command-output "echo \"hi\\\nthere\""
                                 "hithere\n")))