From 22f44e8b9f255ab7ee383621209114131e5713ae Mon Sep 17 00:00:00 2001 From: Howard Abrams Date: Thu, 29 Oct 2026 14:34:23 -0700 Subject: [PATCH] Sped up my startup by not cloning all the treesitter mods Spent more than a minute of my Emacs start time on Tree Sitter, as I would clone _all_ the grammars each time. Now, I need to call my install function with a `force` if I want to update them. Also, I no longer need the `sit-for` entry that I forgot about. --- ha-programming.org | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/ha-programming.org b/ha-programming.org index e4e7b31..c1f4698 100644 --- a/ha-programming.org +++ b/ha-programming.org @@ -450,6 +450,7 @@ Note that Emacs already has the ability to download and install grammars, so fol ;; (julia "https://github.com/tree-sitter/tree-sitter-julia" "master" "src") ;; (lua "https://github.com/MunifTanjim/tree-sitter-lua" "main" "src") (make "https://github.com/alemuller/tree-sitter-make") + (mermaid "https://github.com/monaqa/tree-sitter-mermaid") ;; (markdown "https://github.com/ikatyang/tree-sitter-markdown") ;; (meson "https://github.com/Decodetalkers/tree-sitter-meson" "master" "src") ;; (python "https://github.com/tree-sitter/tree-sitter-python") @@ -460,11 +461,17 @@ Note that Emacs already has the ability to download and install grammars, so fol ;; (typescript "https://github.com/tree-sitter/tree-sitter-typescript" "master" "typescript/src") (yaml "https://github.com/tree-sitter-grammars/tree-sitter-yaml"))) - (defun mp-setup-install-grammars () - "Install Tree-sitter grammars if they are absent." - (interactive) - (sit-for 30) - (mapc #'treesit-install-language-grammar (mapcar #'car treesit-language-source-alist))) + (defun mp-setup-install-grammars (&optional force) + "Install Tree-sitter grammars if they are absent. +Each grammar in `treesit-language-source-alist' is only cloned and +compiled when `treesit-language-available-p' says it is missing, as +installing one takes a second or two. With a prefix argument, FORCE +reinstalls every grammar, which is how we pick up upstream changes." + (interactive "P") + (dolist (lang (mapcar #'car treesit-language-source-alist)) + (when (or force (not (treesit-language-available-p lang))) + (message "Installing Tree-sitter grammar for `%s' ..." lang) + (treesit-install-language-grammar lang)))) ;; Optional, but Mickey recommends. Tree-sitter enabled major ;; modes are distinct from their ordinary counterparts, however,