summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2016-10-16 15:16:16 -0200
committerArtur Malabarba <bruce.connor.am@gmail.com>2016-10-16 15:16:16 -0200
commit2f54a587ce2c7fdf48a2335b6a58172b66f9a581 (patch)
treedfdca7644d65183078ff50c4a967b90dba1ff24e
parent43bce892ce71b23528ad9e318b2b6e861c5ea6be (diff)
Use an idle-timer instead of sit-for+redisplay
-rw-r--r--aggressive-indent.el23
1 files 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)