unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Ellis Kenyo via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Stefan Kangas <stefankangas@gmail.com>
Cc: 65719@debbugs.gnu.org
Subject: bug#65719: [PATCH] Pass restart argument to 'kill-emacs-query-functions'
Date: Mon, 12 Feb 2024 15:29:50 +0000	[thread overview]
Message-ID: <0d97a409-b9c4-4204-b5d0-1bb386056c56@elken.dev> (raw)
In-Reply-To: <2aae66e7-f7e3-4da4-aee8-0ff9a8db1f0a@elken.dev>

[-- 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


  reply	other threads:[~2024-02-12 15:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0d97a409-b9c4-4204-b5d0-1bb386056c56@elken.dev \
    --to=bug-gnu-emacs@gnu.org \
    --cc=65719@debbugs.gnu.org \
    --cc=me@elken.dev \
    --cc=stefankangas@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).