From 3969a34fa1ba1647665c662ce0a594b92f3f9d87 Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Mon, 13 Feb 2023 10:15:33 +0100 Subject: [PATCH 01/24] Revert "Rename to inhibit-automatic-native-compilation" This reverts commit f97993ee667f9be7589825f3a4fbc095d6944ec6. --- doc/lispref/compile.texi | 4 ++-- etc/NEWS | 9 +++++---- lisp/emacs-lisp/comp.el | 2 +- lisp/progmodes/elisp-mode.el | 4 ++-- lisp/startup.el | 7 +++---- lisp/subr.el | 2 +- src/comp.c | 7 +++---- 7 files changed, 17 insertions(+), 18 deletions(-) diff --git a/doc/lispref/compile.texi b/doc/lispref/compile.texi index be2125a9ab3..8bb079b65df 100644 --- a/doc/lispref/compile.texi +++ b/doc/lispref/compile.texi @@ -981,7 +981,7 @@ whether native-compilation is available should use this predicate. This section documents the variables that control native-compilation. -@defvar inhibit-automatic-native-compilation +@defvar inhibit-native-compilation If your Emacs has support for native compilation, Emacs will (by default) compile the Lisp files you're loading in the background, and then install the native-compiled versions of the functions. If you @@ -995,7 +995,7 @@ files, the compiler may still be invoked to install @dfn{trampolines} if any built-in functions are redefined. However, these trampolines will not get written to your cache directory. -You can also use the @samp{EMACS_INHIBIT_AUTOMATIC_NATIVE_COMPILATION} +You can also use the @samp{EMACS_INHIBIT_NATIVE_COMPILATION} environment variable to disable native compilation. @end defvar diff --git a/etc/NEWS b/etc/NEWS index 2d15e39036a..5ce18872f1a 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -199,11 +199,12 @@ load time. ** Native Compilation +++ -*** New variable 'inhibit-automatic-native-compilation'. +*** New variable 'inhibit-native-compilation'. If set, Emacs will inhibit native compilation (and won't write -anything to the eln cache automatically). The variable is initialized -during Emacs startup from the environment variable -'EMACS_INHIBIT_AUTOMATIC_NATIVE_COMPILATION'. +anything to the eln cache automatically). The variable is initialised +from the EMACS_INHIBIT_NATIVE_COMPILATION environment variable on +Emacs startup. + --- *** New command 'native-compile-prune-cache'. diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index 7ba8e956fb2..ab6c8a8ea90 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -3805,7 +3805,7 @@ Return the trampoline if found or nil otherwise." form nil ;; If we've disabled nativecomp, don't write the trampolines to ;; the eln cache (but create them). - (and (not inhibit-automatic-native-compilation) + (and (not inhibit-native-compilation) (cl-loop for dir in (if native-compile-target-directory (list (expand-file-name comp-native-version-dir diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index be969b0c3e3..7ba2c38cb75 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -220,8 +220,8 @@ All commands in `lisp-mode-shared-map' are inherited by this map." Load the compiled code when finished. Use `emacs-lisp-byte-compile-and-load' in combination with -`inhibit-automatic-native-compilation' set to nil to achieve -asynchronous native compilation." +`inhibit-native-compilation' set to nil to achieve asynchronous +native compilation." (interactive nil emacs-lisp-mode) (emacs-lisp--before-compile-buffer) (load (native-compile buffer-file-name))) diff --git a/lisp/startup.el b/lisp/startup.el index e5ec15eebea..b0a8eed9d38 100644 --- a/lisp/startup.el +++ b/lisp/startup.el @@ -542,7 +542,7 @@ DIRS are relative." (setq comp--compilable t)) (defvar native-comp-eln-load-path) -(defvar inhibit-automatic-native-compilation) +(defvar inhibit-native-compilation) (defvar comp-enable-subr-trampolines) (defvar startup--original-eln-load-path nil @@ -580,8 +580,7 @@ It sets `command-line-processed', processes the command-line, reads the initialization files, etc. It is the default value of the variable `top-level'." ;; Allow disabling automatic .elc->.eln processing. - (setq inhibit-automatic-native-compilation - (getenv "EMACS_INHIBIT_AUTOMATIC_NATIVE_COMPILATION")) + (setq inhibit-native-compilation (getenv "EMACS_INHIBIT_NATIVE_COMPILATION")) (if command-line-processed (message internal--top-level-message) @@ -601,7 +600,7 @@ It is the default value of the variable `top-level'." ;; in this session. This is necessary if libgccjit is not ;; available on MS-Windows, but Emacs was built with ;; native-compilation support. - (setq inhibit-automatic-native-compilation t + (setq inhibit-native-compilation t comp-enable-subr-trampolines nil)) ;; Form `native-comp-eln-load-path'. diff --git a/lisp/subr.el b/lisp/subr.el index 9e6388987df..6282abc1b16 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -1895,7 +1895,7 @@ instead; it will indirectly limit the specpdl stack size as well.") (make-obsolete-variable 'max-specpdl-size nil "29.1") (make-obsolete-variable 'native-comp-deferred-compilation - 'inhibit-automatic-native-compilation "29.1") + 'inhibit-native-compilation "29.1") ;;;; Alternate names for functions - these are not being phased out. diff --git a/src/comp.c b/src/comp.c index 10cf7962ba1..88b871aaae8 100644 --- a/src/comp.c +++ b/src/comp.c @@ -5174,7 +5174,7 @@ maybe_defer_native_compilation (Lisp_Object function_name, return; if (!native_comp_deferred_compilation - || !NILP (Vinhibit_automatic_native_compilation) + || !NILP (Vinhibit_native_compilation) || noninteractive || !NILP (Vpurify_flag) || !COMPILEDP (definition) @@ -5678,13 +5678,12 @@ For internal use. */); doc: /* Non-nil when comp.el can be native compiled. For internal use. */); /* Compiler control customizes. */ - DEFVAR_LISP ("inhibit-automatic-native-compilation", - Vinhibit_automatic_native_compilation, + DEFVAR_LISP ("inhibit-native-compilation", Vinhibit_native_compilation, doc: /* If non-nil, inhibit automatic native compilation of loaded .elc files. After compilation, each function definition is updated to the native compiled one. */); - Vinhibit_automatic_native_compilation = Qnil; + Vinhibit_native_compilation = Qnil; DEFVAR_BOOL ("native-comp-deferred-compilation", native_comp_deferred_compilation, From c0681cd3477b6fce5e257ac720a32e09357ea157 Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Mon, 13 Feb 2023 10:19:31 +0100 Subject: [PATCH 02/24] Revert "Add new variable 'inhibit-native-compilation'" This reverts commit 5fec9182dbeffa88cef6651d8c798ef9665d6681. --- doc/lispref/compile.texi | 18 ------------------ etc/NEWS | 8 -------- lisp/emacs-lisp/comp.el | 35 ++++++++++++++++------------------- lisp/progmodes/elisp-mode.el | 2 +- lisp/startup.el | 7 ++----- lisp/subr.el | 3 --- src/comp.c | 8 -------- 7 files changed, 19 insertions(+), 62 deletions(-) diff --git a/doc/lispref/compile.texi b/doc/lispref/compile.texi index 8bb079b65df..0617b9c533c 100644 --- a/doc/lispref/compile.texi +++ b/doc/lispref/compile.texi @@ -981,24 +981,6 @@ whether native-compilation is available should use this predicate. This section documents the variables that control native-compilation. -@defvar inhibit-native-compilation -If your Emacs has support for native compilation, Emacs will (by -default) compile the Lisp files you're loading in the background, and -then install the native-compiled versions of the functions. If you -wish to disable this, you can set this variable to non-@code{nil}. If -you want to set it permanently, this should probably be done from the -early init file, since setting it in the normal init file is probably -too late. - -While setting this variable disables automatic compilation of Lisp -files, the compiler may still be invoked to install @dfn{trampolines} -if any built-in functions are redefined. However, these trampolines -will not get written to your cache directory. - -You can also use the @samp{EMACS_INHIBIT_NATIVE_COMPILATION} -environment variable to disable native compilation. -@end defvar - @defopt native-comp-speed This variable specifies the optimization level for native compilation. Its value should be a number between @minus{}1 and 3. Values between diff --git a/etc/NEWS b/etc/NEWS index 5ce18872f1a..8f344aa5764 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -199,14 +199,6 @@ load time. ** Native Compilation +++ -*** New variable 'inhibit-native-compilation'. -If set, Emacs will inhibit native compilation (and won't write -anything to the eln cache automatically). The variable is initialised -from the EMACS_INHIBIT_NATIVE_COMPILATION environment variable on -Emacs startup. - - ---- *** New command 'native-compile-prune-cache'. This command deletes old subdirectories of the eln cache (but not the ones for the current Emacs version). Note that subdirectories of the diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index ab6c8a8ea90..828e31c43bd 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -3803,25 +3803,22 @@ Return the trampoline if found or nil otherwise." (lexical-binding t)) (comp--native-compile form nil - ;; If we've disabled nativecomp, don't write the trampolines to - ;; the eln cache (but create them). - (and (not inhibit-native-compilation) - (cl-loop - for dir in (if native-compile-target-directory - (list (expand-file-name comp-native-version-dir - native-compile-target-directory)) - (comp-eln-load-path-eff)) - for f = (expand-file-name - (comp-trampoline-filename subr-name) - dir) - unless (file-exists-p dir) - do (ignore-errors - (make-directory dir t) - (cl-return f)) - when (file-writable-p f) - do (cl-return f) - finally (error "Cannot find suitable directory for output in \ -`native-comp-eln-load-path'")))))) + (cl-loop + for dir in (if native-compile-target-directory + (list (expand-file-name comp-native-version-dir + native-compile-target-directory)) + (comp-eln-load-path-eff)) + for f = (expand-file-name + (comp-trampoline-filename subr-name) + dir) + unless (file-exists-p dir) + do (ignore-errors + (make-directory dir t) + (cl-return f)) + when (file-writable-p f) + do (cl-return f) + finally (error "Cannot find suitable directory for output in \ +`native-comp-eln-load-path'"))))) ;; Some entry point support code. diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index 7ba2c38cb75..ba1183f686b 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -220,7 +220,7 @@ All commands in `lisp-mode-shared-map' are inherited by this map." Load the compiled code when finished. Use `emacs-lisp-byte-compile-and-load' in combination with -`inhibit-native-compilation' set to nil to achieve asynchronous +`native-comp-deferred-compilation' set to t to achieve asynchronous native compilation." (interactive nil emacs-lisp-mode) (emacs-lisp--before-compile-buffer) diff --git a/lisp/startup.el b/lisp/startup.el index b0a8eed9d38..240cfa30098 100644 --- a/lisp/startup.el +++ b/lisp/startup.el @@ -542,7 +542,7 @@ DIRS are relative." (setq comp--compilable t)) (defvar native-comp-eln-load-path) -(defvar inhibit-native-compilation) +(defvar native-comp-deferred-compilation) (defvar comp-enable-subr-trampolines) (defvar startup--original-eln-load-path nil @@ -579,9 +579,6 @@ the updated value." It sets `command-line-processed', processes the command-line, reads the initialization files, etc. It is the default value of the variable `top-level'." - ;; Allow disabling automatic .elc->.eln processing. - (setq inhibit-native-compilation (getenv "EMACS_INHIBIT_NATIVE_COMPILATION")) - (if command-line-processed (message internal--top-level-message) (setq command-line-processed t) @@ -600,7 +597,7 @@ It is the default value of the variable `top-level'." ;; in this session. This is necessary if libgccjit is not ;; available on MS-Windows, but Emacs was built with ;; native-compilation support. - (setq inhibit-native-compilation t + (setq native-comp-deferred-compilation nil comp-enable-subr-trampolines nil)) ;; Form `native-comp-eln-load-path'. diff --git a/lisp/subr.el b/lisp/subr.el index 6282abc1b16..a56aeab724a 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -1894,9 +1894,6 @@ activations. To prevent runaway recursion, use `max-lisp-eval-depth' instead; it will indirectly limit the specpdl stack size as well.") (make-obsolete-variable 'max-specpdl-size nil "29.1") -(make-obsolete-variable 'native-comp-deferred-compilation - 'inhibit-native-compilation "29.1") - ;;;; Alternate names for functions - these are not being phased out. diff --git a/src/comp.c b/src/comp.c index 88b871aaae8..7d67995fa87 100644 --- a/src/comp.c +++ b/src/comp.c @@ -5174,7 +5174,6 @@ maybe_defer_native_compilation (Lisp_Object function_name, return; if (!native_comp_deferred_compilation - || !NILP (Vinhibit_native_compilation) || noninteractive || !NILP (Vpurify_flag) || !COMPILEDP (definition) @@ -5678,13 +5677,6 @@ For internal use. */); doc: /* Non-nil when comp.el can be native compiled. For internal use. */); /* Compiler control customizes. */ - DEFVAR_LISP ("inhibit-native-compilation", Vinhibit_native_compilation, - doc: /* If non-nil, inhibit automatic native compilation of loaded .elc files. - -After compilation, each function definition is updated to the native -compiled one. */); - Vinhibit_native_compilation = Qnil; - DEFVAR_BOOL ("native-comp-deferred-compilation", native_comp_deferred_compilation, doc: /* If non-nil compile loaded .elc files asynchronously. From b6e2799aa1c3887c2995e115e6ff2f69d59f0e44 Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Mon, 13 Feb 2023 10:26:03 +0100 Subject: [PATCH 03/24] * Some more `inhibit-native-compile' clean-up * lisp/emacs-lisp/generate-lisp-file.el (generate-lisp-file-trailer): Use `native-comp-deferred-compilation'. --- lisp/emacs-lisp/comp.el | 4 +--- lisp/emacs-lisp/generate-lisp-file.el | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index 828e31c43bd..8a41989237e 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -4107,14 +4107,12 @@ the deferred compilation mechanism." data ;; So we return the compiled function. (native-elisp-load data))) - ;; We may have created a temporary file when we're being - ;; called with something other than a file as the argument. - ;; Delete it if we can. (when (and (not (stringp function-or-file)) (not output) comp-ctxt (comp-ctxt-output comp-ctxt) (file-exists-p (comp-ctxt-output comp-ctxt))) + ;; NOTE: Not sure if we want to remove this or being cautious. (cond ((eq 'windows-nt system-type) ;; We may still be using the temporary .eln file. (ignore-errors (delete-file (comp-ctxt-output comp-ctxt)))) diff --git a/lisp/emacs-lisp/generate-lisp-file.el b/lisp/emacs-lisp/generate-lisp-file.el index b2f67ab848d..167cdfbf826 100644 --- a/lisp/emacs-lisp/generate-lisp-file.el +++ b/lisp/emacs-lisp/generate-lisp-file.el @@ -103,7 +103,7 @@ if it's also byte-compiled)." (insert ";; no-byte-" "compile: t\n")) (unless autoloads (insert ";; no-update-autoloads: t\n")) - (when inhibit-native-compile + (unless native-comp-deferred-compilation (insert ";; no-native-" "compile: t\n")) (when coding (insert (format ";; coding: %s\n" From 1795839babcf8572a79aaee3c76ca5b357937a59 Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Mon, 13 Feb 2023 11:09:46 +0100 Subject: [PATCH 04/24] Support `comp-enable-subr-trampolines' as string value * src/comp.c (syms_of_comp): Update `comp-enable-subr-trampolines'. * lisp/emacs-lisp/comp.el (native-comp-never-optimize-functions) (comp--trampoline-abs-filename): Support `comp-enable-subr-trampolines' string value. * src/data.c (Ffset): Use Vcomp_enable_subr_trampolines now. --- lisp/emacs-lisp/comp.el | 39 +++++++++++++++++++++++---------------- src/comp.c | 5 ++++- src/data.c | 2 +- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index 8a41989237e..eeee66b3d1b 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -3782,6 +3782,28 @@ Return the trampoline if found or nil otherwise." when (file-exists-p filename) do (cl-return (native-elisp-load filename)))) +(defun comp--trampoline-abs-filename (subr-name) + "Return the absolute filename for a trampoline for SUBR-NAME." + (cl-loop + with dirs = (if (stringp comp-enable-subr-trampolines) + (list comp-enable-subr-trampolines) + (if native-compile-target-directory + (list (expand-file-name comp-native-version-dir + native-compile-target-directory)) + (comp-eln-load-path-eff))) + for dir in dirs + for f = (expand-file-name + (comp-trampoline-filename subr-name) + dir) + unless (file-exists-p dir) + do (ignore-errors + (make-directory dir t) + (cl-return f)) + when (file-writable-p f) + do (cl-return f) + finally (error "Cannot find suitable directory for output in \ +`native-comp-eln-load-path'"))) + (defun comp-trampoline-compile (subr-name) "Synthesize compile and return a trampoline for SUBR-NAME." (let* ((lambda-list (comp-make-lambda-list-from-subr @@ -3803,22 +3825,7 @@ Return the trampoline if found or nil otherwise." (lexical-binding t)) (comp--native-compile form nil - (cl-loop - for dir in (if native-compile-target-directory - (list (expand-file-name comp-native-version-dir - native-compile-target-directory)) - (comp-eln-load-path-eff)) - for f = (expand-file-name - (comp-trampoline-filename subr-name) - dir) - unless (file-exists-p dir) - do (ignore-errors - (make-directory dir t) - (cl-return f)) - when (file-writable-p f) - do (cl-return f) - finally (error "Cannot find suitable directory for output in \ -`native-comp-eln-load-path'"))))) + (comp--trampoline-abs-filename subr-name)))) ;; Some entry point support code. diff --git a/src/comp.c b/src/comp.c index 7d67995fa87..82224845bff 100644 --- a/src/comp.c +++ b/src/comp.c @@ -5858,12 +5858,15 @@ The last directory of this list is assumed to be the system one. */); dump reload. */ Vnative_comp_eln_load_path = Fcons (build_string ("../native-lisp/"), Qnil); - DEFVAR_BOOL ("comp-enable-subr-trampolines", comp_enable_subr_trampolines, + DEFVAR_LISP ("comp-enable-subr-trampolines", Vcomp_enable_subr_trampolines, doc: /* If non-nil, enable primitive trampoline synthesis. This makes Emacs respect redefinition or advises of primitive functions when they are called from Lisp code natively-compiled at `native-comp-speed' of 2. +If `comp-enable-subr-trampolines' is a string it specifies a directory +in which to deposit the trampoline. + By default, this is enabled, and when Emacs sees a redefined or advised primitive called from natively-compiled Lisp, it generates a trampoline for it on-the-fly. diff --git a/src/data.c b/src/data.c index bb4d1347d72..a43fa8991fe 100644 --- a/src/data.c +++ b/src/data.c @@ -855,7 +855,7 @@ DEFUN ("fset", Ffset, Sfset, 2, 2, 0, #ifdef HAVE_NATIVE_COMP register Lisp_Object function = XSYMBOL (symbol)->u.s.function; - if (comp_enable_subr_trampolines + if (!NILP (Vcomp_enable_subr_trampolines) && SUBRP (function) && !SUBR_NATIVE_COMPILEDP (function)) CALLN (Ffuncall, Qcomp_subr_trampoline_install, symbol); From abfd00e5c02ec0aed8bbac1eca0d0db1874f020a Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Mon, 13 Feb 2023 11:56:02 +0100 Subject: [PATCH 05/24] * lisp/emacs-lisp/comp.el (native-comp-never-optimize-functions): Improve doc --- lisp/emacs-lisp/comp.el | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index eeee66b3d1b..5077ca0aa1f 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -105,7 +105,12 @@ during bootstrap." ;; correctly (see comment in `advice--add-function'). DO NOT ;; REMOVE. macroexpand rename-buffer) - "Primitive functions to exclude from trampoline optimization." + "Primitive functions to exclude from trampoline optimization. + +Primitive functions included in this list will not be called +directly by the native code being compiled, this makes +tranpolines for those primitives not necessary in case of +function redefinition/advise." :type '(repeat symbol) :version "28.1") From 5d0912f1445e33f1ccf23a84f0dc6d08c4ee2b60 Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Mon, 13 Feb 2023 16:33:40 +0100 Subject: [PATCH 06/24] Rename comp-enable-subr-trampolines into native-comp-enable-subr-trampolines * src/data.c (Ffset): Rename comp-enable-subr-trampolines into native-comp-enable-subr-trampolines. * src/comp.c (syms_of_comp): Likewise. * lisp/subr.el (comp-enable-subr-trampolines): Make comp-enable-subr-trampolines obsolete. * lisp/startup.el (native-comp-enable-subr-trampolines) (normal-top-level): Rename comp-enable-subr-trampolines into native-comp-enable-subr-trampolines. * lisp/loadup.el (dump-mode): Likewise. * lisp/emacs-lisp/comp.el (comp-subr-trampoline-install) (comp--trampoline-abs-filename): Likewise. --- lisp/emacs-lisp/comp.el | 6 +++--- lisp/loadup.el | 2 +- lisp/startup.el | 4 ++-- lisp/subr.el | 4 ++++ src/comp.c | 3 ++- src/data.c | 2 +- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index 5077ca0aa1f..fc1862a45e8 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -700,7 +700,7 @@ Useful to hook into pass checkers.") ;;;###autoload (defun comp-subr-trampoline-install (subr-name) "Make SUBR-NAME effectively advice-able when called from native code." - (unless (or (null comp-enable-subr-trampolines) + (unless (or (null native-comp-enable-subr-trampolines) (memq subr-name native-comp-never-optimize-functions) (gethash subr-name comp-installed-trampolines-h)) (cl-assert (subr-primitive-p (symbol-function subr-name))) @@ -3790,8 +3790,8 @@ Return the trampoline if found or nil otherwise." (defun comp--trampoline-abs-filename (subr-name) "Return the absolute filename for a trampoline for SUBR-NAME." (cl-loop - with dirs = (if (stringp comp-enable-subr-trampolines) - (list comp-enable-subr-trampolines) + with dirs = (if (stringp native-comp-enable-subr-trampolines) + (list native-comp-enable-subr-trampolines) (if native-compile-target-directory (list (expand-file-name comp-native-version-dir native-compile-target-directory)) diff --git a/lisp/loadup.el b/lisp/loadup.el index 5c576861579..46b26750cd5 100644 --- a/lisp/loadup.el +++ b/lisp/loadup.el @@ -550,7 +550,7 @@ lost after dumping"))) (equal dump-mode "pdump")) ;; Don't enable this before bootstrap is completed, as the ;; compiler infrastructure may not be usable yet. - (setq comp-enable-subr-trampolines t)) + (setq native-comp-enable-subr-trampolines t)) (message "Dumping under the name %s" output) (condition-case () (delete-file output) diff --git a/lisp/startup.el b/lisp/startup.el index 240cfa30098..ddbb39df857 100644 --- a/lisp/startup.el +++ b/lisp/startup.el @@ -543,7 +543,7 @@ DIRS are relative." (defvar native-comp-eln-load-path) (defvar native-comp-deferred-compilation) -(defvar comp-enable-subr-trampolines) +(defvar native-comp-enable-subr-trampolines) (defvar startup--original-eln-load-path nil "Original value of `native-comp-eln-load-path'.") @@ -598,7 +598,7 @@ It is the default value of the variable `top-level'." ;; available on MS-Windows, but Emacs was built with ;; native-compilation support. (setq native-comp-deferred-compilation nil - comp-enable-subr-trampolines nil)) + native-comp-enable-subr-trampolines nil)) ;; Form `native-comp-eln-load-path'. (let ((path-env (getenv "EMACSNATIVELOADPATH"))) diff --git a/lisp/subr.el b/lisp/subr.el index a56aeab724a..56c8377da87 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -1894,6 +1894,10 @@ activations. To prevent runaway recursion, use `max-lisp-eval-depth' instead; it will indirectly limit the specpdl stack size as well.") (make-obsolete-variable 'max-specpdl-size nil "29.1") +(make-obsolete-variable 'comp-enable-subr-trampolines + 'native-comp-enable-subr-trampolines + "29.1") + ;;;; Alternate names for functions - these are not being phased out. diff --git a/src/comp.c b/src/comp.c index 82224845bff..ba3ed95bcce 100644 --- a/src/comp.c +++ b/src/comp.c @@ -5858,7 +5858,8 @@ The last directory of this list is assumed to be the system one. */); dump reload. */ Vnative_comp_eln_load_path = Fcons (build_string ("../native-lisp/"), Qnil); - DEFVAR_LISP ("comp-enable-subr-trampolines", Vcomp_enable_subr_trampolines, + DEFVAR_LISP ("native-comp-enable-subr-trampolines", + Vnative_comp_enable_subr_trampolines, doc: /* If non-nil, enable primitive trampoline synthesis. This makes Emacs respect redefinition or advises of primitive functions when they are called from Lisp code natively-compiled at `native-comp-speed' diff --git a/src/data.c b/src/data.c index a43fa8991fe..0f1d881e00b 100644 --- a/src/data.c +++ b/src/data.c @@ -855,7 +855,7 @@ DEFUN ("fset", Ffset, Sfset, 2, 2, 0, #ifdef HAVE_NATIVE_COMP register Lisp_Object function = XSYMBOL (symbol)->u.s.function; - if (!NILP (Vcomp_enable_subr_trampolines) + if (!NILP (Vnative_comp_enable_subr_trampolines) && SUBRP (function) && !SUBR_NATIVE_COMPILEDP (function)) CALLN (Ffuncall, Qcomp_subr_trampoline_install, symbol); From 8d8464bd5a98598e7a6fe63370545c7f07574926 Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Mon, 13 Feb 2023 16:37:43 +0100 Subject: [PATCH 07/24] Rename native-comp-deferred-compilation into native-comp-jit-compilation * src/comp.c (maybe_defer_native_compilation, syms_of_comp): Rename native-comp-deferred-compilation into native-comp-jit-compilation. * lisp/subr.el (native-comp-deferred-compilation): Mark native-comp-deferred-compilation as obsolete. * lisp/startup.el (native-comp-deferred-compilation) (normal-top-level): Rename native-comp-deferred-compilation into native-comp-jit-compilation. * lisp/progmodes/elisp-mode.el (emacs-lisp-native-compile-and-load): Likewise. * lisp/emacs-lisp/generate-lisp-file.el (generate-lisp-file-trailer): Likewise. --- lisp/emacs-lisp/generate-lisp-file.el | 2 +- lisp/progmodes/elisp-mode.el | 2 +- lisp/startup.el | 4 ++-- lisp/subr.el | 4 ++++ src/comp.c | 8 ++++---- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lisp/emacs-lisp/generate-lisp-file.el b/lisp/emacs-lisp/generate-lisp-file.el index 167cdfbf826..d878784ba32 100644 --- a/lisp/emacs-lisp/generate-lisp-file.el +++ b/lisp/emacs-lisp/generate-lisp-file.el @@ -103,7 +103,7 @@ if it's also byte-compiled)." (insert ";; no-byte-" "compile: t\n")) (unless autoloads (insert ";; no-update-autoloads: t\n")) - (unless native-comp-deferred-compilation + (unless native-comp-jit-compilation (insert ";; no-native-" "compile: t\n")) (when coding (insert (format ";; coding: %s\n" diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index ba1183f686b..1c339d08148 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -220,7 +220,7 @@ All commands in `lisp-mode-shared-map' are inherited by this map." Load the compiled code when finished. Use `emacs-lisp-byte-compile-and-load' in combination with -`native-comp-deferred-compilation' set to t to achieve asynchronous +`native-comp-jit-compilation' set to t to achieve asynchronous native compilation." (interactive nil emacs-lisp-mode) (emacs-lisp--before-compile-buffer) diff --git a/lisp/startup.el b/lisp/startup.el index ddbb39df857..b0f019d704e 100644 --- a/lisp/startup.el +++ b/lisp/startup.el @@ -542,7 +542,7 @@ DIRS are relative." (setq comp--compilable t)) (defvar native-comp-eln-load-path) -(defvar native-comp-deferred-compilation) +(defvar native-comp-jit-compilation) (defvar native-comp-enable-subr-trampolines) (defvar startup--original-eln-load-path nil @@ -597,7 +597,7 @@ It is the default value of the variable `top-level'." ;; in this session. This is necessary if libgccjit is not ;; available on MS-Windows, but Emacs was built with ;; native-compilation support. - (setq native-comp-deferred-compilation nil + (setq native-comp-jit-compilation nil native-comp-enable-subr-trampolines nil)) ;; Form `native-comp-eln-load-path'. diff --git a/lisp/subr.el b/lisp/subr.el index 56c8377da87..db33483f509 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -1898,6 +1898,10 @@ instead; it will indirectly limit the specpdl stack size as well.") 'native-comp-enable-subr-trampolines "29.1") +(make-obsolete-variable 'native-comp-deferred-compilation + 'native-comp-jit-compilation + "29.1") + ;;;; Alternate names for functions - these are not being phased out. diff --git a/src/comp.c b/src/comp.c index ba3ed95bcce..019d1e78fff 100644 --- a/src/comp.c +++ b/src/comp.c @@ -5173,7 +5173,7 @@ maybe_defer_native_compilation (Lisp_Object function_name, if (!load_gccjit_if_necessary (false)) return; - if (!native_comp_deferred_compilation + if (!native_comp_jit_compilation || noninteractive || !NILP (Vpurify_flag) || !COMPILEDP (definition) @@ -5677,13 +5677,13 @@ For internal use. */); doc: /* Non-nil when comp.el can be native compiled. For internal use. */); /* Compiler control customizes. */ - DEFVAR_BOOL ("native-comp-deferred-compilation", - native_comp_deferred_compilation, + DEFVAR_BOOL ("native-comp-jit-compilation", + native_comp_jit_compilation, doc: /* If non-nil compile loaded .elc files asynchronously. After compilation, each function definition is updated to the native compiled one. */); - native_comp_deferred_compilation = true; + native_comp_jit_compilation = true; DEFSYM (Qnative_comp_speed, "native-comp-speed"); DEFSYM (Qnative_comp_debug, "native-comp-debug"); From 95692f6754c3a8f55a90df2d6f7ce62be55cdcfc Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Mon, 13 Feb 2023 16:40:02 +0100 Subject: [PATCH 08/24] Rename native-comp-deferred-compilation-deny-list * lisp/emacs-lisp/comp.el (native-comp-jit-compilation-deny-list) (native-compile-async-skip-p): Rename native-comp-deferred-compilation-deny-list into native-comp-jit-compilation-deny-list. (native-comp-deferred-compilation-deny-list): Mark it obsolete. --- lisp/emacs-lisp/comp.el | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index fc1862a45e8..ed706feb923 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -85,13 +85,17 @@ This is intended for debugging the compiler itself. :type 'boolean :version "28.1") -(defcustom native-comp-deferred-compilation-deny-list +(defcustom native-comp-jit-compilation-deny-list '() "List of regexps to exclude matching files from deferred native compilation. Files whose names match any regexp are excluded from native compilation." :type '(repeat regexp) :version "28.1") +(make-obsolete-variable 'native-comp-deferred-compilation-deny-list + 'native-comp-jit-compilation-deny-list + "29.1") + (defcustom native-comp-bootstrap-deny-list '() "List of regexps to exclude files from native compilation during bootstrap. @@ -4144,11 +4148,11 @@ LOAD and SELECTOR work as described in `native--compile-async'." (t (error "SELECTOR must be a function a regexp or nil"))) ;; Also exclude files from deferred compilation if ;; any of the regexps in - ;; `native-comp-deferred-compilation-deny-list' matches. + ;; `native-comp-jit-compilation-deny-list' matches. (and (eq load 'late) (cl-some (lambda (re) (string-match-p re file)) - native-comp-deferred-compilation-deny-list)))) + native-comp-jit-compilation-deny-list)))) (defun native--compile-async (files &optional recursively load selector) ;; BEWARE, this function is also called directly from C. From 1a64f326e0a8b86768031ac688ded9c863ff759c Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Mon, 13 Feb 2023 17:00:31 +0100 Subject: [PATCH 09/24] * Fix previous change * lisp/emacs-lisp/generate-lisp-file.el (generate-lisp-file-trailer): Fix previous change b6e2799aa1c. --- lisp/emacs-lisp/generate-lisp-file.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/emacs-lisp/generate-lisp-file.el b/lisp/emacs-lisp/generate-lisp-file.el index d878784ba32..b2f67ab848d 100644 --- a/lisp/emacs-lisp/generate-lisp-file.el +++ b/lisp/emacs-lisp/generate-lisp-file.el @@ -103,7 +103,7 @@ if it's also byte-compiled)." (insert ";; no-byte-" "compile: t\n")) (unless autoloads (insert ";; no-update-autoloads: t\n")) - (unless native-comp-jit-compilation + (when inhibit-native-compile (insert ";; no-native-" "compile: t\n")) (when coding (insert (format ";; coding: %s\n" From ce4a066ed1ea07f651f439132017db8ceb32779c Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Tue, 14 Feb 2023 11:21:45 +0100 Subject: [PATCH 10/24] * Generate trampolines in a temporary directory if no other option is viable * lisp/emacs-lisp/comp.el (comp--trampoline-abs-filename): Use temporary file if no other option is viable. --- lisp/emacs-lisp/comp.el | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index ed706feb923..a6b9b3f57ea 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -3800,18 +3800,22 @@ Return the trampoline if found or nil otherwise." (list (expand-file-name comp-native-version-dir native-compile-target-directory)) (comp-eln-load-path-eff))) + with rel-filename = (comp-trampoline-filename subr-name) for dir in dirs - for f = (expand-file-name - (comp-trampoline-filename subr-name) - dir) + for abs-filename = (expand-file-name rel-filename dir) unless (file-exists-p dir) do (ignore-errors (make-directory dir t) - (cl-return f)) - when (file-writable-p f) - do (cl-return f) - finally (error "Cannot find suitable directory for output in \ -`native-comp-eln-load-path'"))) + (cl-return abs-filename)) + when (file-writable-p abs-filename) + do (cl-return abs-filename) + ;; Default to some temporary directory if no better option was + ;; found. + finally (cl-return + (expand-file-name + (make-temp-file-internal (file-name-sans-extension rel-filename) + 0 ".eln" nil) + temporary-file-directory)))) (defun comp-trampoline-compile (subr-name) "Synthesize compile and return a trampoline for SUBR-NAME." From b44a7ff85dc8074735c5a8baa1fdea9d47c35ffa Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 17 Feb 2023 09:40:32 +0200 Subject: [PATCH 11/24] Allow 'icon-title-format' to have the value t * src/xdisp.c (gui_consider_frame_title, syms_of_xdisp): If the value of 'icon-title-format' is t, use 'frame-title-format' instead. (Bug#61496) * etc/NEWS: * doc/lispref/frames.texi (Frame Titles): Document the new handling of the value t. (Basic Parameters): Fix the documentation of the 'title' and 'name' frame parameters. --- doc/lispref/frames.texi | 40 +++++++++++++++++++++++++++------------- etc/NEWS | 7 +++++++ src/xdisp.c | 11 +++++++---- 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/doc/lispref/frames.texi b/doc/lispref/frames.texi index 68f31e500bb..638b759ff13 100644 --- a/doc/lispref/frames.texi +++ b/doc/lispref/frames.texi @@ -1474,19 +1474,24 @@ in this frame. Its value is @code{color}, @code{grayscale} or @vindex title@r{, a frame parameter} @item title -If a frame has a non-@code{nil} title, it appears in the window +If a frame has a non-@code{nil} title, that title appears in the window system's title bar at the top of the frame, and also in the mode line of windows in that frame if @code{mode-line-frame-identification} uses @samp{%F} (@pxref{%-Constructs}). This is normally the case when Emacs is not using a window system, and can only display one frame at -a time. @xref{Frame Titles}. +a time. When Emacs is using a window system, this parameter, if +non-@code{nil}, overrides the title determined by the @code{name} +parameter and the implicit title calculated according to +@code{frame-title-format}. It also overrides the title determined by +@code{icon-title-format} for iconified frames. @xref{Frame Titles}. @vindex name@r{, a frame parameter} @item name -The name of the frame. The frame name serves as a default for the frame -title, if the @code{title} parameter is unspecified or @code{nil}. If -you don't specify a name, Emacs sets the frame name automatically -(@pxref{Frame Titles}). +The name of the frame. If you don't specify a name via this +parameter, Emacs sets the frame name automatically, as specified by +@code{frame-title-format} and @code{icon-title-format}, and that is +the frame's title that will appear on display when Emacs uses a window +system (unless the @code{title} parameter overrides it). If you specify the frame name explicitly when you create the frame, the name is also used (instead of the name of the Emacs executable) when @@ -2630,17 +2635,26 @@ frame name automatically based on a template stored in the variable frame is redisplayed. @defvar frame-title-format -This variable specifies how to compute a name for a frame when you have -not explicitly specified one. The variable's value is actually a mode +This variable specifies how to compute a name for a frame when you +have not explicitly specified one (via the frame's parameters; +@pxref{Basic Parameters}). The variable's value is actually a mode line construct, just like @code{mode-line-format}, except that the -@samp{%c}, @samp{%C}, and @samp{%l} constructs are ignored. @xref{Mode Line -Data}. +@samp{%c}, @samp{%C}, and @samp{%l} constructs are ignored. +@xref{Mode Line Data}. @end defvar @defvar icon-title-format -This variable specifies how to compute the name for an iconified frame, -when you have not explicitly specified the frame title. This title -appears in the icon itself. +This variable specifies how to compute the name for an iconified frame +when you have not explicitly specified the frame's name via the +frame's parameters. The resulting title appears in the frame's icon +itself. If the value is a string, is should be a mode line construct +like that of @code{frame-title-format}. The value can also be +@code{t}, which means to use @code{frame-title-format} instead; this +avoids problems with some window managers and desktop environments, +where a change in a frame's title (when a frame is iconified) is +interpreted as a request to raise the frame and/or give it input +focus. The default is a string identical to the default value of +@code{frame-title-format}. @end defvar @defvar multiple-frames diff --git a/etc/NEWS b/etc/NEWS index 35063678f58..133c07e56df 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1202,6 +1202,13 @@ the most recently deleted frame. With a numerical prefix argument between 1 and 16, where 1 is the most recently deleted frame, undelete the corresponding deleted frame. ++++ +*** The variable 'icon-title-format' can now have the value t. +That value means to use 'frame-title-format' for iconified frames. +This is useful with some window managers and desktop environments +which treat changes in frame's title as requests to raise the frame +and/or give it input focus. + ** Tab Bars and Tab Lines --- diff --git a/src/xdisp.c b/src/xdisp.c index 5c5ecaa2bcb..1f630de7586 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -13424,7 +13424,8 @@ gui_consider_frame_title (Lisp_Object frame) Fselect_window (f->selected_window, Qt); set_buffer_internal_1 (XBUFFER (XWINDOW (f->selected_window)->contents)); - fmt = FRAME_ICONIFIED_P (f) ? Vicon_title_format : Vframe_title_format; + fmt = (FRAME_ICONIFIED_P (f) && !EQ (Vicon_title_format, Qt) + ? Vicon_title_format : Vframe_title_format); mode_line_target = MODE_LINE_TITLE; title_start = MODE_LINE_NOPROP_LEN (0); @@ -36608,9 +36609,11 @@ which no explicit name has been set (see `modify-frame-parameters'). */); DEFVAR_LISP ("icon-title-format", Vicon_title_format, doc: /* Template for displaying the title bar of an iconified frame. \(Assuming the window manager supports this feature.) -This variable has the same structure as `mode-line-format' (which see), -and is used only on frames for which no explicit name has been set -\(see `modify-frame-parameters'). */); +If the value is a string, it should have the same structure +as `mode-line-format' (which see), and is used only on frames +for which no explicit name has been set \(see `modify-frame-parameters'). +If the value is t, that means use `frame-title-format' for +iconified frames. */); /* Do not nest calls to pure_list. This works around a bug in Oracle Developer Studio 12.6. */ Lisp_Object icon_title_name_format From a555abc56d5270cebe94f904189526d7ac433a94 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 17 Feb 2023 10:27:39 +0200 Subject: [PATCH 12/24] Fix order of faces in 'face-list' * lisp/faces.el (frame-face-alist, face-list): Sort faces in decreasing order of face IDs. Patch by Brennan Vincent . (Bug#61521) Copyright-paperwork-exempt: yes --- lisp/faces.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lisp/faces.el b/lisp/faces.el index 4933b495a6c..d1a7881e396 100644 --- a/lisp/faces.el +++ b/lisp/faces.el @@ -191,7 +191,7 @@ For internal use only." (let ((face-id (car (gethash face face--new-frame-defaults)))) (push `(,face-id ,face . ,spec) faces))) (frame--face-hash-table frame)) - (mapcar #'cdr (sort faces (lambda (f1 f2) (< (car f1) (car f2))))))) + (mapcar #'cdr (sort faces (lambda (f1 f2) (> (car f1) (car f2))))))) (defun face-list () "Return a list of all defined faces." @@ -199,7 +199,7 @@ For internal use only." (maphash (lambda (face spec) (push `(,(car spec) . ,face) faces)) face--new-frame-defaults) - (mapcar #'cdr (sort faces (lambda (f1 f2) (< (car f1) (car f2))))))) + (mapcar #'cdr (sort faces (lambda (f1 f2) (> (car f1) (car f2))))))) (defun make-face (face) "Define a new face with name FACE, a symbol. From 8aad8d75aa94d0d07f6abb0f0e04d7634d0d1d4a Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 17 Feb 2023 16:15:51 +0200 Subject: [PATCH 13/24] ; Improve and update documentation of native compilation * src/comp.c (syms_of_comp) : Doc fixes. * lisp/emacs-lisp/comp.el (native-comp-never-optimize-functions): Doc fix. * doc/lispref/compile.texi (Native-Compilation Variables): Document 'native-comp-jit-compilation' and 'native-comp-enable-subr-trampolines'. --- doc/lispref/compile.texi | 68 +++++++++++++++++++++++++++++++- lisp/emacs-lisp/comp.el | 5 +-- src/comp.c | 85 +++++++++++++++++++++------------------- 3 files changed, 113 insertions(+), 45 deletions(-) diff --git a/doc/lispref/compile.texi b/doc/lispref/compile.texi index 0617b9c533c..cdbf64036da 100644 --- a/doc/lispref/compile.texi +++ b/doc/lispref/compile.texi @@ -849,7 +849,12 @@ from writing its results, the @file{*.eln} files, into a subdirectory of @code{user-emacs-directory} (@pxref{Init File}). You can do that by either changing the value of @code{native-comp-eln-load-path} (@pxref{Native-Compilation Variables}) or by temporarily pointing the -@env{HOME} environment variable to a non-existing directory. +@env{HOME} environment variable to a non-existing directory. Note +that the latter technique might still produce a small number of +@file{*.eln} files if Emacs needs to generate @dfn{trampolines}, which +are used if Lisp primitives are advised or redefined in your Lisp code +that is being natively compiled. @xref{Native-Compilation Variables, +trampolines}. @menu * Native-Compilation Functions:: Functions to natively-compile Lisp. @@ -1075,3 +1080,64 @@ The directories in this list are also used for writing the specifically, Emacs will write these files into the first writable directory in the list. Thus, you can control where native-compilation stores the results by changing the value of this variable. + +@cindex disable asynchronous native compilation +@cindex inhibit asynchronous native compilation +@cindex asynchronous native compilation, disable +@defvar native-comp-jit-compilation +This variable, if non-@code{nil}, enables asynchronous (a.k.a.@: +@dfn{just-in-time}, or @acronym{JIT}) native compilation of the +@file{*.elc} files loaded by Emacs for which the corresponding +@file{*.eln} files do not already exist. This JIT compilation uses +separate Emacs sub-processes running in batch mode, according to the +value of @code{native-comp-async-jobs-number}. When the JIT +compilation of a Lisp file finishes successfully, the resulting +@file{.eln} file is loaded and its code replaces the definition of +functions provided by the @file{.elc} file. +@end defvar + +@cindex trampolines, in native compilation + Setting the value of @code{native-comp-jit-compilation} to@code{nil} +disables JIT native compilation. However, even when JIT native +compilation is disabled, Emacs might still need to start asynchronous +native compilation subprocesses to produce @dfn{trampolines}. To +control this, use a separate variable, described below. + +@defvar native-comp-enable-subr-trampolines +This variable controls generation of trampolines. A trampoline is a +small piece of native code required to allow calling Lisp primitives, +which were advised or redefined, from Lisp code that was +natively-compiled with @code{native-comp-speed} set to 2 or greater. +Emacs stores the generated trampolines on separate @file{*.eln} files. +By default, this variable's value is @code{t}, which enables the +generation of trampoline files; setting it to @code{nil} disables the +generation of trampolines. Note that if a trampoline needed for +advising or redefining a primitive is not available and cannot be +generated, calls to that primitive from natively-compiled Lisp will +ignore redefinitions and advices, and will behave as if the primitive +was called directly from C. Therefore, we don't recommend disabling +the trampoline generation, unless you know that all the trampolines +needed by your Lisp programs are already compiled and accessible to +Emacs. + +The value of this variable can also be a string, in which case it is +interpreted as the name of a directory in which to store the generated +trampoline @file{*.eln} files, overriding the directories specified by +@code{native-comp-eln-load-path}. This is useful if you want the +trampolines to be generated as needed, but don't want to store them +under the user's @env{HOME} directory or the other public directories +where @file{*.eln} files are kept. However, unlike with directories +in @code{native-comp-eln-load-path}, the trampolines will be stored in +the directory given by the value of this variable, not in its +version-specific subdirectory. + +If this variable is non-@code{nil}, and Emacs needs to produce a +trampoline, but it cannot find any writable directory to store the +trampoline, it will store it inside @code{temporary-file-directory} +(@pxref{Unique File Names}). + +Trampolines produced when no writable directory is found to store +them, or when this variable is a string, will only be available for +the duration of the current Emacs session, because Emacs doesn't look +for trampolines in either of these places. +@end defvar diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index a6b9b3f57ea..2d9cad6d98c 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -112,9 +112,8 @@ during bootstrap." "Primitive functions to exclude from trampoline optimization. Primitive functions included in this list will not be called -directly by the native code being compiled, this makes -tranpolines for those primitives not necessary in case of -function redefinition/advise." +directly by the natively-compiled code, which makes trampolines for +those primitives unnecessary in case of function redefinition/advice." :type '(repeat symbol) :version "28.1") diff --git a/src/comp.c b/src/comp.c index 019d1e78fff..beaf443a0f7 100644 --- a/src/comp.c +++ b/src/comp.c @@ -5670,19 +5670,17 @@ syms_of_comp (void) { #ifdef HAVE_NATIVE_COMP DEFVAR_LISP ("comp--delayed-sources", Vcomp__delayed_sources, - doc: /* List of sources to be native-compiled when startup is finished. + doc: /* List of sources to be native-compiled when startup is finished. For internal use. */); - DEFVAR_BOOL ("comp--compilable", - comp__compilable, - doc: /* Non-nil when comp.el can be native compiled. + DEFVAR_BOOL ("comp--compilable", comp__compilable, + doc: /* Non-nil when comp.el can be native compiled. For internal use. */); /* Compiler control customizes. */ - DEFVAR_BOOL ("native-comp-jit-compilation", - native_comp_jit_compilation, - doc: /* If non-nil compile loaded .elc files asynchronously. + DEFVAR_BOOL ("native-comp-jit-compilation", native_comp_jit_compilation, + doc: /* If non-nil, compile loaded .elc files asynchronously. -After compilation, each function definition is updated to the native -compiled one. */); +After compilation, each function definition is updated to use the +natively-compiled one. */); native_comp_jit_compilation = true; DEFSYM (Qnative_comp_speed, "native-comp-speed"); @@ -5827,31 +5825,34 @@ compiled one. */); /* FIXME should be initialized but not here... Plus this don't have to be necessarily exposed to lisp but can easy debug for now. */ DEFVAR_LISP ("comp-subr-list", Vcomp_subr_list, - doc: /* List of all defined subrs. */); + doc: /* List of all defined subrs. */); DEFVAR_LISP ("comp-abi-hash", Vcomp_abi_hash, - doc: /* String signing the .eln files ABI. */); + doc: /* String signing the .eln files ABI. */); Vcomp_abi_hash = Qnil; DEFVAR_LISP ("comp-native-version-dir", Vcomp_native_version_dir, - doc: /* Directory in use to disambiguate eln compatibility. */); + doc: /* Directory in use to disambiguate eln compatibility. */); Vcomp_native_version_dir = Qnil; DEFVAR_LISP ("comp-deferred-pending-h", Vcomp_deferred_pending_h, - doc: /* Hash table symbol-name -> function-value. + doc: /* Hash table symbol-name -> function-value. For internal use. */); Vcomp_deferred_pending_h = CALLN (Fmake_hash_table, QCtest, Qeq); DEFVAR_LISP ("comp-eln-to-el-h", Vcomp_eln_to_el_h, - doc: /* Hash table eln-filename -> el-filename. */); + doc: /* Hash table eln-filename -> el-filename. */); Vcomp_eln_to_el_h = CALLN (Fmake_hash_table, QCtest, Qequal); DEFVAR_LISP ("native-comp-eln-load-path", Vnative_comp_eln_load_path, - doc: /* List of eln cache directories. + doc: /* List of directories to look for natively-compiled *.eln files. -If a directory is non absolute it is assumed to be relative to -`invocation-directory'. -`comp-native-version-dir' value is used as a sub-folder name inside -each eln cache directory. -The last directory of this list is assumed to be the system one. */); +The *.eln files are actually looked for in a version-specific +subdirectory of each directory in this list. That subdirectory +is determined by the value of `comp-native-version-dir'. +If the name of a directory in this list is not absolute, it is +assumed to be relative to `invocation-directory'. +The last directory of this list is assumed to be the one holding +the system *.eln files, which are the files produced when building +Emacs. */); /* Temporary value in use for bootstrap. We can't do better as `invocation-directory' is still unset, will be fixed up during @@ -5860,45 +5861,47 @@ The last directory of this list is assumed to be the system one. */); DEFVAR_LISP ("native-comp-enable-subr-trampolines", Vnative_comp_enable_subr_trampolines, - doc: /* If non-nil, enable primitive trampoline synthesis. -This makes Emacs respect redefinition or advises of primitive functions -when they are called from Lisp code natively-compiled at `native-comp-speed' -of 2. + doc: /* If non-nil, enable generation of trampolines for calling primitives. +Trampolines are needed so that Emacs respects redefinition or advice of +primitive functions when they are called from Lisp code natively-compiled +at `native-comp-speed' of 2. -If `comp-enable-subr-trampolines' is a string it specifies a directory -in which to deposit the trampoline. - -By default, this is enabled, and when Emacs sees a redefined or advised +By default, the value is t, and when Emacs sees a redefined or advised primitive called from natively-compiled Lisp, it generates a trampoline for it on-the-fly. -Disabling this, when a trampoline for a redefined or advised primitive is -not available from previous compilations, means that such redefinition -or advise will not have effect on calls from natively-compiled Lisp code. -That is, calls to primitives without existing trampolines from -natively-compiled Lisp will behave as if the primitive was called -directly from C. */); +If the value is a file name (a string), it specifies the directory in +which to deposit the generated trampolines, overriding the directories +in `native-comp-eln-load-path'. + +When this variable is nil, generation of trampolines is disabled. + +Disabling the generation of trampolines, when a trampoline for a redefined +or advised primitive is not already available from previous compilations, +means that such redefinition or advice will not have effect when calling +primitives from natively-compiled Lisp code. That is, calls to primitives +without existing trampolines from natively-compiled Lisp will behave as if +the primitive was called directly from C, and will ignore its redefinition +and advice. */); DEFVAR_LISP ("comp-installed-trampolines-h", Vcomp_installed_trampolines_h, - doc: /* Hash table subr-name -> installed trampoline. -This is used to prevent double trampoline instantiation but also to + doc: /* Hash table subr-name -> installed trampoline. +This is used to prevent double trampoline instantiation, and also to protect the trampolines against GC. */); Vcomp_installed_trampolines_h = CALLN (Fmake_hash_table); DEFVAR_LISP ("comp-no-native-file-h", V_comp_no_native_file_h, - doc: /* Files for which no deferred compilation has to be performed. + doc: /* Files for which no deferred compilation should be performed. These files' compilation should not be deferred because the bytecode version was explicitly requested by the user during load. For internal use. */); V_comp_no_native_file_h = CALLN (Fmake_hash_table, QCtest, Qequal); DEFVAR_BOOL ("comp-file-preloaded-p", comp_file_preloaded_p, - doc: /* When non-nil assume the file being compiled to -be preloaded. */); + doc: /* When non-nil, assume the file being compiled to be preloaded. */); DEFVAR_LISP ("comp-loaded-comp-units-h", Vcomp_loaded_comp_units_h, - doc: /* Hash table recording all loaded compilation units. -file -> CU. */); + doc: /* Hash table recording all loaded compilation units, file -> CU. */); Vcomp_loaded_comp_units_h = CALLN (Fmake_hash_table, QCweakness, Qvalue, QCtest, Qequal); From 09fad246de82c720295a8708657d61407bb968c3 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Fri, 17 Feb 2023 15:23:19 +0100 Subject: [PATCH 14/24] * lisp/calc/calc.el (calc-mode): Improve docstring. --- lisp/calc/calc.el | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lisp/calc/calc.el b/lisp/calc/calc.el index 39e54c89e06..f129552c9a4 100644 --- a/lisp/calc/calc.el +++ b/lisp/calc/calc.el @@ -1282,16 +1282,17 @@ the trail buffer." (defun calc-mode () "Calculator major mode. -This is an RPN calculator featuring arbitrary-precision integer, rational, -floating-point, complex, matrix, and symbolic arithmetic. +This is a Reverse Polish notation (RPN) calculator featuring +arbitrary-precision integer, rational, floating-point, complex, +matrix, and symbolic arithmetic. RPN calculation: 2 RET 3 + produces 5. Algebraic style: \\=' 2+3 RET produces 5. Basic operators are +, -, *, /, ^, & (reciprocal), % (modulo), n (change-sign). -Press ? repeatedly for more complete help. Press `h i' to read the -Calc manual on-line, `h s' to read the summary, or `h t' for the tutorial. +Press \\`?' repeatedly for more complete help. Press \\`h i' to read the +Calc manual, \\`h s' to read the summary, or \\`h t' for the tutorial. Notations: 3.14e6 3.14 * 10^6 _23 negative number -23 (or type `23 n') From 1c7d7623781cd7ee5d2ba7c1303e476592ccaee1 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 17 Feb 2023 16:57:09 +0200 Subject: [PATCH 15/24] ; Minor copyedit of NEWS wrt *-ts-modes * etc/NEWS: Add desktop.el caveat for when restarting after trying the *-ts-modes. Suggested by Alan Mackenzie . --- etc/NEWS | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 6d3d849a757..b140d1dcbfd 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -3251,8 +3251,10 @@ for which a "built-in" mode would be turned on. For example: (add-to-list 'major-mode-remap-alist '(ruby-mode . ruby-ts-mode)) If you try these modes and don't like them, you can go back to the -"built-in" modes by restarting Emacs. But please tell us why you -didn't like the tree-sitter based modes, so that we could try +"built-in" modes by restarting Emacs. (If you use desktop.el to save +and restore Emacs sessions, make sure no buffer under these modes is +recorded in the desktop file, before restarting.) But please tell us +why you didn't like the tree-sitter based modes, so that we could try improving them. Each major mode based on tree-sitter needs a language grammar library, From 5b34fc07085a4ec636124756d09dcc3be8414eb8 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Fri, 17 Feb 2023 17:06:53 +0200 Subject: [PATCH 16/24] * lisp/treesit.el (treesit-node-at): Update docstring (bug#61529). --- lisp/treesit.el | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lisp/treesit.el b/lisp/treesit.el index 6015e78bbd5..09531b838a1 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -166,10 +166,13 @@ parser in `treesit-parser-list', or nil if there is no parser." A leaf node is a node that doesn't have any child nodes. The returned node's span covers POS: the node's beginning is before -or at POS, and the node's end is at or after POS. +or at POS, and the node's end is after POS. -If no leaf node's span covers POS (e.g., POS is on whitespace -between two leaf nodes), return the first leaf node after POS. +If no such node exists, but there's a leaf node which ends at POS, +return that node. + +Otherwise (e.g., when POS is on whitespace between two leaf +nodes), return the first leaf node after POS. If there is no leaf node after POS, return the first leaf node before POS. From 0a5615669a4f5d7e2db3c4117f3c2440e9c4cfd5 Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Fri, 17 Feb 2023 14:21:49 -0800 Subject: [PATCH 17/24] Don't completely clip into visible range in treesit_record_change (Bug#61369) From min (visible_end, max (visible_beg, new_end_byte)) - visible_beg to max (visible_beg, new_end_byte) - visible_beg * src/treesit.c (treesit_record_change): We don't clip the new end into the visible range anymore. If you think of it, when inserting in a narrowed region, the visible region is always extended to accommodate more text, rather than pushing text at the end to keep the size of the visible region. --- src/treesit.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/treesit.c b/src/treesit.c index cab2f0d5354..08119f149b7 100644 --- a/src/treesit.c +++ b/src/treesit.c @@ -770,7 +770,8 @@ treesit_record_change (ptrdiff_t start_byte, ptrdiff_t old_end_byte, treesit_check_parser (lisp_parser); TSTree *tree = XTS_PARSER (lisp_parser)->tree; /* See comment (ref:visible-beg-null) if you wonder why we don't - update visible_beg/end when tree is NULL. */ + update visible_beg/end when tree is NULL. */ + if (tree != NULL) { eassert (start_byte <= old_end_byte); @@ -794,8 +795,14 @@ treesit_record_change (ptrdiff_t start_byte, ptrdiff_t old_end_byte, ptrdiff_t old_end_offset = (min (visible_end, max (visible_beg, old_end_byte)) - visible_beg); - ptrdiff_t new_end_offset = (min (visible_end, - max (visible_beg, new_end_byte)) + /* We don't clip new_end_offset under visible_end, because + inserting in narrowed region always extends the visible + region. If we clip new_end_offset here, and re-add the + clipped "tail" in treesit_sync_visible_region later, + while it is technically equivalent, tree-sitter's + incremental parsing algorithm doesn't seem to like it + (bug#61369). */ + ptrdiff_t new_end_offset = (max (visible_beg, new_end_byte) - visible_beg); eassert (start_offset <= old_end_offset); eassert (start_offset <= new_end_offset); @@ -817,11 +824,13 @@ treesit_record_change (ptrdiff_t start_byte, ptrdiff_t old_end_byte, /* Move forward. */ visi_beg_delta = (old_end_byte < visible_beg ? new_end_byte - old_end_byte : 0); + XTS_PARSER (lisp_parser)->visible_beg = visible_beg + visi_beg_delta; XTS_PARSER (lisp_parser)->visible_end = (visible_end + visi_beg_delta + (new_end_offset - old_end_offset)); + eassert (XTS_PARSER (lisp_parser)->visible_beg >= 0); eassert (XTS_PARSER (lisp_parser)->visible_beg <= XTS_PARSER (lisp_parser)->visible_end); From 18e96ed7c8a388d5aee4be37c8f268fb826fc1d2 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Sat, 18 Feb 2023 00:50:29 +0200 Subject: [PATCH 18/24] project.el: Extract backend->marker association for a defvar * lisp/progmodes/project.el (project-vc-backend-markers-alist): Extract from 'project-try-vc'. (project-try-vc): Update accordingly (bug#61577). --- lisp/progmodes/project.el | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 2343adf4698..46bafc55777 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -494,6 +494,22 @@ files related to the current buffer. The directory names should be absolute. Used in the VC-aware project backend implementation of `project-external-roots'.") +(defvar project-vc-backend-markers-alist + `((Git . ".git") + (Hg . ".hg") + (Bzr . ".bzr") + ;; See the comment above `vc-svn-admin-directory' for why we're + ;; duplicating the definition. + (SVN . ,(if (and (memq system-type '(cygwin windows-nt ms-dos)) + (getenv "SVN_ASP_DOT_NET_HACK")) + "_svn" + ".svn")) + (DARCS . "_darcs") + (Fossil . ".fslckout")) + "Associative list assigning root markers to VC backend symbols. + +See `project-vc-extra-root-markers' for the marker value format.") + (defun project-try-vc (dir) (defvar vc-svn-admin-directory) (require 'vc-svn) @@ -501,17 +517,11 @@ project backend implementation of `project-external-roots'.") ;; `project-vc-merge-submodules' or `project-vc-extra-root-markers' ;; changes. (or (vc-file-getprop dir 'project-vc) - (let* ((backend-markers-alist `((Git . ".git") - (Hg . ".hg") - (Bzr . ".bzr") - (SVN . ,vc-svn-admin-directory) - (DARCS . "_darcs") - (Fossil . ".fslckout"))) - (backend-markers + (let* ((backend-markers (delete nil (mapcar - (lambda (b) (assoc-default b backend-markers-alist)) + (lambda (b) (assoc-default b project-vc-backend-markers-alist)) vc-handled-backends))) (marker-re (concat @@ -537,7 +547,7 @@ project backend implementation of `project-external-roots'.") (backend (cl-find-if (lambda (b) - (member (assoc-default b backend-markers-alist) + (member (assoc-default b project-vc-backend-markers-alist) last-matches)) vc-handled-backends)) project) From a40b1745d4ade399852ea15a60c07e63907eb298 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Sat, 18 Feb 2023 00:54:02 +0200 Subject: [PATCH 19/24] (project-vc-backend-markers-alist): Add entry for vc-got * lisp/progmodes/project.el (project-vc-backend-markers-alist): Add entry for vc-got (bug#61577). Bump the version. --- lisp/progmodes/project.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 46bafc55777..1228c73fee8 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -1,7 +1,7 @@ ;;; project.el --- Operations on the current project -*- lexical-binding: t; -*- ;; Copyright (C) 2015-2023 Free Software Foundation, Inc. -;; Version: 0.9.6 +;; Version: 0.9.7 ;; Package-Requires: ((emacs "26.1") (xref "1.4.0")) ;; This is a GNU ELPA :core package. Avoid using functionality that @@ -505,7 +505,8 @@ project backend implementation of `project-external-roots'.") "_svn" ".svn")) (DARCS . "_darcs") - (Fossil . ".fslckout")) + (Fossil . ".fslckout") + (Got . ".got")) "Associative list assigning root markers to VC backend symbols. See `project-vc-extra-root-markers' for the marker value format.") From 13fd7667f9c7fe5a4588bcae427e2da1ce368fe0 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Sat, 11 Feb 2023 09:26:11 +0800 Subject: [PATCH 20/24] ; * src/treesit.c: Improve sectioning. --- src/treesit.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/treesit.c b/src/treesit.c index 08119f149b7..e1d6f1ef79f 100644 --- a/src/treesit.c +++ b/src/treesit.c @@ -720,6 +720,7 @@ Return nil if a grammar library for LANGUAGE is not available. */) } } + /*** Parsing functions */ static void @@ -1113,6 +1114,7 @@ treesit_read_buffer (void *parser, uint32_t byte_index, return beg; } + /*** Functions for parser and node object */ /* Wrap the parser in a Lisp_Object to be used in the Lisp @@ -1275,6 +1277,9 @@ treesit_ensure_query_compiled (Lisp_Object query, Lisp_Object *signal_symbol, return treesit_query; } + +/* Lisp definitions. */ + DEFUN ("treesit-parser-p", Ftreesit_parser_p, Streesit_parser_p, 1, 1, 0, doc: /* Return t if OBJECT is a tree-sitter parser. */) @@ -1493,6 +1498,7 @@ treesit_parser_live_p (Lisp_Object parser) (!NILP (Fbuffer_live_p (XTS_PARSER (parser)->buffer)))); } + /*** Parser API */ DEFUN ("treesit-parser-root-node", @@ -1739,6 +1745,7 @@ positions. PARSER is the parser issuing the notification. */) return Qnil; } + /*** Node API */ /* Check that OBJ is a positive integer and signal an error if @@ -2261,6 +2268,7 @@ produced by tree-sitter. */) return same_node ? Qt : Qnil; } + /*** Query functions */ DEFUN ("treesit-pattern-expand", @@ -2835,6 +2843,7 @@ the query. */) return Fnreverse (result); } + /*** Navigation */ static inline void @@ -3455,7 +3464,7 @@ DEFUN ("treesit-available-p", Ftreesit_available_p, #endif } - + /*** Initialization */ /* Initialize the tree-sitter routines. */ From 3e747630999894553e2726f81b7d13da46b96350 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Sat, 18 Feb 2023 11:03:07 +0800 Subject: [PATCH 21/24] * lisp/files.el (file-equal-p): Work around Haiku stat bug. --- lisp/files.el | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lisp/files.el b/lisp/files.el index 0d24852358e..57e01340359 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -6357,7 +6357,18 @@ If FILE1 or FILE2 does not exist, the return value is unspecified." (let (f1-attr f2-attr) (and (setq f1-attr (file-attributes (file-truename file1))) (setq f2-attr (file-attributes (file-truename file2))) - (equal f1-attr f2-attr)))))) + (progn + ;; Haiku systems change the file's last access timestamp + ;; every time `stat' is called. Make sure to not compare + ;; the timestamps in that case. + (or (equal f1-attr f2-attr) + (when (and (eq system-type 'haiku) + (consp (nthcdr 4 f1-attr)) + (consp (nthcdr 4 f2-attr))) + (ignore-errors + (setcar (nthcdr 4 f1-attr) nil) + (setcar (nthcdr 4 f2-attr) nil)) + (equal f1-attr f2-attr))))))))) (defun file-in-directory-p (file dir) "Return non-nil if DIR is a parent directory of FILE. From 5093a5349603390666681966442a21382287b4bd Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 18 Feb 2023 09:37:34 +0200 Subject: [PATCH 22/24] Fix regression due to change in face sort order by 'face-list' * lisp/faces.el (x-create-frame-with-faces): Undo reversing of the face list, which is no longer necessary, since 'face-list's sorting order has been reversed recently. (Bug#61521) --- lisp/faces.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/faces.el b/lisp/faces.el index d1a7881e396..8bf7e4429d9 100644 --- a/lisp/faces.el +++ b/lisp/faces.el @@ -2226,7 +2226,7 @@ the X resource \"reverseVideo\" is present, handle that." (unwind-protect (progn (x-setup-function-keys frame) - (dolist (face (nreverse (face-list))) + (dolist (face (face-list)) (face-spec-recalc face frame)) (x-handle-reverse-video frame parameters) (frame-set-background-mode frame t) From deef41a82590658455bfd6468b2811147dd5f845 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 18 Feb 2023 10:45:12 +0200 Subject: [PATCH 23/24] Fix hi-lock-tests when 'use-dialog-box' is non-nil * test/lisp/hi-lock-tests.el (hi-lock-case-fold) (hi-lock-unhighlight): Bind 'use-dialog-box' to nil. --- test/lisp/hi-lock-tests.el | 135 ++++++++++++++++++++----------------- 1 file changed, 75 insertions(+), 60 deletions(-) diff --git a/test/lisp/hi-lock-tests.el b/test/lisp/hi-lock-tests.el index aeb08ecbb29..794a3b1d0c2 100644 --- a/test/lisp/hi-lock-tests.el +++ b/test/lisp/hi-lock-tests.el @@ -86,13 +86,18 @@ (unhighlight-regexp "a a") (should (= (length (overlays-in (point-min) (point-max))) 0)) - (let ((search-spaces-regexp search-whitespace-regexp)) (highlight-regexp "a a")) + (let ((search-spaces-regexp search-whitespace-regexp)) + (highlight-regexp "a a")) (should (= (length (overlays-in (point-min) (point-max))) 1)) - (cl-letf (((symbol-function 'completing-read) - (lambda (_prompt _coll - &optional _x _y _z _hist defaults _inherit) - (car defaults)))) - (call-interactively 'unhighlight-regexp)) + ;; We bind use-dialog-box to nil to prevent unhighlight-regexp + ;; from using popup menus, since the replacement for + ;; completing-read below is not ready for that calamity + (let ((use-dialog-box nil)) + (cl-letf (((symbol-function 'completing-read) + (lambda (_prompt _coll + &optional _x _y _z _hist defaults _inherit) + (car defaults)))) + (call-interactively 'unhighlight-regexp))) (should (= (length (overlays-in (point-min) (point-max))) 0)) (emacs-lisp-mode) @@ -142,12 +147,16 @@ (let ((search-spaces-regexp search-whitespace-regexp)) (highlight-regexp "a a")) (font-lock-ensure) (should (memq 'hi-yellow (get-text-property 1 'face))) - (cl-letf (((symbol-function 'completing-read) - (lambda (_prompt _coll - &optional _x _y _z _hist defaults _inherit) - (car defaults))) - (font-lock-fontified t)) - (call-interactively 'unhighlight-regexp)) + ;; We bind use-dialog-box to nil to prevent unhighlight-regexp + ;; from using popup menus, since the replacement for + ;; completing-read below is not ready for that calamity + (let ((use-dialog-box nil)) + (cl-letf (((symbol-function 'completing-read) + (lambda (_prompt _coll + &optional _x _y _z _hist defaults _inherit) + (car defaults))) + (font-lock-fontified t)) + (call-interactively 'unhighlight-regexp))) (should (null (get-text-property 1 'face)))))) (ert-deftest hi-lock-unhighlight () @@ -156,58 +165,64 @@ (with-temp-buffer (insert "aAbB\n") - (cl-letf (((symbol-function 'completing-read) - (lambda (_prompt _coll - &optional _x _y _z _hist defaults _inherit) - (car defaults)))) + ;; We bind use-dialog-box to nil to prevent unhighlight-regexp + ;; from using popup menus, since the replacement for + ;; completing-read below is not ready for that calamity + (let ((use-dialog-box nil)) + (cl-letf (((symbol-function 'completing-read) + (lambda (_prompt _coll + &optional _x _y _z _hist defaults _inherit) + (car defaults)))) + (highlight-regexp "a") + (highlight-regexp "b") + (should (= (length (overlays-in (point-min) (point-max))) 4)) + ;; `hi-lock--regexps-at-point' should take regexp "a" at point 1, + ;; not the last regexp "b" + (goto-char 1) + (call-interactively 'unhighlight-regexp) + (should (= (length (overlays-in 1 3)) 0)) + (should (= (length (overlays-in 3 5)) 2)) + ;; Next call should unhighlight remaining regepxs + (call-interactively 'unhighlight-regexp) + (should (= (length (overlays-in 3 5)) 0)) - (highlight-regexp "a") - (highlight-regexp "b") - (should (= (length (overlays-in (point-min) (point-max))) 4)) - ;; `hi-lock--regexps-at-point' should take regexp "a" at point 1, - ;; not the last regexp "b" - (goto-char 1) - (call-interactively 'unhighlight-regexp) - (should (= (length (overlays-in 1 3)) 0)) - (should (= (length (overlays-in 3 5)) 2)) - ;; Next call should unhighlight remaining regepxs - (call-interactively 'unhighlight-regexp) - (should (= (length (overlays-in 3 5)) 0)) + ;; Test unhighlight all + (highlight-regexp "a") + (highlight-regexp "b") + (should (= (length (overlays-in (point-min) (point-max))) 4)) + (unhighlight-regexp t) + (should (= (length (overlays-in (point-min) (point-max))) 0)) - ;; Test unhighlight all - (highlight-regexp "a") - (highlight-regexp "b") - (should (= (length (overlays-in (point-min) (point-max))) 4)) - (unhighlight-regexp t) - (should (= (length (overlays-in (point-min) (point-max))) 0)) + (emacs-lisp-mode) + (setq font-lock-mode t) - (emacs-lisp-mode) - (setq font-lock-mode t) + (highlight-regexp "a") + (highlight-regexp "b") + (font-lock-ensure) + (should (memq 'hi-yellow (get-text-property 1 'face))) + (should (memq 'hi-yellow (get-text-property 3 'face))) + ;; `hi-lock--regexps-at-point' should take regexp "a" at point 1, + ;; not the last regexp "b" + (goto-char 1) + (let ((font-lock-fontified t)) + (call-interactively 'unhighlight-regexp)) + (should (null (get-text-property 1 'face))) + (should (memq 'hi-yellow (get-text-property 3 'face))) + ;; Next call should unhighlight remaining regepxs + (let ((font-lock-fontified t)) + (call-interactively 'unhighlight-regexp)) + (should (null (get-text-property 3 'face))) - (highlight-regexp "a") - (highlight-regexp "b") - (font-lock-ensure) - (should (memq 'hi-yellow (get-text-property 1 'face))) - (should (memq 'hi-yellow (get-text-property 3 'face))) - ;; `hi-lock--regexps-at-point' should take regexp "a" at point 1, - ;; not the last regexp "b" - (goto-char 1) - (let ((font-lock-fontified t)) (call-interactively 'unhighlight-regexp)) - (should (null (get-text-property 1 'face))) - (should (memq 'hi-yellow (get-text-property 3 'face))) - ;; Next call should unhighlight remaining regepxs - (let ((font-lock-fontified t)) (call-interactively 'unhighlight-regexp)) - (should (null (get-text-property 3 'face))) - - ;; Test unhighlight all - (highlight-regexp "a") - (highlight-regexp "b") - (font-lock-ensure) - (should (memq 'hi-yellow (get-text-property 1 'face))) - (should (memq 'hi-yellow (get-text-property 3 'face))) - (let ((font-lock-fontified t)) (unhighlight-regexp t)) - (should (null (get-text-property 1 'face))) - (should (null (get-text-property 3 'face))))))) + ;; Test unhighlight all + (highlight-regexp "a") + (highlight-regexp "b") + (font-lock-ensure) + (should (memq 'hi-yellow (get-text-property 1 'face))) + (should (memq 'hi-yellow (get-text-property 3 'face))) + (let ((font-lock-fontified t)) + (unhighlight-regexp t)) + (should (null (get-text-property 1 'face))) + (should (null (get-text-property 3 'face)))))))) (provide 'hi-lock-tests) ;;; hi-lock-tests.el ends here From 1769a588300f471a85fe8887864ae33340dececb Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 18 Feb 2023 10:58:00 +0200 Subject: [PATCH 24/24] Fix some uses of 'use-dialog-box' * lisp/frame.el (display-mouse-p): Fix return value on MS-Windows in batch invocations. * lisp/hi-lock.el (hi-lock-unface-buffer): Don't consider 'last-nonmenu-event' being nil as a mouse event, for the purpose of using dialog boxes. --- lisp/frame.el | 5 +++-- lisp/hi-lock.el | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lisp/frame.el b/lisp/frame.el index af95a047c38..81383349354 100644 --- a/lisp/frame.el +++ b/lisp/frame.el @@ -2120,8 +2120,9 @@ frame's display)." ;; a toggle. (featurep 't-mouse) ;; No way to check whether a w32 console has a mouse, assume - ;; it always does. - (boundp 'w32-use-full-screen-buffer)))))) + ;; it always does, except in batch invocations. + (and (not noninteractive) + (boundp 'w32-use-full-screen-buffer))))))) (defun display-popup-menus-p (&optional display) "Return non-nil if popup menus are supported on DISPLAY. diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el index 78fc5e6f716..5c536b190fb 100644 --- a/lisp/hi-lock.el +++ b/lisp/hi-lock.el @@ -611,6 +611,7 @@ then remove all hi-lock highlighting." (cond (current-prefix-arg (list t)) ((and (display-popup-menus-p) + last-nonmenu-event (listp last-nonmenu-event) use-dialog-box) (catch 'snafu