branch: elpa/clojure-ts-mode
commit 0e2eb1f7752664e3ae875eeede7537c3e175080e
Author: dannyfreeman <danny@dfreeman.email>
Commit: dannyfreeman <danny@dfreeman.email>

    Auto-install tree-sitter-clojure grammar when it's not available
---
 README.md          | 36 ++++++++++++++++++++----------------
 clojure-ts-mode.el | 10 +++++++++-
 2 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/README.md b/README.md
index 30e63fba84..d2fd691736 100644
--- a/README.md
+++ b/README.md
@@ -18,16 +18,33 @@ More information on this can be found in the Emacs 
repository:
 - [Emacs tree-sitter 
starter-guide](https://git.savannah.gnu.org/cgit/emacs.git/tree/admin/notes/tree-sitter/starter-guide?h=emacs-29)
 - [Emacs install 
instructions](https://git.savannah.gnu.org/cgit/emacs.git/tree/INSTALL.REPO).
 
+### Install clojure-ts-mode
+
+This package is not yet avaialble through package.el.
+You can install it by cloning the repository and adding it to your load path.
+
+```bash
+git clone https://github.com/clojure-emacs/clojure-ts-mode.git
+```
+
+```emacs-lisp
+(add-to-list 'load-path "~/path/to/clojure-ts-mode/")
+```
+
+Once installed, evaluate clojure-ts-mode.el and you should be ready to go.
+
 ### Install libtree-sitter-clojure shared library
 
 The tree-sitter clojure shared library must be available to Emacs.
-clojure-ts-mode will not automatically install this (yet).
-For now, users must do it themselves manually, which requires that a c 
compiler be installed.
+If you have `git` and a c compiler (`cc`) available on your system's `PATH`, 
**then these steps are not necessary**.
+clojure-ts-mode will install the grammar when you first open a Clojure file.
+
+If clojure-ts-mode fails to automatically install the grammar, you have the 
option to install it manually.
+All you need is `git` and a c compiler (gcc works well).
 
 To start, clone 
[tree-sitter-clojure](https://github.com/sogaiu/tree-sitter-clojure).
 
 Then run the following code (depending on your OS) from the 
tree-sitter-clojure repository on your machine.
-(A C compiler like GCC is required)
 
 #### Linux
 
@@ -60,19 +77,6 @@ Then tell Emacs where to find the shared library by adding 
something like this t
 OR you can move the `libtree-sitter-clojure.so`/`libtree-sitter-clojure.dylib` 
to a directory named `tree-sitter`
 under your `user-emacs-directory`.
 
-### Install clojure-ts-mode
-
-This package is not yet avaialble through package.el.
-You can install it by cloning the repository and adding it to your load path.
-
-```bash
-git clone https://github.com/clojure-emacs/clojure-ts-mode.git
-```
-
-```emacs-lisp
-(add-to-list 'load-path "~/path/to/clojure-ts-mode/")
-```
-
 ## License
 
 Copyright © 2022 Danny Freeman and [contributors][].
diff --git a/clojure-ts-mode.el b/clojure-ts-mode.el
index 35a2d052ca..65a806b779 100644
--- a/clojure-ts-mode.el
+++ b/clojure-ts-mode.el
@@ -341,13 +341,19 @@
 ;;      ;; All other lists indent 1 space
 ;;      ((parent-is "list_lit") parent-bol 1))))
      ;; Need to deal with deref, tagged literals.
-     
+
 
 (defvar clojure-ts-mode-map
   (let ((map (make-sparse-keymap)))
     ;(set-keymap-parent map clojure-mode-map)
     map))
 
+;;;###autolaod
+(add-to-list
+ 'treesit-language-source-alist
+ '(clojure "https://github.com/sogaiu/tree-sitter-clojure.git";))
+
+
 ;;;###autoload
 (define-derived-mode clojure-ts-mode prog-mode "Clojure[TS]"
   "Major mode for editing Clojure code.
@@ -355,6 +361,8 @@ Requires Emacs 29 and libtree-sitter-clojure.so available 
somewhere in
 `treesit-extra-load-path'.
 
 \\{clojure-ts-mode-map}"
+  (unless (treesit-language-available-p 'clojure nil)
+    (treesit-install-language-grammar 'clojure))
   (when (treesit-ready-p 'clojure)
     (treesit-parser-create 'clojure)
     (setq-local treesit-font-lock-settings clojure--treesit-settings)

Reply via email to