fix: define native commands at the Ebox facade
Some checks are pending
CI / test (push) Waiting to run
CI / native-build (macos-latest) (push) Waiting to run
CI / native-build (ubuntu-latest) (push) Waiting to run
CI / native-build (windows-latest) (push) Waiting to run
CI / native-msrv (macos-latest) (push) Waiting to run
CI / native-msrv (ubuntu-latest) (push) Waiting to run
CI / native-msrv (windows-latest) (push) Waiting to run

This commit is contained in:
Kinneyzhang 2026-08-27 16:53:12 +08:00
parent 9f48b2f283
commit 8861902b7e
3 changed files with 58 additions and 18 deletions

View File

@ -948,8 +948,7 @@ next Emacs start."
(plist-get issue :message))))))
(display-buffer buffer)))
;;;###autoload
(defun ebox-native-build (&optional clean)
(defun ebox-native-reflow--build (&optional clean)
"Compile and install the bundled native module asynchronously.
The command always runs the shared environment checks first and requires a
Rust/Cargo toolchain native to the current Emacs architecture. With prefix
@ -1018,15 +1017,15 @@ Build output and exact errors appear in `*Ebox Native Build*'."
(error-message-string err)))))))
(defun ebox-native-reflow--clean-build ()
"Run `ebox-native-build' after clearing Ebox's private Cargo cache."
"Run a native build after clearing Ebox's private Cargo cache."
(interactive)
(ebox-native-build t))
(ebox-native-reflow--build t))
(defvar ebox-native-status-mode-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map special-mode-map)
(define-key map (kbd "g") #'ebox-native-status)
(define-key map (kbd "b") #'ebox-native-build)
(define-key map (kbd "g") #'ebox-native-reflow--status)
(define-key map (kbd "b") #'ebox-native-reflow--build)
(define-key map (kbd "B") #'ebox-native-reflow--clean-build)
map)
"Keymap for `ebox-native-status-mode'.")
@ -1142,8 +1141,7 @@ Build output and exact errors appear in `*Ebox Native Build*'."
(insert (concat "Keys: g refresh status, b build/rebuild, "
"B clean rebuild, q quit.\n"))))
;;;###autoload
(defun ebox-native-status ()
(defun ebox-native-reflow--status ()
"Display native toolchain, installation, and runtime loading status."
(interactive)
(unless ebox-native-reflow--load-attempted-p

22
ebox.el
View File

@ -65,11 +65,10 @@
"ebox-incremental" (buffer report))
(declare-function ebox--scroll-rendered-content-lines
"ebox-layout" (box lines region-id &optional start-index))
(declare-function ebox-native-reflow--build
"ebox-native-reflow" (&optional clean))
(declare-function ebox-native-reflow--status "ebox-native-reflow" ())
(unless (fboundp 'ebox-native-build)
(autoload 'ebox-native-build "ebox-native-reflow" nil t))
(unless (fboundp 'ebox-native-status)
(autoload 'ebox-native-status "ebox-native-reflow" nil t))
(defalias 'ebox-select-all #'ebox-selector-query-buffer)
(defalias 'ebox-update-selector #'ebox-selector-update-buffer)
@ -78,6 +77,21 @@
:group 'applications
:prefix "ebox-")
;;;###autoload
(defun ebox-native-build (&optional clean)
"Build and install Ebox's optional native module asynchronously.
With prefix argument CLEAN, clear only Ebox's private Cargo build cache first."
(interactive "P")
(require 'ebox-native-reflow)
(ebox-native-reflow--build clean))
;;;###autoload
(defun ebox-native-status ()
"Display Ebox native toolchain, installation, and runtime status."
(interactive)
(require 'ebox-native-reflow)
(ebox-native-reflow--status))
;;;###autoload
(defun ebox-byte-compile ()
"Recompile every active Ebox Lisp source into a neighboring `.elc' file.

View File

@ -19,8 +19,7 @@
"ebox-grid.el"
"ebox-canonical.el"
"ebox-buffer-backend.el"
"ebox-selector.el"
"ebox-native-reflow.el")
"ebox-selector.el")
"Source files that currently own public autoload entry points.")
(defun ebox-test--source-text ()
@ -81,13 +80,42 @@
"(unless (ebox-text-node-p (ebox-text-create :value \"A\")) "
" (error \"Typed Text autoload failed\")))")))))))
(ert-deftest ebox-facade-exposes-native-workflow-without-loading-it ()
"The two native commands should be available without native load work."
(ert-deftest ebox-facade-defines-native-workflow-without-loading-it ()
"The facade should define native commands without loading the subsystem."
(require 'ebox)
(should (autoloadp (symbol-function 'ebox-native-build)))
(should (autoloadp (symbol-function 'ebox-native-status)))
(should (commandp 'ebox-native-build))
(should (commandp 'ebox-native-status))
(should-not (autoloadp (symbol-function 'ebox-native-build)))
(should-not (autoloadp (symbol-function 'ebox-native-status)))
(should-not (featurep 'ebox-native-reflow)))
(ert-deftest ebox-native-command-autoloads-may-target-the-facade ()
"Startup registries may safely autoload native commands from `ebox'."
(let* ((emacs (expand-file-name invocation-name invocation-directory))
(parent (file-name-directory (directory-file-name ebox-test--root)))
(ecss (expand-file-name "ecss" parent))
(tp (expand-file-name "tp" parent)))
(with-temp-buffer
(should
(zerop
(process-file
emacs nil (current-buffer) nil
"-Q" "--batch"
"-L" ebox-test--root "-L" ecss "-L" tp
"--eval" "(setq load-prefer-newer t)"
"--eval"
(concat
"(progn "
"(autoload 'ebox-native-status \"ebox\" nil t) "
"(autoload 'ebox-native-build \"ebox\" nil t) "
"(autoload-do-load (symbol-function 'ebox-native-status) "
" 'ebox-native-status) "
"(unless (and (commandp 'ebox-native-status) "
" (commandp 'ebox-native-build)) "
" (error \"Facade did not define native commands\")) "
"(when (featurep 'ebox-native-reflow) "
" (error \"Facade autoload eagerly loaded native subsystem\")))")))))))
(ert-deftest ebox-byte-compile-is-an-interactive-public-command ()
"Users should be able to rebuild all active Ebox bytecode from Emacs."
(should (commandp 'ebox-byte-compile))