From bbed615f17fecbb9bb0dc1c2f3ea59cc1335c4ea Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 2 Sep 2025 12:26:49 +0200 Subject: [PATCH] feat(tree-sitter): batch grammar installs Instead of being prompted 2-4 times to install each missing grammar, batches them together into one prompt. --- modules/tools/tree-sitter/config.el | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/modules/tools/tree-sitter/config.el b/modules/tools/tree-sitter/config.el index 0de302d84..cf1ca0ed5 100644 --- a/modules/tools/tree-sitter/config.el +++ b/modules/tools/tree-sitter/config.el @@ -70,10 +70,20 @@ ;; and push forward anyway, even if a missing grammar ;; results in a broken state. (not (fboundp fallback-mode)) - (cl-every (if (get mode '+tree-sitter-ensured) - (doom-rpartial #'treesit-ready-p 'message) - #'treesit-ensure-installed) - (cdr ts)))) + ;; Ensure grammars are present (and prompt to install + ;; them if needed). + (if-let* ((grammars + (cl-remove-if (doom-rpartial #'treesit-ready-p 'message) + (cdr ts)))) + (if (or (eq treesit-auto-install-grammar 'always) + (if (eq treesit-auto-install-grammar 'ask) + (y-or-n-p + (format "Missing tree-sitter grammars: %s\nInstall now?" + (mapconcat #'symbol-name grammars ", "))))) + (mapc #'treesit-install-language-grammar grammars) + (message "Aborted installing missing grammars...") + nil) + t))) (put mode '+tree-sitter-ensured t) mode) (fallback-mode))