branch: elpa/blueprint-ts-mode
commit 5856835590aaf00d549469eb6a39a8d4b6f3268d
Merge: b4c72623d9 91e5104686
Author: Huan <73443559+hua...@users.noreply.github.com>
Commit: GitHub <nore...@github.com>

    Merge pull request #4 from mavit/ensure
    
    Auto-install grammar on Emacs 31 and newer
---
 README.org           | 5 ++---
 blueprint-ts-mode.el | 8 +++++++-
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/README.org b/README.org
index 215ea36bd3..55839668bf 100644
--- a/README.org
+++ b/README.org
@@ -6,10 +6,9 @@ Major mode for Blueprint 
([[https://jwestman.pages.gitlab.gnome.org/blueprint-co
 * Installation
 You need Emacs version >= 29. Your Emacs also needs to be compiled with 
Treesitter support (~--with-tree-sitter~) which you can check with the variable 
~system-configuration-options~.
 
-Get the grammar:
+On Emacs 30 and older (or Emacs 31 and newer, if 
~treesit-auto-install-grammar~ is set to ~never~), there is an addition step to 
get the grammar:
 #+begin_src emacs-lisp
-  (add-to-list 'treesit-language-source-alist
-               '(blueprint . 
("https://github.com/huanie/tree-sitter-blueprint";)))
+  (require 'blueprint-ts-mode)
   (treesit-install-language-grammar 'blueprint)
 #+end_src
 
diff --git a/blueprint-ts-mode.el b/blueprint-ts-mode.el
index 6aa833f5f6..d9424c2d29 100644
--- a/blueprint-ts-mode.el
+++ b/blueprint-ts-mode.el
@@ -39,6 +39,10 @@
 (require 'eglot)
 (eval-when-compile (require 'rx))
 
+(add-to-list
+ 'treesit-language-source-alist
+ '(blueprint "https://github.com/huanie/tree-sitter-blueprint";))
+
 (defgroup blueprint ()
   "Tree-sitter support for Blueprint files."
   :prefix "blueprint-ts-"
@@ -112,7 +116,9 @@ Saves me from writing :language `LANGUAGE' for every 
`RULES'."
 ;;;###autoload
 (define-derived-mode blueprint-ts-mode prog-mode "Blueprint"
   "Blueprint major mode using treesitter."
-  (when (treesit-ready-p 'blueprint)
+  (when (if (fboundp 'treesit-ensure-installed)
+            (treesit-ensure-installed 'blueprint)
+          (treesit-ready-p 'blueprint))
     (treesit-parser-create 'blueprint)
     ;; Comments
     (setq-local comment-start "// ")

Reply via email to