From: Jim Porter Date: Wed, 11 Oct 2023 18:38:27 +0000 (-0700) Subject: Fix behavior of Eshell prompt when yanking output into it X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=60f695285331dcf723dc9ce69c8bffc3b3d606c9;p=emacs.git 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). --- 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 @@ and the hook `eshell-exit-hook'." (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 @@ current buffer." (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 @@ insert the queued one at the next prompt, and finally run it." (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