diff --git a/CHANGELOG.md b/CHANGELOG.md index 0060ede..2ce075e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - [#72](https://github.com/clojure-emacs/clojure-ts-mode/pull/72): Pass fully qualified symbol to `clojure-ts-get-indent-function`. - [#76](https://github.com/clojure-emacs/clojure-ts-mode/pull/76): Improve performance of semantic indentation by caching rules. - [#74](https://github.com/clojure-emacs/clojure-ts-mode/issues/74): Add imenu support for keywords definitions. +- [#77](https://github.com/clojure-emacs/clojure-ts-mode/issues/77): Update grammars to the latest versions. ## 0.2.3 (2025-03-04) diff --git a/README.md b/README.md index af70b42..cbbafb3 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ Once installed, evaluate clojure-ts-mode.el and you should be ready to go. `clojure-ts-mode` makes use of two TreeSitter grammars to work properly: - The Clojure grammar, mentioned earlier -- [markdown_inline](https://github.com/MDeiml/tree-sitter-markdown), which +- [markdown-inline](https://github.com/MDeiml/tree-sitter-markdown), which will be used for docstrings if available and if `clojure-ts-use-markdown-inline` is enabled. If you have `git` and a C compiler (`cc`) available on your system's `PATH`, @@ -137,6 +137,17 @@ option to install it manually, Please, refer to the installation instructions of each required grammar and make sure you're install the versions expected. (see `clojure-ts-grammar-recipes` for details) +### Upgrading tree-sitter grammars + +To reinstall or upgrade TreeSitter grammars, you can execute: + +```emacs-lisp +M-x clojure-ts-reinstall-grammars +``` + +This will install the latest compatible grammars, even if they are already +installed. + ## Configuration To see a list of available configuration options do `M-x customize-group clojure-ts`. diff --git a/clojure-ts-mode.el b/clojure-ts-mode.el index 9658234..b6bd75f 100644 --- a/clojure-ts-mode.el +++ b/clojure-ts-mode.el @@ -343,14 +343,14 @@ if a third argument (the value) is provided. (defvar clojure-ts--treesit-range-settings (treesit-range-rules - :embed 'markdown_inline + :embed 'markdown-inline :host 'clojure (clojure-ts--docstring-query '@capture))) (defun clojure-ts--font-lock-settings (markdown-available) "Return font lock settings suitable for use in `treesit-font-lock-settings'. When MARKDOWN-AVAILABLE is non-nil, includes rules for highlighting docstrings -with the markdown_inline grammar." +with the markdown-inline grammar." (append (treesit-font-lock-rules :feature 'string @@ -512,11 +512,9 @@ with the markdown_inline grammar." (when markdown-available (treesit-font-lock-rules :feature 'doc - :language 'markdown_inline + :language 'markdown-inline :override t - `((inline - (code_span (code_span_delimiter) :* @font-lock-delimiter-face) - @font-lock-constant-face)))) + `((code_span) @font-lock-constant-face))) (treesit-font-lock-rules :feature 'quote @@ -985,7 +983,7 @@ and (:defn) is converted to (:inner 1)." (t nil)))) (defun clojure-ts--dynamic-indent-for-symbol (sym &optional ns) - "Returns the dynamic indentation specification for SYM, if found. + "Return the dynamic indentation specification for SYM, if found. If the function `clojure-ts-get-indent-function' is defined, call it and produce a valid indentation specification from its return value. @@ -1019,7 +1017,7 @@ If NS is defined, then the fully qualified symbol is passed to (equal (car spec1) :block))))))))) (defun clojure-ts--find-semantic-rule (node parent current-depth) - "Returns a suitable indentation rule for NODE, considering the CURRENT-DEPTH. + "Return a suitable indentation rule for NODE, considering the CURRENT-DEPTH. Attempts to find an indentation rule by examining the symbol name of the PARENT's first child. If a rule is not found, it navigates up the @@ -1153,13 +1151,13 @@ according to the rule. If NODE is nil, use next node after BOL." (clojure-ts--metadata-node-p prev-sibling)))) (defun clojure-ts--anchor-parent-skip-metadata (_node parent _bol) - "Anchor function that returns position of PARENT start for NODE. + "Return position of PARENT start for NODE. If PARENT has optional metadata we skip it and return starting position of the first child's opening paren. -NOTE: This anchor is used to fix indentation issue for forms with type -hints." +NOTE: This serves as an anchor function to resolve an indentation issue +for forms with type hints." (let ((first-child (treesit-node-child parent 0 t))) (if (clojure-ts--metadata-node-p first-child) ;; We don't need named node here @@ -1167,7 +1165,7 @@ hints." (treesit-node-start parent)))) (defun clojure-ts--match-collection-item-with-metadata (node-type) - "Returns a matcher for a collection item with metadata by NODE-TYPE. + "Return a matcher for a collection item with metadata by NODE-TYPE. The returned matcher accepts NODE, PARENT and BOL and returns true only if NODE has metadata and its parent has type NODE-TYPE." @@ -1296,9 +1294,9 @@ If JUSTIFY is non-nil, justify as well as fill the paragraph." (defconst clojure-ts-grammar-recipes '((clojure "https://github.com/sogaiu/tree-sitter-clojure.git" - "v0.0.12") - (markdown_inline "https://github.com/MDeiml/tree-sitter-markdown" - "v0.1.6" + "v0.0.13") + (markdown-inline "https://github.com/MDeiml/tree-sitter-markdown" + "v0.4.1" "tree-sitter-markdown-inline/src")) "Intended to be used as the value for `treesit-language-source-alist'.") @@ -1316,6 +1314,18 @@ If JUSTIFY is non-nil, justify as well as fill the paragraph." (let ((treesit-language-source-alist clojure-ts-grammar-recipes)) (treesit-install-language-grammar grammar))))))) +(defun clojure-ts-reinstall-grammars () + "Install the required versions of language grammars. + +If the grammars are already installed, they will be reinstalled. This +function can also be used to upgrade the grammars if they are outdated." + (interactive) + (dolist (recipe clojure-ts-grammar-recipes) + (let ((grammar (car recipe))) + (message "Installing %s tree-sitter grammar" grammar) + (let ((treesit-language-source-alist clojure-ts-grammar-recipes)) + (treesit-install-language-grammar grammar))))) + (defun clojure-ts-mode-variables (&optional markdown-available) "Initialize buffer-local variables for `clojure-ts-mode'. See `clojure-ts--font-lock-settings' for usage of MARKDOWN-AVAILABLE." @@ -1361,9 +1371,9 @@ See `clojure-ts--font-lock-settings' for usage of MARKDOWN-AVAILABLE." :syntax-table clojure-ts-mode-syntax-table (clojure-ts--ensure-grammars) (let ((use-markdown-inline (and clojure-ts-use-markdown-inline - (treesit-ready-p 'markdown_inline t)))) + (treesit-ready-p 'markdown-inline t)))) (when use-markdown-inline - (treesit-parser-create 'markdown_inline) + (treesit-parser-create 'markdown-inline) (setq-local treesit-range-settings clojure-ts--treesit-range-settings)) (when (treesit-ready-p 'clojure)