From 7bfdb135882495ab7528b87c121ddafc3640d60e Mon Sep 17 00:00:00 2001 From: Tom Dalziel Date: Sun, 16 Jun 2024 18:09:50 +0200 Subject: Pause hooks and undos during blockwise (bulk) insert --- evil-commands.el | 1 + evil-states.el | 36 +++++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/evil-commands.el b/evil-commands.el index e4fe002..a75bead 100644 --- a/evil-commands.el +++ b/evil-commands.el @@ -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 diff --git a/evil-states.el b/evil-states.el index 26eb844..6f3a2c0 100644 --- a/evil-states.el +++ b/evil-states.el @@ -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. @@ -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 -- cgit v1.0