diff options
| author | Craig Jennings <c@cjennings.net> | 2026-07-01 22:14:07 -0400 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-07-01 22:14:07 -0400 |
| commit | 4ea52a61560b6fa25b3d04f484c1ab140c723133 (patch) | |
| tree | 5345d635fac9f123c119a97ba48cf6e94b24b567 | |
| parent | 6c8ee35aa8f1bddf264b880925270b33ff576a46 (diff) | |
| download | dotemacs-4ea52a61560b6fa25b3d04f484c1ab140c723133.tar.gz dotemacs-4ea52a61560b6fa25b3d04f484c1ab140c723133.zip | |
fix(treesit): prompt before grammar installs, add explicit bootstrap
treesit-auto-install was t, so opening a file could silently trigger a network download and compiler build mid-edit. It now prompts, and cj/install-treesit-grammars is the deliberate fresh-machine bootstrap that installs everything in one command.
| -rw-r--r-- | modules/prog-general.el | 17 | ||||
| -rw-r--r-- | tests/test-prog-general--install-treesit-grammars.el | 34 |
2 files changed, 48 insertions, 3 deletions
diff --git a/modules/prog-general.el b/modules/prog-general.el index 15bf40c4..831f43cb 100644 --- a/modules/prog-general.el +++ b/modules/prog-general.el @@ -115,11 +115,14 @@ REGEXP must be a string or an rx form." ;; incremental language syntax parser ;; Using Emacs 29+ built-in treesit with treesit-auto for grammar management -;; installs tree-sitter grammars if they're absent +;; Manages tree-sitter grammars. Install is 'prompt, never t: with t, +;; merely opening a file could trigger a network download and a compiler +;; build mid-edit. Batch/test runs never load treesit-auto (no package +;; init), so they can never install. Fresh-machine bootstrap is the +;; explicit `cj/install-treesit-grammars' command below. (use-package treesit-auto :custom - (treesit-auto-install t) - ;; (treesit-auto-install 'prompt) ;; optional prompt instead of auto-install + (treesit-auto-install 'prompt) :config (require 'cl-lib) ;; Pin Go grammar to v0.19.1 for compatibility with Emacs 30.2 font-lock queries @@ -134,6 +137,14 @@ REGEXP must be a string or an rx form." (treesit-auto-add-to-auto-mode-alist 'all) (global-treesit-auto-mode)) +(defun cj/install-treesit-grammars () + "Install every tree-sitter grammar treesit-auto knows about. +The deliberate bootstrap for a fresh machine, replacing the old +silent install-on-file-open (`treesit-auto-install' t)." + (interactive) + (require 'treesit-auto) + (treesit-auto-install-all)) + ;; -------------------------------- Code Folding ------------------------------- ;; BICYCLE diff --git a/tests/test-prog-general--install-treesit-grammars.el b/tests/test-prog-general--install-treesit-grammars.el new file mode 100644 index 00000000..62bf3920 --- /dev/null +++ b/tests/test-prog-general--install-treesit-grammars.el @@ -0,0 +1,34 @@ +;;; test-prog-general--install-treesit-grammars.el --- Grammar bootstrap command -*- lexical-binding: t; -*- + +;;; Commentary: +;; `treesit-auto-install' is set to `prompt' so opening a file never silently +;; downloads and builds a grammar. `cj/install-treesit-grammars' is the +;; explicit fresh-machine bootstrap: it loads treesit-auto and installs every +;; grammar in one deliberate command. + +;;; Code: + +(require 'ert) +(require 'cl-lib) + +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'prog-general) + +;; Satisfy the command's (require 'treesit-auto) without the real package, +;; which isn't available in batch runs. +(provide 'treesit-auto) + +(ert-deftest test-prog-general-install-treesit-grammars-is-a-command () + "Normal: the bootstrap entry point exists and is interactive." + (should (commandp 'cj/install-treesit-grammars))) + +(ert-deftest test-prog-general-install-treesit-grammars-installs-all () + "Normal: the command delegates to treesit-auto-install-all." + (let ((called 0)) + (cl-letf (((symbol-function 'treesit-auto-install-all) + (lambda (&rest _) (setq called (1+ called))))) + (cj/install-treesit-grammars) + (should (= called 1))))) + +(provide 'test-prog-general--install-treesit-grammars) +;;; test-prog-general--install-treesit-grammars.el ends here |
