Skip to content

Commit

Permalink
Pause hooks and undos during blockwise (bulk) insert
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdl89 committed Jun 16, 2024
1 parent e72562f commit 7bfdb13
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
1 change: 1 addition & 0 deletions evil-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -2684,6 +2684,7 @@ lines. This is the default behaviour for Visual-state insertion."
(when (memq (evil-visual-type) '(line block))
(1+ (evil-count-lines evil-visual-point evil-visual-mark)))
t)))
(and evil-want-fine-undo vcount (evil-start-undo-step))
(if (and (evil-visual-state-p) (eq (evil-visual-type) 'line))
(evil-insert-line count vcount)
(setq evil-insert-count count
Expand Down
36 changes: 23 additions & 13 deletions evil-states.el
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ commands opening a new line."
(remove-hook 'pre-command-hook #'evil-insert-repeat-hook))
(put 'evil-insert-repeat-hook 'permanent-local-hook t)

(eval-when-compile
;; TODO remove this once support for emacs 26 is dropped
(unless (fboundp 'combine-change-calls)
(defmacro combine-change-calls (_beg _end &rest body) `(progn ,@body))))
(declare-function evil-execute-repeat-info "evil-repeat")
(defun evil-cleanup-insert-state ()
"Called when Insert or Replace state is about to be exited.
Expand All @@ -158,19 +162,25 @@ Handles the repeat-count of the insertion command."
buffer-invisibility-spec)))
(cl-destructuring-bind (line col vcount) evil-insert-vcount
(save-excursion
(dotimes (v (1- vcount))
(goto-char (point-min))
(forward-line (+ line v))
(when (or (not evil-insert-skip-empty-lines)
(not (integerp col))
(save-excursion
(evil-move-end-of-line)
(>= (current-column) col)))
(if (integerp col)
(move-to-column col t)
(funcall col))
(dotimes (_ (or evil-insert-count 1))
(evil-execute-repeat-info (cdr evil-insert-repeat-info))))))))))
(combine-change-calls ; For performance
(progn (goto-line line) (line-beginning-position))
(line-end-position vcount)
(let (pre-command-hook post-command-hook) ; For performance
(dotimes (v (1- vcount))
(goto-char (point-min))
(forward-line (+ line v))
(when (or (not evil-insert-skip-empty-lines)
(not (integerp col))
(save-excursion
(evil-move-end-of-line)
(>= (current-column) col)))
(if (integerp col)
(move-to-column col t)
(funcall col))
(dotimes (_ (or evil-insert-count 1))
(evil-execute-repeat-info (cdr evil-insert-repeat-info))))))
(run-hooks 'post-command-hook))))))
(and evil-want-fine-undo (evil-end-undo-step)))

;;; Visual state

Expand Down

0 comments on commit 7bfdb13

Please sign in to comment.