Fix evil change/delete operators in eshell buffers

evil-{change,delete}{,-line} now jump to the prompt before trying to
modify the buffer.
This commit is contained in:
Henrik Lissner 2018-05-26 18:55:37 +02:00
parent 4e2beb8b7e
commit 177bf2a9de
No known key found for this signature in database
GPG Key ID: 5F6C0EA160557395
2 changed files with 26 additions and 25 deletions

View File

@ -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 "<R><x><y>")
(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 "<R><x><y>")
(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 "<R><x><y>")
(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 "<R><x>")
(+eshell/evil-delete (point) end type register yank-handler))

View File

@ -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