Skip to content

Commit

Permalink
Make the idle timer not be buffer local
Browse files Browse the repository at this point in the history
Desperate attempt to resolve #112
  • Loading branch information
Malabarba committed Oct 18, 2018
1 parent 8e70039 commit cc8da01
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions aggressive-indent.el
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ 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
(defvar aggressive-indent--idle-timer nil
"Idle timer used for indentation")

(defun aggressive-indent--indent-if-changed ()
Expand All @@ -421,18 +421,15 @@ typing, try tweaking this number."
(save-excursion
(save-selected-window
(while-no-input
(aggressive-indent--proccess-changed-list-and-indent))))
(when (timerp aggressive-indent--idle-timer)
(cancel-timer aggressive-indent--idle-timer))))
(aggressive-indent--proccess-changed-list-and-indent))))))

(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)
(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))))
(unless (timerp 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
Expand Down Expand Up @@ -465,7 +462,8 @@ typing, try tweaking this number."
(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))
(cancel-timer aggressive-indent--idle-timer)
(setq aggressive-indent--idle-timer nil))
(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--softly-indent-defun 'local)))
Expand Down

0 comments on commit cc8da01

Please sign in to comment.