Improve documentation of new native-compilation commands

* lisp/progmodes/elisp-mode.el (emacs-lisp-mode-menu)
(emacs-lisp-native-compile, emacs-lisp-native-compile-and-load):
Doc fixes.

* doc/lispref/compile.texi (Native-Compilation Functions):
Document 'emacs-lisp-native-compile' and
'emacs-lisp-native-compile-and-load'.
This commit is contained in:
Eli Zaretskii 2023-12-22 16:49:49 +02:00
parent 1ad126c0f2
commit bd0c758971
2 changed files with 23 additions and 8 deletions

View file

@ -878,8 +878,7 @@ well.
You can natively-compile either a single function or macro You can natively-compile either a single function or macro
definition, or a whole file of Lisp code, with the definition, or a whole file of Lisp code, with the
@code{native-compile} function. Natively-compiling a file will @code{native-compile} function. Natively-compiling a file will
produce both the corresponding @file{.elc} file with byte code and the produce the @file{.eln} file with native code.
@file{.eln} file with native code.
@findex native-comp-limple-mode @findex native-comp-limple-mode
@vindex native-comp-verbose @vindex native-comp-verbose
@ -971,6 +970,18 @@ compilation subprocesses in parallel, under the control of
Variables}). Variables}).
@end defun @end defun
@deffn Command emacs-lisp-native-compile
This command compiles the file visited by the current buffer into
native code, if the file was changed since the last time it was
natively-compiled.
@end deffn
@deffn Command emacs-lisp-native-compile-and-load
This command compiles the file visited by the current buffer into
native code, like @code{emacs-lisp-native-compile}, but it also loads
the native code when the compilation finishes.
@end deffn
The following function allows Lisp programs to test whether The following function allows Lisp programs to test whether
native-compilation is available at runtime. native-compilation is available at runtime.

View file

@ -85,10 +85,10 @@ All commands in `lisp-mode-shared-map' are inherited by this map."
["Byte-recompile Directory..." byte-recompile-directory ["Byte-recompile Directory..." byte-recompile-directory
:help "Recompile every `.el' file in DIRECTORY that needs recompilation"] :help "Recompile every `.el' file in DIRECTORY that needs recompilation"]
["Native-compile This File" emacs-lisp-native-compile ["Native-compile This File" emacs-lisp-native-compile
:help "Compile the current file containing the current buffer to native code" :help "Compile this buffer's file to native code"
:active (native-comp-available-p)] :active (native-comp-available-p)]
["Native-compile and Load" emacs-lisp-native-compile-and-load ["Native-compile and Load" emacs-lisp-native-compile-and-load
:help "Compile the current file to native code, then load compiled native code" :help "Compile this buffer's file to native code, then load compiled native code"
:active (native-comp-available-p)] :active (native-comp-available-p)]
["Disassemble Byte Compiled Object..." disassemble ["Disassemble Byte Compiled Object..." disassemble
:help "Print disassembled code for OBJECT in a buffer"] :help "Print disassembled code for OBJECT in a buffer"]
@ -224,7 +224,9 @@ All commands in `lisp-mode-shared-map' are inherited by this map."
(declare-function comp-write-bytecode-file "comp") (declare-function comp-write-bytecode-file "comp")
(defun emacs-lisp-native-compile () (defun emacs-lisp-native-compile ()
"Native-compile synchronously the current file (if it has changed)." "Native-compile the current buffer's file (if it has changed).
This invokes a synchronous native-compilation of the file that is
visited by the current buffer."
(interactive nil emacs-lisp-mode) (interactive nil emacs-lisp-mode)
(emacs-lisp--before-compile-buffer) (emacs-lisp--before-compile-buffer)
(let* ((byte+native-compile t) (let* ((byte+native-compile t)
@ -234,12 +236,14 @@ All commands in `lisp-mode-shared-map' are inherited by this map."
(comp-write-bytecode-file eln)))) (comp-write-bytecode-file eln))))
(defun emacs-lisp-native-compile-and-load () (defun emacs-lisp-native-compile-and-load ()
"Native-compile synchronously the current file (if it has changed). "Native-compile the current buffer's file (if it has changed), then load it.
Load the compiled code when finished. This invokes a synchronous native-compilation of the file that is
visited by the current buffer, then loads the compiled native code
when the compilation is finished.
Use `emacs-lisp-byte-compile-and-load' in combination with Use `emacs-lisp-byte-compile-and-load' in combination with
`native-comp-jit-compilation' set to t to achieve asynchronous `native-comp-jit-compilation' set to t to achieve asynchronous
native compilation." native compilation of the current buffer's file."
(interactive nil emacs-lisp-mode) (interactive nil emacs-lisp-mode)
(when-let ((byte-file (emacs-lisp-native-compile))) (when-let ((byte-file (emacs-lisp-native-compile)))
(load (file-name-sans-extension byte-file)))) (load (file-name-sans-extension byte-file))))