Wilfred / helpful

A better Emacs *help* buffer
1.11k stars 62 forks source link

helpful caused error `Selecting deleted buffer` #78

Open stardiviner opened 6 years ago

stardiviner commented 6 years ago

helpful-function on function move-file.

Then got "Selecting deleted buffer" in echo-area. Then I can't do [M-x] and switching buffer [C-x b] etc. They all raise this message "Selecting deleted buffer".

But I can't reproduce it in minimal Emacs init.

And I can't invoke [M-x toggle-debug-on-error] and [M-x toggle-debug-on-quit]. So can't get the backtrace.

Even I set ~debug-on-error~ variable to ~t~, still does not get backtrace.

Hope package maintainer can help me to find it out.

Wilfred commented 6 years ago

Can you use M-: when it breaks? I'd be interested to know what helpful-buffers looks like. What value have you set to helpful-max-buffers to?

Wilfred commented 6 years ago

You might also be able to force a backtrace out of Emacs by sending SIGUSR2:

$ pkill -SIGUSR2 emacs
Wilfred commented 6 years ago

Also, my Emacs doesn't have a function called move-file.

stardiviner commented 6 years ago

Can you use M-: when it breaks? I'd be interested to know what helpful-buffers looks like. What value have you set to helpful-max-buffers to?

Unable to call [M-:] too. All commands which need to use minibuffer failed. I will try to keep an ielm REPL buffer opened, then reproduce this error, then check out you mentioned variables. Update later.

stardiviner commented 6 years ago

I got the values on those variables:

ELISP> (prin1 helpful--buffers)
(0 3 . [#<buffer *helpful command: move-file*> #<buffer *helpful command: move-file*> #<buffer *helpful command: copy-file*> nil nil])
(0 3 .
   [#<buffer *helpful command: move-file*> #<buffer *helpful command: move-file*> #<buffer *helpful command: copy-file*> nil nil])

ELISP> (print helpful-max-buffers)

5

5 (#o5, #x5, ?\C-e)
ELISP> 

And now I reproduce on helpful-function on move-file (which defined by myself) twice, then helpful-function on copy-file. Then triggered this error. helpful did popup an buffer helpful command: copy-file*, but the buffer is empty. Then I run upper variables checking. Then I run kill -s SIGUSR2 emacs, it only shows Quit in echo-area. can't trigger backtrace output.

In those variables' value. I found nil, guess that why?

Wilfred commented 6 years ago

Aha, I suspect I know what's happening. Helpful has killed your minibuffer.

If you call (kill-buffer nil), Emacs kills the current buffer. Somehow we're doing that in helpful--buffer, presumably because of the duplicate in helpful--buffers.

Wilfred commented 6 years ago

OK, I've had another look at this, and I'm stumped. I can't see anywhere where we call (kill-buffer nil) and I can't reproduce the issue.

Could you configure Emacs to open a debugger when it tries to kill the minibuffer? This should do the trick:

(defun wh/check-is-minibuffer ()
  (if (minibufferp (current-buffer))
      (progn
        (debug)
        nil)
    t))

(add-to-list 'kill-buffer-query-functions #'wh/check-is-minibuffer)

This should also prevent your minibuffer getting killed, which is a Good Thing :)

Hopefully, this should give you a backtrace, which should help us see what is going wrong.

stardiviner commented 6 years ago

It does not popup stack trace. Still nothing. I guess I have to do a "bisect init files" to find out the reason now. It will take a long time on my lots of init files.

stardiviner commented 6 years ago

After a bisecting init files. Sometimes it has this error. sometimes not. And I can't locate the place which caused this issue. That's sad.

Wilfred commented 6 years ago

Have you tried https://github.com/Malabarba/elisp-bug-hunter ? That can really speed up bisecting an init file.

stardiviner commented 6 years ago

After tried bug-hunter. It did help me solved some other bugs which live for a long time. And about this issue, I got new infomation:

Table of Contents

When I try to exit Emacs, I got the following error. Seems flycheck is trying to delete a temporary flycheck buffer or file.

Debugger entered--Lisp error: (error "Selecting deleted buffer")
  flycheck-global-teardown()
  kill-emacs()
  save-buffers-kill-emacs(nil)
  save-buffers-kill-terminal(nil)
  funcall-interactively(save-buffers-kill-terminal nil)
  call-interactively(save-buffers-kill-terminal nil nil)
  #f(compiled-function (cmd &optional record-flag keys special) "Execute CMD as an editor command.\nCMD must be a symbol that satisfies the `commandp' predicate.\nOptional second arg RECORD-FLAG non-nil\nmeans unconditionally put this command in the variable `command-history'.\nOtherwise, that is done only if an arg is read using the minibuffer.\nThe argument KEYS specifies the value to use instead of (this-command-keys)\nwhen reading the arguments; if it is nil, (this-command-keys) is used.\nThe argument SPECIAL, if non-nil, means that this command is executing\na special event, so ignore the prefix argument and don't clear it." #<bytecode 0x24dfef>)(save-buffers-kill-terminal nil nil nil)
  ad-Advice-command-execute(#f(compiled-function (cmd &optional record-flag keys special) "Execute CMD as an editor command.\nCMD must be a symbol that satisfies the `commandp' predicate.\nOptional second arg RECORD-FLAG non-nil\nmeans unconditionally put this command in the variable `command-history'.\nOtherwise, that is done only if an arg is read using the minibuffer.\nThe argument KEYS specifies the value to use instead of (this-command-keys)\nwhen reading the arguments; if it is nil, (this-command-keys) is used.\nThe argument SPECIAL, if non-nil, means that this command is executing\na special event, so ignore the prefix argument and don't clear it." #<bytecode 0x24dfef>) save-buffers-kill-terminal)
  apply(ad-Advice-command-execute #f(compiled-function (cmd &optional record-flag keys special) "Execute CMD as an editor command.\nCMD must be a symbol that satisfies the `commandp' predicate.\nOptional second arg RECORD-FLAG non-nil\nmeans unconditionally put this command in the variable `command-history'.\nOtherwise, that is done only if an arg is read using the minibuffer.\nThe argument KEYS specifies the value to use instead of (this-command-keys)\nwhen reading the arguments; if it is nil, (this-command-keys) is used.\nThe argument SPECIAL, if non-nil, means that this command is executing\na special event, so ignore the prefix argument and don't clear it." #<bytecode 0x24dfef>) save-buffers-kill-terminal)
  command-execute(save-buffers-kill-terminal)
simendsjo commented 6 years ago

I just tried Helpful, but I'm getting the same behavior. I can just call helpful-at-point, and I get into this state quite often and need to quit Emacs. Any update on this bug? Afraid I'm unable to help debug it as I don't know any emacs/elisp.

Wilfred commented 6 years ago

@simendsjo could you try M-x toggle-debug-on-error and paste the backtrace you get?

Also, is your emacs configuration available anywhere for me to try?

Hopefully with another user experiencing this we can find the cause :)