* bug#65719: [PATCH] Pass restart argument to 'kill-emacs-query-functions'
@ 2023-09-03 19:28 me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-04 1:01 ` Stefan Kangas
0 siblings, 1 reply; 11+ messages in thread
From: me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-09-03 19:28 UTC (permalink / raw)
To: 65719
[-- Attachment #1: Type: text/plain, Size: 538 bytes --]
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)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-restart-argument-to-kill-emacs-query-functions.patch --]
[-- Type: text/x-diff; name=0001-Add-restart-argument-to-kill-emacs-query-functions.patch, Size: 2423 bytes --]
From 250c0c4f88f1d169415d4f6c6634e17829064746 Mon Sep 17 00:00:00 2001
From: Ellis Kenyo <me@elken.dev>
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'.
+
\f
* 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
^ permalink raw reply related [flat|nested] 11+ messages in thread
* bug#65719: [PATCH] Pass restart argument to 'kill-emacs-query-functions'
2023-09-03 19:28 bug#65719: [PATCH] Pass restart argument to 'kill-emacs-query-functions' me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-09-04 1:01 ` Stefan Kangas
2023-09-04 5:04 ` Elken via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-04 5:26 ` me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 2 replies; 11+ messages in thread
From: Stefan Kangas @ 2023-09-04 1:01 UTC (permalink / raw)
To: me, 65719
me--- via "Bug reports for GNU Emacs, the Swiss army knife of text
editors" <bug-gnu-emacs@gnu.org> writes:
> 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. The feature sounds useful, and the use-case makes sense. But
isn't the change backwards-incompatible? Can we find a way to do this
without any breaking changes?
One idea would be to simply introduce a new variable that takes the
argument, while making the old one obsolete. That would allow people to
slowly migrate over to the new one, without everything suddenly breaking
under their feet.
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#65719: [PATCH] Pass restart argument to 'kill-emacs-query-functions'
2023-09-04 1:01 ` Stefan Kangas
@ 2023-09-04 5:04 ` Elken via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-04 5:26 ` me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
1 sibling, 0 replies; 11+ messages in thread
From: Elken via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-09-04 5:04 UTC (permalink / raw)
To: Stefan Kangas, 65719
[-- Attachment #1: Type: text/plain, Size: 315 bytes --]
Hi Stefan,
Thanks for the positive feedback.
I'm not sure that's the case, I'll do more testing locally. If that is the case, then I can introduce 'restart-emacs-query-functions' instead when 'restart' is t for the same outcome, which may actually be a preferable change anyway.
Thanks,
Ellis (@lkn)
[-- Attachment #2: Type: text/html, Size: 394 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#65719: [PATCH] Pass restart argument to 'kill-emacs-query-functions'
2023-09-04 1:01 ` Stefan Kangas
2023-09-04 5:04 ` Elken via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-09-04 5:26 ` me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-08 11:37 ` Stefan Kangas
2023-10-15 14:32 ` Stefan Kangas
1 sibling, 2 replies; 11+ messages in thread
From: me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-09-04 5:26 UTC (permalink / raw)
To: Stefan Kangas; +Cc: 65719
[-- Attachment #1: Type: text/plain, Size: 313 bytes --]
> One idea would be to simply introduce a new variable that takes the
> argument, while making the old one obsolete. That would allow people
> to
> slowly migrate over to the new one, without everything suddenly
> breaking
> under their feet.
How does this patch sound? I think it's the best of both worlds :)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Introduce-restart-emacs-query-functions.patch --]
[-- Type: text/x-diff; name=0001-Introduce-restart-emacs-query-functions.patch, Size: 2369 bytes --]
From 7d6f5c259cefe65b5e021dacee18966acc6bc120 Mon Sep 17 00:00:00 2001
From: Ellis Kenyo <me@elken.dev>
Date: Mon, 4 Sep 2023 06:20:33 +0100
Subject: [PATCH] Introduce 'restart-emacs-query-functions'
* etc/NEWS: Update NEWS file.
* lisp/files.el (save-buffers-kill-emacs): Add new option
'restart-emacs-query-functions' for functions that should be called
when 'restart' is passed.
---
etc/NEWS | 7 +++++++
lisp/files.el | 13 +++++++++++++
2 files changed, 20 insertions(+)
diff --git a/etc/NEWS b/etc/NEWS
index bbf4b67fe34..95e6248c08a 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
+
+*** New user option 'restart-emacs-query-functions'.
+Equivalent to 'kill-emacs-query-functions', this hook is called when
+'save-buffers-kill-emacs' is called with the 'restart' flag; if
+invoked from say 'M-x restart-emacs'.
+
\f
* Incompatible Lisp Changes in Emacs 30.1
diff --git a/lisp/files.el b/lisp/files.el
index 4188615e490..7849d6b7c81 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -8142,6 +8142,15 @@ defcustom kill-emacs-query-functions
:version "26.1"
:group 'convenience)
+(defcustom restart-emacs-query-functions nil
+ "Functions to call with no arguments to query about restarting
+Emacs. If any of these functions returns nil, restarting Emacs is
+canceled. `save-buffers-kill-emacs' calls these functions when passed
+`restart'. See also `kill-emacs-hook'."
+ :type 'hook
+ :version "30.1"
+ :group 'convenience)
+
(defcustom confirm-kill-emacs nil
"How to ask for confirmation when leaving Emacs.
If nil, the default, don't ask at all. If the value is non-nil, it should
@@ -8227,6 +8236,10 @@ defun save-buffers-kill-emacs
(yes-or-no-p "Active processes exist; kill them and exit anyway? "))
(when (window-live-p window)
(quit-restore-window window 'kill)))))))))
+ ;; Only call these when restarting
+ (when restart
+ (run-hook-with-args-until-failure 'restart-emacs-query-functions))
+
;; Query the user for other things, perhaps.
(run-hook-with-args-until-failure 'kill-emacs-query-functions)
(or (null confirm)
--
2.41.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* bug#65719: [PATCH] Pass restart argument to 'kill-emacs-query-functions'
2023-09-04 5:26 ` me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-09-08 11:37 ` Stefan Kangas
2023-10-15 14:32 ` Stefan Kangas
1 sibling, 0 replies; 11+ messages in thread
From: Stefan Kangas @ 2023-09-08 11:37 UTC (permalink / raw)
To: me; +Cc: 65719
me@elken.dev writes:
>> One idea would be to simply introduce a new variable that takes the
>> argument, while making the old one obsolete. That would allow people
>> to slowly migrate over to the new one, without everything suddenly
>> breaking under their feet.
>
> How does this patch sound? I think it's the best of both worlds :)
LGTM, but let's see if anyone else has any comments.
> From 7d6f5c259cefe65b5e021dacee18966acc6bc120 Mon Sep 17 00:00:00 2001
> From: Ellis Kenyo <me@elken.dev>
> Date: Mon, 4 Sep 2023 06:20:33 +0100
> Subject: [PATCH] Introduce 'restart-emacs-query-functions'
>
> * etc/NEWS: Update NEWS file.
>
> * lisp/files.el (save-buffers-kill-emacs): Add new option
> 'restart-emacs-query-functions' for functions that should be called
> when 'restart' is passed.
> ---
> etc/NEWS | 7 +++++++
> lisp/files.el | 13 +++++++++++++
> 2 files changed, 20 insertions(+)
>
> diff --git a/etc/NEWS b/etc/NEWS
> index bbf4b67fe34..95e6248c08a 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
> +
> +*** New user option 'restart-emacs-query-functions'.
> +Equivalent to 'kill-emacs-query-functions', this hook is called when
> +'save-buffers-kill-emacs' is called with the 'restart' flag; if
> +invoked from say 'M-x restart-emacs'.
> +
> \f
> * Incompatible Lisp Changes in Emacs 30.1
>
> diff --git a/lisp/files.el b/lisp/files.el
> index 4188615e490..7849d6b7c81 100644
> --- a/lisp/files.el
> +++ b/lisp/files.el
> @@ -8142,6 +8142,15 @@ defcustom kill-emacs-query-functions
> :version "26.1"
> :group 'convenience)
>
> +(defcustom restart-emacs-query-functions nil
> + "Functions to call with no arguments to query about restarting
> +Emacs. If any of these functions returns nil, restarting Emacs is
> +canceled. `save-buffers-kill-emacs' calls these functions when passed
> +`restart'. See also `kill-emacs-hook'."
> + :type 'hook
> + :version "30.1"
> + :group 'convenience)
> +
> (defcustom confirm-kill-emacs nil
> "How to ask for confirmation when leaving Emacs.
> If nil, the default, don't ask at all. If the value is non-nil, it should
> @@ -8227,6 +8236,10 @@ defun save-buffers-kill-emacs
> (yes-or-no-p "Active processes exist; kill them and exit anyway? "))
> (when (window-live-p window)
> (quit-restore-window window 'kill)))))))))
> + ;; Only call these when restarting
> + (when restart
> + (run-hook-with-args-until-failure 'restart-emacs-query-functions))
> +
> ;; Query the user for other things, perhaps.
> (run-hook-with-args-until-failure 'kill-emacs-query-functions)
> (or (null confirm)
> --
> 2.41.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#65719: [PATCH] Pass restart argument to 'kill-emacs-query-functions'
2023-09-04 5:26 ` me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-08 11:37 ` Stefan Kangas
@ 2023-10-15 14:32 ` Stefan Kangas
2024-02-12 14:54 ` Ellis Kenyo via Bug reports for GNU Emacs, the Swiss army knife of text editors
1 sibling, 1 reply; 11+ messages in thread
From: Stefan Kangas @ 2023-10-15 14:32 UTC (permalink / raw)
To: me; +Cc: 65719
me@elken.dev writes:
>> One idea would be to simply introduce a new variable that takes the
>> argument, while making the old one obsolete. That would allow people
>> to
>> slowly migrate over to the new one, without everything suddenly
>> breaking
>> under their feet.
>
> How does this patch sound? I think it's the best of both worlds :)
Thanks, sounds good to me.
Before it can go in, I think it should also be added to the user manual,
next to where `kill-emacs-query-functions' is documented. And add the
correct "+++" tag to the NEWS entry.
Thanks in advance.
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#65719: [PATCH] Pass restart argument to 'kill-emacs-query-functions'
2023-10-15 14:32 ` Stefan Kangas
@ 2024-02-12 14:54 ` Ellis Kenyo via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-12 15:29 ` Ellis Kenyo via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 11+ messages in thread
From: Ellis Kenyo via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-02-12 14:54 UTC (permalink / raw)
To: Stefan Kangas; +Cc: 65719
Apologies for letting this one slip, I must have forgotten to reply.
Some time has passed since so I'll create a new patch in the next few
hours including that manual change and mail it in :)
Sorry for the delay!
Thanks,
Ellis
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#65719: [PATCH] Pass restart argument to 'kill-emacs-query-functions'
2024-02-12 14:54 ` Ellis Kenyo via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-02-12 15:29 ` Ellis Kenyo via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-12 16:53 ` Eli Zaretskii
0 siblings, 1 reply; 11+ messages in thread
From: Ellis Kenyo via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-02-12 15:29 UTC (permalink / raw)
To: Stefan Kangas; +Cc: 65719
[-- Attachment #1: Type: text/plain, Size: 86 bytes --]
One patch hot and fresh out the oven :)
Hope we can get this one in!
Thanks,
Ellis
[-- Attachment #2: 0001-Introduce-restart-emacs-query-functions.patch --]
[-- Type: text/x-patch, Size: 3487 bytes --]
From 7b18b01b434003e6f25fe8b71d510464b8ac0afd Mon Sep 17 00:00:00 2001
From: Ellis Kenyo <me@elken.dev>
Date: Mon, 12 Feb 2024 15:25:25 +0000
Subject: [PATCH] Introduce 'restart-emacs-query-functions'
* etc/NEWS: Update NEWS file.
* lisp/files.el (save-buffers-kill-emacs): Add new option
'restart-emacs-query-functions' for functions that should be called
when 'restart' is passed.
* doc/lispref/os.texi: Document 'restart-emacs-query-functions' and
adjust 'restart-emacs' to reflect new change.
---
doc/lispref/os.texi | 12 +++++++++++-
etc/NEWS | 7 +++++++
lisp/files.el | 12 ++++++++++++
3 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi
index 60ae57d4c1d..5533edcddef 100644
--- a/doc/lispref/os.texi
+++ b/doc/lispref/os.texi
@@ -762,11 +762,21 @@ Killing Emacs
directly does not run this hook.
@end defopt
+@defopt restart-emacs-query-functions
+Similar to how @code{kill-emacs-query-functions} is called, when the
+@code{restart} flag is passed; these hooks trigger. Calling
+@code{restart-emacs} is one such way to ensure this flag is passed.
+
+They obey the same rules as @code{kill-emacs-query-functions}, and as
+such one should reference those rules above.
+@end defopt
+
@deffn Command restart-emacs
This command does the same as @code{save-buffers-kill-emacs}, but
instead of just killing the current Emacs process at the end, it'll
restart a new Emacs process, using the same command line arguments as
-the currently running Emacs process.
+the currently running Emacs process and also trigger all the functions
+defined in @code{restart-emacs-query-functions}.
@end deffn
@node Suspending Emacs
diff --git a/etc/NEWS b/etc/NEWS
index afc2c22e68b..da7ce45e87b 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -538,6 +538,13 @@ you can add this to your init script:
(setopt project-switch-commands #'project-prefix-or-any-command)
+** Files
+
+*** New user option 'restart-emacs-query-functions'.
+Equivalent to 'kill-emacs-query-functions', this hook is called when
+'save-buffers-kill-emacs' is called with the 'restart' flag; if
+invoked from say 'M-x restart-emacs'.
+
** VC
---
diff --git a/lisp/files.el b/lisp/files.el
index f67b650cb92..9704d818310 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -8252,6 +8252,15 @@ kill-emacs-query-functions
:version "26.1"
:group 'convenience)
+(defcustom restart-emacs-query-functions nil
+ "Functions to call with no arguments to query about restarting
+Emacs. If any of these functions returns nil, restarting Emacs is
+canceled. `save-buffers-kill-emacs' calls these functions when passed
+`restart'. See also `kill-emacs-hook'."
+ :type 'hook
+ :version "30.1"
+ :group 'convenience)
+
(defcustom confirm-kill-emacs nil
"How to ask for confirmation when leaving Emacs.
If nil, the default, don't ask at all. If the value is non-nil, it should
@@ -8337,6 +8346,9 @@ save-buffers-kill-emacs
(yes-or-no-p "Active processes exist; kill them and exit anyway? "))
(when (window-live-p window)
(quit-restore-window window 'kill)))))))))
+ ;; Only call these when restarting
+ (when restart
+ (run-hook-with-args-until-failure 'restart-emacs-query-functions))
;; Query the user for other things, perhaps.
(run-hook-with-args-until-failure 'kill-emacs-query-functions)
(or (null confirm)
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* bug#65719: [PATCH] Pass restart argument to 'kill-emacs-query-functions'
2024-02-12 15:29 ` Ellis Kenyo via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-02-12 16:53 ` Eli Zaretskii
[not found] ` <E50F6DD3-D4AA-4A51-B470-ABB496F6B113@elken.dev>
0 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2024-02-12 16:53 UTC (permalink / raw)
To: Ellis Kenyo; +Cc: 65719, stefankangas
> Cc: 65719@debbugs.gnu.org
> Date: Mon, 12 Feb 2024 15:29:50 +0000
> From: Ellis Kenyo via "Bug reports for GNU Emacs,
> the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
>
> From 7b18b01b434003e6f25fe8b71d510464b8ac0afd Mon Sep 17 00:00:00 2001
> From: Ellis Kenyo <me@elken.dev>
> Date: Mon, 12 Feb 2024 15:25:25 +0000
> Subject: [PATCH] Introduce 'restart-emacs-query-functions'
>
> * etc/NEWS: Update NEWS file.
>
> * lisp/files.el (save-buffers-kill-emacs): Add new option
> 'restart-emacs-query-functions' for functions that should be called
> when 'restart' is passed.
Thanks, but can you tell in what cases kill-emacs-query-functions
(which will be called anyway in this case) is not enough?
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2024-02-12 17:52 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-03 19:28 bug#65719: [PATCH] Pass restart argument to 'kill-emacs-query-functions' me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-04 1:01 ` Stefan Kangas
2023-09-04 5:04 ` Elken via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-04 5:26 ` me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-08 11:37 ` Stefan Kangas
2023-10-15 14:32 ` Stefan Kangas
2024-02-12 14:54 ` Ellis Kenyo via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-12 15:29 ` Ellis Kenyo via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-12 16:53 ` Eli Zaretskii
[not found] ` <E50F6DD3-D4AA-4A51-B470-ABB496F6B113@elken.dev>
2024-02-12 17:35 ` Eli Zaretskii
2024-02-12 17:52 ` Elken via Bug reports for GNU Emacs, the Swiss army knife of text editors
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.