8

It turned out not to be the same problem as Kill process buffer without confirmation?: emacs asks for different kind of confirmations when exiting and when just killing a buffer.

How to specify for all or specific processes (e.g. one launched with run-scheme) to be killed without confirmation on exiting emacs?

user905686
  • 327
  • 2
  • 11
  • A side question is : why isn't that question asked from kill-emacs-query-functions ? I have no idea. Hysterical reasons ? A work around would be to use kill-emacs directly (or write an analogue to sbke which bypasses the question). Another workaround would be advice sbke with a :before advice that will kill the processes you don't want to be warned about. – YoungFrog Aug 25 '16 at 11:04
  • Yet another workaround would be to follow my answer at http://emacs.stackexchange.com/questions/14669/sort-of-autoreply-for-specific-messages-in-minibuffer/26357#26357 and code the improvement I suggested in a comment, then use all of that around sbke... ok maybe I should stop now :) – YoungFrog Aug 25 '16 at 11:07

2 Answers2

11

Emacs 26.1 added the confirm-kill-processes variable. To disable confirmation to kill processes on Emacs exit, add to your init file:

(setq confirm-kill-processes nil)

Documentation:

Non-nil if Emacs should confirm killing processes on exit. If this variable is nil, the value of process-query-on-exit-flag is ignored. Otherwise, if there are processes with a non-nil process-query-on-exit-flag, Emacs will prompt the user before killing them.

rduplain
  • 261
  • 3
  • 5
4

Following my own suggestion (second comment on the question), here's an answer which avoids the prompting altogether:

(require 'auto-answer)    
(let ((auto-answer '(("\\`Active processes exist; kill them and exit anyway\\? \\'" t))))
  (save-buffers-kill-emacs))

This uses auto-answer.el, available at https://github.com/YoungFrog/auto-answer/blob/master/auto-answer.el (it requires dash.el from your favourite package store, and nadvice.el which is available at least in 24.4).

Edit: If you only want to avoid the prompt for some (specific) processes, the documented way to do it is to set its query-on-exit flag to nil using set-process-query-on-exit-flag when creating the process.

YoungFrog
  • 3,496
  • 15
  • 27
  • Thanks, just a few problems: first, please note that it also requires [dash.el](https://github.com/magnars/dash.el/blob/master/dash.el). Then: am I supposed to put it in .emacs? Doing so closes emacs right after startup. Finally, for selectively disabling asking for *some* processes this approach doesn't seem appropriate, as it only looks for that message (which is common to all processes being killed). – user905686 Sep 02 '16 at 17:46
  • The dependency on dash is mentionned at the top of that file. The idea behind this code is that you create your own `my-kill-emacs` function and bind that to `C-x C-c` instead of `save-buffers-kill-emacs`. If you want to selectively disable asking for some processes, the obvious answer is to use `set-process-query-on-exit-flag` (set the flag to nil) on those processes when they are created. – YoungFrog Sep 02 '16 at 22:14
  • 2
    Thank you, this was even more what I was looking for. With `(set-process-query-on-exit-flag (get-process "scheme") nil)` [(doc)](https://www.gnu.org/software/emacs/manual/html_node/elisp/Query-Before-Exit.html) right after `(run-scheme "petite")` the query is disabled directly after starting the process (which in my happens in `.emacs`). Could you add this to your answer? Then I'll accept it . – user905686 Sep 03 '16 at 19:37