Open shackra opened 4 years ago
Yes, I have noticed this too. I have resorted to removing this package. Restarting Emacs multiple times per day is no fun :(
See the original issue for this problem https://github.com/Malabarba/aggressive-indent-mode/issues/137.
The fix by @tsdh works perfectly. At the moment I'm keeping it within my .emacs
.
After the package is updated, it could be removed.
(defun aggressive-indent--indent-if-changed (buffer)
"Indent any region that changed in BUFFER in the last command loop."
(if (not (buffer-live-p buffer))
(and aggressive-indent--idle-timer
(cancel-timer aggressive-indent--idle-timer))
(with-current-buffer buffer
(when (and aggressive-indent-mode aggressive-indent--changed-list)
(save-excursion
(save-selected-window
(aggressive-indent--while-no-input
(aggressive-indent--proccess-changed-list-and-indent))))
(when (timerp aggressive-indent--idle-timer)
(cancel-timer aggressive-indent--idle-timer))))))
Same issue here. Please fix it.
I think this fix is more reliable.
(when (timerp aggressive-indent--idle-timer)
(cancel-timer aggressive-indent--idle-timer))
There is a deeper problem here: if the buffer is killed, we have no access to the timer object, which is stored in a buffer-local variable, so we can't cancel it. Right now my Emacs session have four timers created by a-i-m which respective buffers no longer exists.
To begin with, why we create a repeating timer to cancel it right away on aggressive-indent--indent-if-changed
? This seems a leftover from the past where the timer was unique and not buffer-local. So we should create a non-repeating timer, remove the cancel-timer
s from aggressive-indent--indent-if-changed
and the problem described on this issue is gone, along with the leaking timers:
@@ -461,16 +461,13 @@ If BODY finishes, `while-no-input' returns whatever value BODY produced."
(defun aggressive-indent--indent-if-changed (buffer)
"Indent any region that changed in BUFFER in the last command loop."
- (if (not (buffer-live-p buffer))
- (cancel-timer aggressive-indent--idle-timer)
+ (when (buffer-live-p buffer)
(with-current-buffer buffer
(when (and aggressive-indent-mode aggressive-indent--changed-list)
(save-excursion
(save-selected-window
(aggressive-indent--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."
@@ -479,7 +476,7 @@ If BODY finishes, `while-no-input' returns whatever value BODY produced."
(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 (current-buffer)))))
+ (run-with-idle-timer aggressive-indent-sit-for-time nil #'aggressive-indent--indent-if-changed (current-buffer)))))
(defun aggressive-indent--on-buffer-kill ()
Fixed more fully in #139, though perhaps @oscarfv's fix is preferable.
in commit 12a64b4e5c1a1e124baa74336738b6ae1972607f I'm experiencing this bug were after some hours the function
aggressive-indent--indent-if-changed
begins to fail on every point movement or key stroke, which is annoying.a workaround is just to re-start emacs.
This is my configuration related to
aggresive-indent-mode
or where I explicitly do something with the minor mode: