Skip to content

Commit

Permalink
Improve performance of :global and :normal
Browse files Browse the repository at this point in the history
Use combine-change-calls and temporarily nillify pre- and post- command hooks to
improve performance
  • Loading branch information
tomdl89 committed Jun 27, 2024
1 parent 0347d79 commit 8a6ad91
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
22 changes: 13 additions & 9 deletions evil-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -4247,10 +4247,12 @@ Use `evil-flush-lines' if INVERT is nil, or `evil-keep-lines' if not."
(setq markers (nreverse markers))
(unwind-protect
(evil-with-single-undo
(let ((evil--ex-global-active-p t))
(dolist (marker markers)
(goto-char marker)
(eval command-form t))))
(combine-change-calls (point-min) (point-max)
(let ((evil--ex-global-active-p t)
pre-command-hook post-command-hook)
(dolist (marker markers)
(goto-char marker)
(eval command-form t)))))
;; ensure that all markers are deleted afterwards,
;; even in the event of failure
(dolist (marker markers)
Expand Down Expand Up @@ -4287,11 +4289,13 @@ range. The given argument is passed straight to
(deactivate-mark)
(evil-force-normal-state)
(evil-with-single-undo
(dolist (marker markers)
(goto-char marker)
(ignore-errors (execute-kbd-macro commands))
(evil-force-normal-state)
(set-marker marker nil)))))
(combine-change-calls beg end
(let (pre-command-hook post-command-hook)
(dolist (marker markers)
(goto-char marker)
(ignore-errors (execute-kbd-macro commands))
(evil-force-normal-state)
(set-marker marker nil)))))))

(evil-define-motion evil-goto-char (position)
"Go to POSITION in the buffer.
Expand Down
6 changes: 6 additions & 0 deletions evil-common.el
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ the buffer-local value of HOOK is modified."
(declare (obsolete evil-with-delay "1.15.0") (indent 2))
(eval `(evil-with-delay ,condition (,hook ,append ,local ,name) ,form) t))

;; Used to improve performance in macros, :global, and other batch edits
;; TODO remove this once support for emacs 26 is dropped
(eval-when-compile
(unless (fboundp 'combine-change-calls)
(defmacro combine-change-calls (_beg _end &rest body) `(progn ,@body))))

;;; List functions

(defmacro evil--add-to-alist (alist &rest elements)
Expand Down
4 changes: 0 additions & 4 deletions evil-states.el
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,6 @@ 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 Down

0 comments on commit 8a6ad91

Please sign in to comment.