Subject: bug#65719: closed (Re: bug#65719: [PATCH] Pass restart argument to 'kill-emacs-query-functions')

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 01 Feb 2025 12:06:02 +0000

Your bug report

#65719: [PATCH] Pass restart argument to 'kill-emacs-query-functions'

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
65719: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=65719
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#65719: [PATCH] Pass restart argument to 'kill-emacs-query-functions'
From: Eli Zaretskii <[email-masked]>
To: [email-masked]
Cc: [email-masked], [email-masked]
Date: Sat, 01 Feb 2025 14:05:38 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

> Cc: [email-masked], [email-masked]
> Date: Tue, 07 Jan 2025 18:38:04 +0200
> From: Eli Zaretskii <[email-masked]>
> 
> > Date: Tue, 07 Jan 2025 15:54:42 +0000
> > From: [email-masked]
> > Cc: [email-masked], [email-masked]
> > 
> > > It's a strange (and maybe even dangerous) distinction.
> > 
> > I'm afraid I don't see this, could you elaborate?
> > 
> > > But in any case, I think a cleaner solution would be to bind a
> > > variable inside restart-emacs, and then your hook could examine it.
> > > Alternatively, ...
> > > 
> > >> > In any case, the prefix argument is available via current-prefix-arg.
> > >> 
> > >> Yes you're right, I realised after I sent it....
> > > 
> > > ...you could invoke restart-emacs with a prefix argument, and examine
> > > that in your kill-emacs-query-functions hook.  AFAICT, this should
> > > work without any changes.
> > 
> > I'm afraid I also don't follow here, how is that cleaner than 
> > introducing
> > a specific hook? Rather than needing to specifically modify a function
> > to work with the prefix argument, you can just add it to the hook.
> 
> It isn't necessarily cleaner, but it is a local solution for what I
> consider a local and very specialized problem.  There's no reason to
> expect Emacs to have an OOTB solution for every possible niche use
> case that some user needs to handle.  Adding a hook means we all have
> to pay the price in documenting it, maintaining it, etc.
> 
> Each request for adding a new feature should have a solid enough basis
> before we must consider it for addition.  FWIW, I don't yet see why
> this particular request qualifies.

No further comments, so I'm closing this bug.

Subject: [PATCH] Pass restart argument to 'kill-emacs-query-functions'
From: [email-masked]
To: [email-masked]
Date: Sun, 03 Sep 2023 20:28:34 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi all,

Small change here to pass the restart status to 
'kill-emacs-query-functions' in 'save-buffers-kill-emacs' so any 
functions there can react to being restarted, sample use-case this may 
be useful is if one is using a package like perspective.el to handle 
buffer/window management and when calling `M-x restart-emacs` you WANT 
your last session to be persisted, but just starting Emacs normally you 
don't.

There are other potential use-cases for this too, so hopefully this 
patch is well-received.

Thanks all,

Ellis (@lkn)

From 250c0c4f88f1d169415d4f6c6634e17829064746 Mon Sep 17 00:00:00 2001
From: Ellis Kenyo <[email-masked]>
Date: Sun, 3 Sep 2023 20:17:21 +0100
Subject: [PATCH] Add restart argument to 'kill-emacs-query-functions'

* etc/NEWS: Update NEWS file.

* lisp/files.el (save-buffers-kill-emacs): Pass in the RESTART
argument to subsequent hook calls.
---
 etc/NEWS      |  7 +++++++
 lisp/files.el | 11 ++++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index bbf4b67fe34..7273ebd2183 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -776,6 +776,13 @@ the current project.
 The look of the key prompt in the project switcher has been changed
 slightly.  To get the previous one, set this option to 'brackets'.
 
+** Files
+
+*** 'kill-emacs-query-functions' now takes RESTART as an argument.
+Functions added to this hook can now accept an argument denoting
+whether or not the call is due to call restart Emacs; if called from
+say 'restart-emacs'.
+
 
 * Incompatible Lisp Changes in Emacs 30.1
 
diff --git a/lisp/files.el b/lisp/files.el
index 4188615e490..095cba693d0 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -8134,10 +8134,11 @@ defun insert-directory-safely
     (insert (format "%s: No such file or directory\n" file))))
 
 (defcustom kill-emacs-query-functions nil
-  "Functions to call with no arguments to query about killing Emacs.
-If any of these functions returns nil, killing Emacs is canceled.
-`save-buffers-kill-emacs' calls these functions, but `kill-emacs',
-the low level primitive, does not.  See also `kill-emacs-hook'."
+  "Functions to call with restart status as an argument to query about
+killing Emacs. If any of these functions returns nil, killing Emacs is
+canceled. `save-buffers-kill-emacs' calls these functions, but
+`kill-emacs',the low level primitive, does not.  See also
+`kill-emacs-hook'."
   :type 'hook
   :version "26.1"
   :group 'convenience)
@@ -8228,7 +8229,7 @@ defun save-buffers-kill-emacs
                         (when (window-live-p window)
                           (quit-restore-window window 'kill)))))))))
      ;; Query the user for other things, perhaps.
-     (run-hook-with-args-until-failure 'kill-emacs-query-functions)
+     (run-hook-with-args-until-failure 'kill-emacs-query-functions restart)
      (or (null confirm)
          (funcall confirm "Really exit Emacs? "))
      (kill-emacs nil restart))))
-- 
2.41.0