From 177bf2a9de5aa5d0a1686c23f7094ecdaa4a9a82 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 26 May 2018 18:55:37 +0200 Subject: [PATCH] Fix evil change/delete operators in eshell buffers evil-{change,delete}{,-line} now jump to the prompt before trying to modify the buffer. --- modules/tools/eshell/autoload/evil.el | 49 +++++++++++++-------------- modules/tools/eshell/config.el | 2 ++ 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/modules/tools/eshell/autoload/evil.el b/modules/tools/eshell/autoload/evil.el index 79a2df1bd..6e9ac223e 100644 --- a/modules/tools/eshell/autoload/evil.el +++ b/modules/tools/eshell/autoload/evil.el @@ -13,34 +13,33 @@ (evil-define-operator +eshell/evil-change (beg end type register yank-handler delete-func) "Like `evil-change' but will not delete/copy the prompt." (interactive "") - (let ((delete-func (or delete-func #'evil-delete)) - (nlines (1+ (evil-count-lines beg end)))) - (unless (eq evil-want-fine-undo t) - (evil-start-undo-step)) - (when (get-text-property beg 'read-only) - (save-excursion - (goto-char beg) - (evil-collection-eshell-next-prompt) - (setq beg (point)))) - (funcall delete-func beg end type register yank-handler) - (cond - ((eq type 'line) - (goto-char eshell-last-output-end) - (when (get-text-property (point) 'read-only) - (evil-collection-eshell-next-prompt)) - (evil-append 1)) - ((eq type 'block) (evil-insert 1 nlines)) - (t - (evil-insert 1))))) + (save-restriction + (narrow-to-region eshell-last-output-end (point-max)) + (evil-change (max beg (point-min)) + (if (eq type 'line) (point-max) (min (or end (point-max)) (point-max))) + type register yank-handler delete-func))) ;;;###autoload (autoload '+eshell/evil-change-line "tools/eshell/autoload/evil" nil t) (evil-define-operator +eshell/evil-change-line (beg end type register yank-handler) "Change to end of line." :motion evil-end-of-line (interactive "") - (when (get-text-property beg 'read-only) - (save-excursion - (goto-char beg) - (evil-collection-eshell-next-prompt) - (setq beg (point)))) - (evil-change beg end type register yank-handler #'evil-delete-line)) + (+eshell/evil-change beg end type register yank-handler #'evil-delete-line)) + +;;;###autoload (autoload '+eshell/evil-delete "tools/eshell/autoload/evil" nil t) +(evil-define-operator +eshell/evil-delete (beg end type register yank-handler) + "Like `evil-delete' but will not delete/copy the prompt." + (interactive "") + (save-restriction + (narrow-to-region eshell-last-output-end (point-max)) + (evil-delete (if beg (max beg (point-min)) (point-min)) + (if (eq type 'line) (point-max) (min (or end (point-max)) (point-max))) + type register yank-handler))) + +;;;###autoload (autoload '+eshell/evil-delete-line "tools/eshell/autoload/evil" nil t) +(evil-define-operator +eshell/evil-delete-line (_beg end type register yank-handler) + "Change to end of line." + :motion nil + :keep-visual t + (interactive "") + (+eshell/evil-delete (point) end type register yank-handler)) diff --git a/modules/tools/eshell/config.el b/modules/tools/eshell/config.el index 75870835a..b6708a5f7 100644 --- a/modules/tools/eshell/config.el +++ b/modules/tools/eshell/config.el @@ -50,6 +50,8 @@ redefines its keys every time `eshell-mode' is enabled." (map! :map eshell-mode-map :n "c" #'+eshell/evil-change :n "C" #'+eshell/evil-change-line + :n "d" #'+eshell/evil-delete + :n "D" #'+eshell/evil-delete-line :i "C-d" #'+eshell/quit-or-delete-char :i "C-p" #'eshell-previous-input :i "C-n" #'eshell-next-input