1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Ensure that Eshell users can run lines of command output as input

Previously, this failed to work properly because any additional input
the user entered would have no 'field' property, confusing
'eshell-get-old-input'.  To fix this, we simply ensure that any
user-entered text in the output field retains said output field
(bug#61310).

* lisp/eshell/esh-util.el (eshell-command-output-properties): New
variable.
(eshell--mark-as-output, eshell--mark-yanked-as-output): New
functions, mostly copied from comint.

* lisp/eshell/esh-proc.el (eshell-interactive-process-filter):
* lisp/eshell/esh-mode.el (eshell-interactive-print): Call
'eshell--mark-as-output'.
(eshell-get-old-input): Remove properties from the returned string
just to be safe.

* test/lisp/eshell/eshell-tests.el (eshell-test-value): New variable.
(eshell-test/get-old-input/rerun-command)
(eshell-test/get-old-input/run-output): New tests.

* test/lisp/eshell/em-prompt-tests.el
(em-prompt-test/field-properties)
(em-prompt-test/field-properties/no-highlight): Use
'eshell-command-output-properties'.
This commit is contained in:
Jim Porter 2023-02-05 21:37:08 -08:00
parent c53255f677
commit ab7c2f8092
5 changed files with 70 additions and 11 deletions

View file

@ -34,6 +34,8 @@
(file-name-directory (or load-file-name
default-directory))))
(defvar eshell-test-value nil)
;;; Tests:
(ert-deftest eshell-test/pipe-headproc ()
@ -160,6 +162,32 @@ insert the queued one at the next prompt, and finally run it."
(beginning-of-line))
(should (string= (eshell-get-old-input) "echo alpha"))))
(ert-deftest eshell-test/get-old-input/rerun-command ()
"Test that we can rerun an old command when point is on it."
(with-temp-eshell
(let ((eshell-test-value "first"))
(eshell-match-command-output "echo $eshell-test-value" "first"))
;; Go to the previous prompt.
(forward-line -2)
(let ((inhibit-field-text-motion t))
(end-of-line))
;; Rerun the command, but with a different variable value.
(let ((eshell-test-value "second"))
(eshell-send-input))
(eshell-match-output "second")))
(ert-deftest eshell-test/get-old-input/run-output ()
"Test that we can run a line of output as a command when point is on it."
(with-temp-eshell
(eshell-match-command-output "echo \"echo there\"" "echo there")
;; Go to the output, and insert "hello" after "echo".
(forward-line -1)
(forward-word)
(insert " hello")
;; Run the line as a command.
(eshell-send-input)
(eshell-match-output "(\"hello\" \"there\")")))
(provide 'eshell-tests)
;;; eshell-tests.el ends here