From e1e0bce5b3a2fcdaf966e450d86a2fb4b22376a7 Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Wed, 11 Oct 2023 11:38:27 -0700 Subject: [PATCH] Fix behavior of Eshell prompt when yanking output into it * lisp/eshell/esh-util.el (eshell--unmark-string-as-output): New function... * lisp/eshell/esh-mode.el (eshell-mode): ... use it. * test/lisp/eshell/eshell-tests.el (eshell-test/yank-output): New test (bug#66469). --- lisp/eshell/esh-mode.el | 3 +++ lisp/eshell/esh-util.el | 8 ++++++++ test/lisp/eshell/eshell-tests.el | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/lisp/eshell/esh-mode.el b/lisp/eshell/esh-mode.el index 2b560afb92c..9d2cd1e67eb 100644 --- a/lisp/eshell/esh-mode.el +++ b/lisp/eshell/esh-mode.el @@ -361,6 +361,9 @@ eshell-mode (setq-local eshell-last-output-end (point-marker)) (setq-local eshell-last-output-block-begin (point)) + (add-function :filter-return (local 'filter-buffer-substring-function) + #'eshell--unmark-string-as-output) + (let ((modules-list (copy-sequence eshell-modules-list))) (setq-local eshell-modules-list modules-list)) diff --git a/lisp/eshell/esh-util.el b/lisp/eshell/esh-util.el index 4c251a29269..ca2f775318a 100644 --- a/lisp/eshell/esh-util.el +++ b/lisp/eshell/esh-util.el @@ -234,6 +234,14 @@ eshell--mark-yanked-as-output (eshell--mark-as-output start1 end1))))) (add-hook 'after-change-functions hook nil t))) +(defun eshell--unmark-string-as-output (string) + "Unmark STRING as Eshell output." + (remove-list-of-text-properties + 0 (length string) + '(rear-nonsticky front-sticky field insert-in-front-hooks) + string) + string) + (defun eshell-find-delimiter (open close &optional bound reverse-p backslash-p) "From point, find the CLOSE delimiter corresponding to OPEN. diff --git a/test/lisp/eshell/eshell-tests.el b/test/lisp/eshell/eshell-tests.el index b02e5fca592..d2ef44ae507 100644 --- a/test/lisp/eshell/eshell-tests.el +++ b/test/lisp/eshell/eshell-tests.el @@ -195,6 +195,25 @@ eshell-test/get-old-input/run-output (eshell-send-input) (eshell-match-output "(\"hello\" \"there\")"))) +(ert-deftest eshell-test/yank-output () + "Test that yanking a line of output into the next prompt works (bug#66469)." + (with-temp-eshell + (eshell-insert-command "echo hello") + ;; Go to the output and kill the line of text. + (forward-line -1) + (kill-line) + ;; Go to the last prompt and yank the previous output. + (goto-char (point-max)) + (yank) + ;; Go to the beginning of the prompt and add some text. + (move-beginning-of-line 1) + (insert-and-inherit "echo ") + ;; Make sure when we go to the beginning of the line, we go to the + ;; right spot (before the "echo"). + (move-end-of-line 1) + (move-beginning-of-line 1) + (should (looking-at "echo hello")))) + (provide 'eshell-tests) ;;; eshell-tests.el ends here -- 2.25.1