branch: externals/aggressive-indent
commit 2f54a587ce2c7fdf48a2335b6a58172b66f9a581
Author: Artur Malabarba <[email protected]>
Commit: Artur Malabarba <[email protected]>
Use an idle-timer instead of sit-for+redisplay
---
aggressive-indent.el | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/aggressive-indent.el b/aggressive-indent.el
index df04cb9..9679e92 100644
--- a/aggressive-indent.el
+++ b/aggressive-indent.el
@@ -417,22 +417,29 @@ If you feel aggressive-indent is causing Emacs to hang
while
typing, try tweaking this number."
:type 'float)
+(defvar-local aggressive-indent--idle-timer nil
+ "Idle timer used for indentation")
+
(defun aggressive-indent--indent-if-changed ()
"Indent any region that changed in the last command loop."
- (when aggressive-indent--changed-list
+ (when (and aggressive-indent-mode aggressive-indent--changed-list)
(save-excursion
(save-selected-window
(unless (or (run-hook-wrapped
'aggressive-indent--internal-dont-indent-if #'eval)
(aggressive-indent--run-user-hooks))
(while-no-input
- (sit-for aggressive-indent-sit-for-time t)
- (redisplay)
- (aggressive-indent--proccess-changed-list-and-indent)))))))
+ (aggressive-indent--proccess-changed-list-and-indent)))))
+ (when (timerp aggressive-indent--idle-timer)
+ (cancel-timer aggressive-indent--idle-timer))))
(defun aggressive-indent--keep-track-of-changes (l r &rest _)
"Store the limits (L and R) of each change in the buffer."
(when aggressive-indent-mode
- (push (list l r) aggressive-indent--changed-list)))
+ (push (list l r) aggressive-indent--changed-list)
+ (when (timerp aggressive-indent--idle-timer)
+ (cancel-timer aggressive-indent--idle-timer))
+ (setq aggressive-indent--idle-timer
+ (run-with-idle-timer aggressive-indent-sit-for-time t
#'aggressive-indent--indent-if-changed))))
;;; Minor modes
;;;###autoload
@@ -460,12 +467,12 @@ typing, try tweaking this number."
(aggressive-indent--local-electric nil)
(aggressive-indent--local-electric t))
(add-hook 'after-change-functions
#'aggressive-indent--keep-track-of-changes nil 'local)
- (add-hook 'before-save-hook
#'aggressive-indent--proccess-changed-list-and-indent nil 'local)
- (add-hook 'post-command-hook #'aggressive-indent--indent-if-changed
nil 'local))
+ (add-hook 'before-save-hook
#'aggressive-indent--proccess-changed-list-and-indent nil 'local))
;; Clean the hooks
+ (when (timerp aggressive-indent--idle-timer)
+ (cancel-timer aggressive-indent--idle-timer))
(remove-hook 'after-change-functions
#'aggressive-indent--keep-track-of-changes 'local)
(remove-hook 'before-save-hook
#'aggressive-indent--proccess-changed-list-and-indent 'local)
- (remove-hook 'post-command-hook #'aggressive-indent--indent-if-changed
'local)
(remove-hook 'post-command-hook #'aggressive-indent--softly-indent-defun
'local)))
(defun aggressive-indent--local-electric (on)