From a8be860e17e2a737bda7a4c5075b71f0fb627a92 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 10 Mar 2018 13:48:49 +0200 Subject: [PATCH] Improve support for desktop restoration in daemon mode * lisp/server.el (server-after-make-frame-hook): New hook. (server-execute): Call it after creating a new frame or before switching to a buffer shown in a client frame. (Bug#30421) * doc/emacs/misc.texi (Saving Emacs Sessions): Adjust advice for restoring desktop in daemon mode to the new hook. * doc/lispref/frames.texi (Creating Frames, Standard Hooks): Document server-after-make-frame-hook. * etc/NEWS: Mention server-after-make-frame-hook. --- doc/emacs/misc.texi | 2 +- doc/lispref/frames.texi | 6 ++++++ doc/lispref/hooks.texi | 1 + etc/NEWS | 9 +++++++++ lisp/server.el | 9 +++++++++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi index 60986347a71..68bd308983f 100644 --- a/doc/emacs/misc.texi +++ b/doc/emacs/misc.texi @@ -2529,7 +2529,7 @@ e.g., the daemon cannot use GUI features, so parameters such as frame position, size, and decorations cannot be restored. For that reason, you may wish to delay restoring the desktop in daemon mode until the first client connects, by calling @code{desktop-read} in a hook -function that you add to @code{after-make-frame-functions} +function that you add to @code{server-after-make-frame-hook} (@pxref{Creating Frames,,, elisp, The Emacs Lisp Reference Manual}). @node Recursive Edit diff --git a/doc/lispref/frames.texi b/doc/lispref/frames.texi index 2f9bb398865..459f05cb1c9 100644 --- a/doc/lispref/frames.texi +++ b/doc/lispref/frames.texi @@ -181,6 +181,12 @@ the value of that parameter in the created frame to its value in the selected frame. @end defvar +@defopt server-after-make-frame-hook +A normal hook run when the Emacs server creates a client frame. When +this hook is called, the created frame is the selected one. +@xref{Emacs Server,,, emacs, The GNU Emacs Manual}. +@end defopt + @node Multiple Terminals @section Multiple Terminals diff --git a/doc/lispref/hooks.texi b/doc/lispref/hooks.texi index db4e413921f..e374d02defb 100644 --- a/doc/lispref/hooks.texi +++ b/doc/lispref/hooks.texi @@ -66,6 +66,7 @@ not exactly a hook, but does a similar job. @item after-make-frame-functions @itemx before-make-frame-hook +@itemx server-after-make-frame-hook @xref{Creating Frames}. @c Not general enough? diff --git a/etc/NEWS b/etc/NEWS index 14926ba2e3b..8d69dc6b538 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -83,6 +83,15 @@ Customize the option 'mode-line-default-help-echo' to restore the old behavior where the tooltip text is also shown when the corresponding action does not apply. ++++ +** New hook 'server-after-make-frame-hook'. +This hook is a convenient place to perform initializations in daemon +mode which require GUI features to be available. One example is +restoration of the previous session using the desktop.el package: put +the call to 'desktop-read' in this hook, if you want the GUI settings +to be restored, or if desktop.el needs to interact with you during +restoration of the session. + +++ ** New function 'logcount' calculates an integer's Hamming weight. diff --git a/lisp/server.el b/lisp/server.el index a892203c24a..ff03cbe622c 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -188,6 +188,13 @@ space (this means characters from ! to ~; or from code 33 to :group 'server :type 'hook) +(defcustom server-after-make-frame-hook nil + "Hook run when the Emacs server creates a client frame. +The created frame is selected when the hook is called." + :group 'server + :type 'hook + :version "27.1") + (defcustom server-done-hook nil "Hook run when done editing a buffer for the Emacs server." :group 'server @@ -1336,9 +1343,11 @@ The following commands are accepted by the client: ((or isearch-mode (minibufferp)) nil) ((and frame (null buffers)) + (run-hooks 'server-after-make-frame-hook) (message "%s" (substitute-command-keys "When done with this frame, type \\[delete-frame]"))) ((not (null buffers)) + (run-hooks 'server-after-make-frame-hook) (server-switch-buffer (car buffers) nil (cdr (car files))) (run-hooks 'server-switch-hook) (unless nowait -- 2.39.2