Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't yes-or-no-p query the user when killing plz process buffers #52

Closed
wants to merge 1 commit into from
Closed

Conversation

mkcms
Copy link
Contributor

@mkcms mkcms commented May 23, 2024

The current behavior when interrupting a sync request by C-g or in other way, externally - e.g. with with-timeout, Emacs unexpectedly asks if I really want to kill the curl process buffer.
E.g. when interrupting this long-running request with C-g:

(plz 'get "http://httpbin.org/delay/10")

Emacs asks if I want to really kill the curl buffer. This is unexpected, as the library itself should never be interactive.
It even does this in --batch mode, which I caught here: https://github.com/mkcms/compiler-explorer.el/actions/runs/9200670124/job/25307608066#step:6:148

I have signed the FSF papers a couple of years ago and already contributed to Emacs, so this is good to go.

@alphapapa
Copy link
Owner

Hi Michał,

Ah, this is great! I just had this happen to me yesterday when I was testing something while pressing C-g. I hadn't thought about this variable.

What do you think about using defsubst or define-inline for plz--kill-buffer? It would seem reasonable to me, to avoid an extra function call.

Thanks for submitting this!

cc: @josephmturner

@alphapapa alphapapa self-assigned this May 24, 2024
@alphapapa alphapapa added the bug Something isn't working label May 24, 2024
@alphapapa alphapapa added this to the v0.9 milestone May 24, 2024
@josephmturner
Copy link
Contributor

josephmturner commented May 24, 2024

Thank you @mkcms! I wonder if it might be more appropriate to temporarily bind kill-buffer-query-functions to (cl-callf2 remq 'process-kill-buffer-query-function kill-buffer-query-functions) instead of nil. OTOH, remq would allow for greater flexibility. OTOH, kill-buffer-query-functions is not a defcustom, so customizability might not be important in this case.

@mkcms
Copy link
Contributor Author

mkcms commented May 24, 2024

@josephmturner

I wonder if it might be more appropriate to temporarily bind kill-buffer-query-functions to (cl-callf2 remq 'process-kill-buffer-query-function kill-buffer-query-functions) instead of nil

There's no need, because we actually do want to unconditionally kill the buffer. So we don't want any query. If another user function, apart from process-kill-buffer-query-function remains in there, and actually prevents the buffer from being killed (or just also asks us for confirmation), that won't really fix the problem.

@alphapapa

What do you think about using defsubst or define-inline for plz--kill-buffer? It would seem reasonable to me, to avoid an extra function call.

Sure, I can change that if you want, but I get this warning:

Warning: Optimization failure for plz--kill-buffer: Handler: plz--kill-buffer--inliner
(wrong-type-argument stringp (process-buffer process))

I rarely use these - do you think it's worth it?

@josephmturner
Copy link
Contributor

josephmturner commented May 24, 2024

There's no need, because we actually do want to unconditionally kill the buffer. So we don't want any query. If another user function, apart from process-kill-buffer-query-function remains in there, and actually prevents the buffer from being killed (or just also asks us for confirmation), that won't really fix the problem.

That sounds reasonable to me. I was imagining a scenario where for some reason (debugging, maybe?) the user wants to never kill any process buffers. The user could add a different hook, and that would ensure the buffer stayed alive.

OTOH, if we only remq the default hook, other hooks might prompt for confirmation in an undesired way.

Whatever you guys decide is fine by me. My example user story is pretty far-fetched - I'm just trying to be thorough :)

@alphapapa
Copy link
Owner

According to the Elisp manual, if generate-new-buffer is called with the inhibit-buffer-hooks argument, kill-buffer-query-functions are not called. So it would probably be better if we just passed that argument when we call generate-new-buffer.

@mkcms
Copy link
Contributor Author

mkcms commented May 24, 2024

@alphapapa

if generate-new-buffer is called with the inhibit-buffer-hooks argument, kill-buffer-query-functions are not called

Nice, that's even better. I've updated the PR to do that.

@alphapapa alphapapa closed this in acba6e1 May 26, 2024
@alphapapa
Copy link
Owner

@mkcms Thank you!

@josephmturner
Copy link
Contributor

josephmturner commented Jun 2, 2024

Note that the current solution only works on Emacs 28+. We were not able to backport generate-new-buffer's optional INHIBIT-BUFFER-HOOKS argument in compat. See this comment for details.

@alphapapa
Copy link
Owner

@josephmturner Thanks. So do we need to bind kill-buffer-query-functions on Emacs 27 after all?

I can't reopen this PR, so we'll have to make a new issue.

@josephmturner
Copy link
Contributor

@alphapapa Yes, I believe so. I think we could apply the same patch that @mkcms wrote, and then add a TODO to deprecate plz--kill-buffer when plz stops supporting Emacs 27.

alphapapa added a commit that referenced this pull request Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants