aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Porter2024-01-28 15:49:03 -0800
committerJim Porter2024-01-28 15:54:46 -0800
commit1f5a13d5843306af2e6a74fbdfd6d00af8804a23 (patch)
tree7ab1a6ba1a4fbd6e27b4e64e23a861b467481ccb
parente734f8e502e315441214936e89ecd1e11e981fca (diff)
downloademacs-1f5a13d5843306af2e6a74fbdfd6d00af8804a23.tar.gz
emacs-1f5a13d5843306af2e6a74fbdfd6d00af8804a23.zip
In Eshell, allow an escaped newline at the end of a command
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.
-rw-r--r--lisp/eshell/esh-arg.el5
-rw-r--r--test/lisp/eshell/esh-arg-tests.el14
2 files changed, 11 insertions, 8 deletions
diff --git a/lisp/eshell/esh-arg.el b/lisp/eshell/esh-arg.el
index 1880cc03885..97ddac58629 100644
--- a/lisp/eshell/esh-arg.el
+++ b/lisp/eshell/esh-arg.el
@@ -440,6 +440,7 @@ Point is left at the end of the arguments."
440 440
441(defsubst eshell-looking-at-backslash-return (pos) 441(defsubst eshell-looking-at-backslash-return (pos)
442 "Test whether a backslash-return sequence occurs at POS." 442 "Test whether a backslash-return sequence occurs at POS."
443 (declare (obsolete nil "30.1"))
443 (and (eq (char-after pos) ?\\) 444 (and (eq (char-after pos) ?\\)
444 (or (= (1+ pos) (point-max)) 445 (or (= (1+ pos) (point-max))
445 (and (eq (char-after (1+ pos)) ?\n) 446 (and (eq (char-after (1+ pos)) ?\n)
@@ -464,8 +465,8 @@ backslash is ignored and the character after is returned. If the
464backslash is in a quoted string, the backslash and the character 465backslash is in a quoted string, the backslash and the character
465after are both returned." 466after are both returned."
466 (when (eq (char-after) ?\\) 467 (when (eq (char-after) ?\\)
467 (when (eshell-looking-at-backslash-return (point)) 468 (when (= (1+ (point)) (point-max))
468 (throw 'eshell-incomplete "\\")) 469 (throw 'eshell-incomplete "\\"))
469 (forward-char 2) ; Move one char past the backslash. 470 (forward-char 2) ; Move one char past the backslash.
470 (let ((special-chars (if eshell-current-quoted 471 (let ((special-chars (if eshell-current-quoted
471 eshell-special-chars-inside-quoting 472 eshell-special-chars-inside-quoting
diff --git a/test/lisp/eshell/esh-arg-tests.el b/test/lisp/eshell/esh-arg-tests.el
index b626cf10bf1..b748c5ab4c0 100644
--- a/test/lisp/eshell/esh-arg-tests.el
+++ b/test/lisp/eshell/esh-arg-tests.el
@@ -60,13 +60,17 @@ chars."
60 "he\\\\llo\n"))) 60 "he\\\\llo\n")))
61 61
62(ert-deftest esh-arg-test/escape/newline () 62(ert-deftest esh-arg-test/escape/newline ()
63 "Test that an escaped newline is equivalent to the empty string. 63 "Test that an escaped newline is equivalent to the empty string."
64When newlines are *nonspecial*, an escaped newline should be
65treated as just a newline."
66 (with-temp-eshell 64 (with-temp-eshell
67 (eshell-match-command-output "echo hi\\\nthere" 65 (eshell-match-command-output "echo hi\\\nthere"
68 "hithere\n"))) 66 "hithere\n")))
69 67
68(ert-deftest esh-arg-test/escape/trailing-newline ()
69 "Test that an escaped newline is equivalent to the empty string."
70 (with-temp-eshell
71 (eshell-match-command-output "echo hi\\\n"
72 "hi\n")))
73
70(ert-deftest esh-arg-test/escape/newline-conditional () 74(ert-deftest esh-arg-test/escape/newline-conditional ()
71 "Test invocation of an if/else statement using line continuations." 75 "Test invocation of an if/else statement using line continuations."
72 (let ((eshell-test-value t)) 76 (let ((eshell-test-value t))
@@ -95,9 +99,7 @@ chars."
95 "\\\"hi\\\\\n"))) 99 "\\\"hi\\\\\n")))
96 100
97(ert-deftest esh-arg-test/escape-quoted/newline () 101(ert-deftest esh-arg-test/escape-quoted/newline ()
98 "Test that an escaped newline is equivalent to the empty string. 102 "Test that an escaped newline is equivalent to the empty string."
99When newlines are *nonspecial*, an escaped newline should be
100treated literally, as a backslash and a newline."
101 (with-temp-eshell 103 (with-temp-eshell
102 (eshell-match-command-output "echo \"hi\\\nthere\"" 104 (eshell-match-command-output "echo \"hi\\\nthere\""
103 "hithere\n"))) 105 "hithere\n")))