branch: elpa/clojure-ts-mode commit 9a96a78a934edcb0bb4ac0483947e9693e4861ea Author: dannyfreeman <danny@dfreeman.email> Commit: dannyfreeman <danny@dfreeman.email>
Add fixed indent rules 1 problem occurs when indenting in the middle of a populated list like (a b | c) where | is the cursor. It should indent to (a b | c) but instead we get (a b | c) Because the "(list_lit . (sym_lit) _* @indent)" query is not matching, apparently. I am unsure why it doesn't match, testing manually indicates that it should, but I'm not sure what node is being used exactly. --- clojure-ts-mode.el | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/clojure-ts-mode.el b/clojure-ts-mode.el index 6bdc7fccd6..e0ee31ba21 100644 --- a/clojure-ts-mode.el +++ b/clojure-ts-mode.el @@ -327,18 +327,17 @@ '((derefing_lit marker: "@" @font-lock-warning-face)))) -;; (defvar clojure-ts-mode--indent-rules -;; '((clojure -;; ((parent-is "source") parent-bol 0) -;; ((parent-is "set_lit") parent-bol 2) -;; ((parent-is "vec_lit") parent-bol 1) -;; ((parent-is "map_lit") parent-bol 1) -;; ;; Lists beginning with a symbol indent 2 spaces (usally a function call) -;; ((query "(list_lit . (sym_lit) _* @indent)") parent-bol 2) -;; ;; All other lists indent 1 space -;; ((parent-is "list_lit") parent-bol 1)))) - ;; Need to deal with deref, tagged literals. - +(defvar clojure-ts-mode--fixed-indent-rules + ;; This is in contrast to semantic rules + ;; fixed-indent-rules come from https://tonsky.me/blog/clojurefmt/ + '((clojure + ((parent-is "source") parent-bol 0) + ;; Lists beginning with a symbol indent 2 spaces (usually a function/macro call) + ((query "(list_lit . (sym_lit) _* @indent)") parent 2) + ((or (parent-is "vec_lit") + (parent-is "map_lit") + (parent-is "list_lit")) parent 1) + ((parent-is "set_lit") parent 2)))) (defvar clojure-ts-mode-map (let ((map (make-sparse-keymap))) @@ -374,7 +373,8 @@ Requires Emacs 29 and libtree-sitter-clojure.so available somewhere in '((comment string char number) (keyword constant symbol bracket builtin) (deref quote metadata definition variable type doc regex tagged-literals))) - ;(setq-local treesit-simple-indent-rules clojure-ts-mode--indent-rules) + (setq-local treesit-simple-indent-rules clojure-ts-mode--fixed-indent-rules) + (setq treesit--indent-verbose t) (treesit-major-mode-setup) (treesit-inspect-mode) ;(clojure-mode-variables)