Malabarba / aggressive-indent-mode

Emacs minor mode that keeps your code always indented. More reliable than electric-indent-mode.
850 stars 36 forks source link

Error running timer ‘aggressive-indent--indent-if-changed’: (error "Selecting deleted buffer") #137

Closed tsdh closed 4 years ago

tsdh commented 4 years ago

Since the update to the latest MELPA version 20200421.1149, I frequently get the error in the subject. I think the problem is that you use with-current-buffer and inside that, you then check if the buffer is live. I guess you need to do it the other way round. The following version works for me:

(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))))))
rprimus commented 4 years ago

Thu Apr 23 13:39:50 BST 2020

Further to the above, this error continuously shows up in the minibuffer - making it effectively useless.

Just wondering why turning off aggressive-indent-mode has no effect on the generation of the error?

(With AIM off, both aggressive-indent-mode and aggressive-indent--changed-list are nil.)

tsdh commented 4 years ago

@rprimus The error stays because the code trying to select a deleted buffer (which causes the error) is run from a timer and fails to cancel the timer for exactly that reason.

Malabarba commented 4 years ago

Odd that I didn't get that at all. Anyway, I agree with the fix and pushed a change. Sorry for the trouble, Tassilo.

mkaschenko commented 4 years ago

@Malabarba This error appears to me when I close buffers within *Ibuffer* window, for example.

chasecaleb commented 4 years ago

I hate to be the bearer of bad news... but this is still broken as of current master (12a64b4e5c1a1e124baa74336738b6ae1972607f)

Here's a backtrace. I omitted some of it due to being extremely long plus containing some personal info, e.g. buffer names, but it should be useful still:

Debugger entered--Lisp error: (wrong-type-argument timerp nil)
  signal(wrong-type-argument (timerp nil))
  cancel-timer(nil)
  aggressive-indent--indent-if-changed(#<killed buffer>)
  apply(aggressive-indent--indent-if-changed #<killed buffer>)
  timer-event-handler([t 0 0 50000 t aggressive-indent--indent-if-changed (#<killed buffer>) idle 0])
  read-from-minibuffer(...<omitted>...)
  <...omitted...>
tsdh commented 4 years ago

@chasecaleb @Malabarba That's why I've had

(and aggressive-indent--idle-timer
     (cancel-timer aggressive-indent--idle-timer)

in my fix. :-)