From: Lars Ingebrigtsen Date: Tue, 12 Oct 2021 11:55:28 +0000 (+0200) Subject: Add a new after-pdump-load-hook variable X-Git-Tag: emacs-29.0.90~3671^2~599 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=6d68fbd57f730051dd3af470e7b0c41b41238bd0;p=emacs.git Add a new after-pdump-load-hook variable * doc/lispref/internals.texi (Building Emacs): Document it. * lisp/subr.el (after-pdump-load-hook): New variable. * src/emacs.c (main): Run the new hook. * src/pdumper.c (syms_of_pdumper): Define a symbol. --- diff --git a/doc/lispref/internals.texi b/doc/lispref/internals.texi index d3edd633171..7718712b9b8 100644 --- a/doc/lispref/internals.texi +++ b/doc/lispref/internals.texi @@ -218,6 +218,14 @@ the Emacs executable that dumped them. If you want to use this function in an Emacs that was already dumped, you must run Emacs with the @samp{-batch} option. + +@vindex after-pdump-load-hook +If you're including @samp{.el} files in the dumped Emacs and that +@samp{.el} file has code that is normally run at load time, that code +won't be run when Emacs starts after dumping. To help work around +that problem, you can put functions on the +@code{after-pdump-load-hook} hook. This hook is run when starting +Emacs. @end defun @defun dump-emacs to-file from-file diff --git a/etc/NEWS b/etc/NEWS index fe6f21fec2d..9daf958b07e 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -31,6 +31,12 @@ applies, and please also update docstrings as needed. ** Emacs now has a --fingerprint option. This will output a string identifying the current Emacs build. ++++ +** New hook 'after-pdump-load-hook'. +This is run at the end of the Emacs startup process, and it meant to +be used to reinitialize structures that would normally be done at load +time. + * Changes in Emacs 29.1 diff --git a/lisp/subr.el b/lisp/subr.el index 90f24a237fb..805c14eae3b 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -3568,6 +3568,9 @@ If either NAME or VAL are specified, both should be specified." (defvar suspend-resume-hook nil "Normal hook run by `suspend-emacs', after Emacs is continued.") +(defvar after-pdump-load-hook nil + "Normal hook run after loading the .pdmp file.") + (defvar temp-buffer-show-hook nil "Normal hook run by `with-output-to-temp-buffer' after displaying the buffer. When the hook runs, the temporary buffer is current, and the window it diff --git a/src/emacs.c b/src/emacs.c index b178c6a06cf..1f6490fbc04 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -2333,6 +2333,11 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem if (dump_mode) Vdump_mode = build_string (dump_mode); +#ifdef HAVE_PDUMPER + /* Allow code to be run (mostly useful after redumping). */ + safe_run_hooks (Qafter_pdump_load_hook); +#endif + /* Enter editor command loop. This never returns. */ set_initial_minibuffer_mode (); Frecursive_edit (); diff --git a/src/pdumper.c b/src/pdumper.c index 96fbd56a236..6cf7b847cb7 100644 --- a/src/pdumper.c +++ b/src/pdumper.c @@ -5706,6 +5706,7 @@ pdumper_load (const char *dump_filename, char *argv0) dump_mmap_release (§ions[i]); if (dump_fd >= 0) emacs_close (dump_fd); + return err; } @@ -5790,6 +5791,7 @@ syms_of_pdumper (void) DEFSYM (Qdumped_with_pdumper, "dumped-with-pdumper"); DEFSYM (Qload_time, "load-time"); DEFSYM (Qdump_file_name, "dump-file-name"); + DEFSYM (Qafter_pdump_load_hook, "after-pdump-load-hook"); defsubr (&Spdumper_stats); #endif /* HAVE_PDUMPER */ }