Skip to content

Commit 3ca382c

Browse files
rschmuklerbbatsov
authored andcommitted
Fix semantic indentation of quoted functions
Fixes an error where quoted functions would not align correctly with semantic indentation. Adds an example test and updates the changelog
1 parent 177e8e1 commit 3ca382c

4 files changed

+19
-6
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- [#42]: Fix imenu support for definitions with metadata.
1010
- [#42]: Fix font locking of definitions with metadata
1111
- [#42]: Fix indentation of definitions with metadata
12+
- Fix semantic indentation of quoted functions
1213

1314
## 0.2.2 (2024-02-16)
1415

clojure-ts-mode.el

+10-5
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,10 @@ with the markdown_inline grammar."
528528
"Return non-nil if NODE is a Clojure metadata node."
529529
(string-equal "meta_lit" (treesit-node-type node)))
530530

531+
(defun clojure-ts--var-node-p (node)
532+
"Return non-nil if NODE is a var (eg. #\\'foo)."
533+
(string-equal "var_quoting_lit" (treesit-node-type node)))
534+
531535
(defun clojure-ts--named-node-text (node)
532536
"Gets the name of a symbol or keyword NODE.
533537
This does not include the NODE's namespace."
@@ -616,13 +620,13 @@ Includes a dispatch value when applicable (defmethods)."
616620
"Return non-nil if NODE is a ns form."
617621
(clojure-ts--definition-node-p "ns" node))
618622

619-
(defvar clojure-ts--variable-type-regexp
623+
(defvar clojure-ts--variable-definition-type-regexp
620624
(rx string-start (or "def" "defonce") string-end)
621625
"Regular expression for matching definition nodes that resemble variables.")
622626

623-
(defun clojure-ts--variable-node-p (node)
627+
(defun clojure-ts--variable-definition-node-p (node)
624628
"Return non-nil if NODE is a def or defonce form."
625-
(clojure-ts--definition-node-match-p clojure-ts--variable-type-regexp node))
629+
(clojure-ts--definition-node-match-p clojure-ts--variable-definition-type-regexp node))
626630

627631
(defvar clojure-ts--class-type-regexp
628632
(rx string-start (or "deftype" "defrecord" "defstruct") string-end)
@@ -647,7 +651,7 @@ Includes a dispatch value when applicable (defmethods)."
647651
;; Used instead of treesit-defun-name-function.
648652
clojure-ts--function-node-name)
649653
("Macro" "list_lit" clojure-ts--defmacro-node-p)
650-
("Variable" "list_lit" clojure-ts--variable-node-p)
654+
("Variable" "list_lit" clojure-ts--variable-definition-node-p)
651655
("Interface" "list_lit" clojure-ts--interface-node-p)
652656
("Class" "list_lit" clojure-ts--class-node-p))
653657
"The value for `treesit-simple-imenu-settings'.
@@ -735,7 +739,8 @@ https://github.com/weavejester/cljfmt/blob/fb26b22f569724b05c93eb2502592dfc2de89
735739
(not (treesit-node-eq (treesit-node-child parent 1 t) node))
736740
(let ((first-child (treesit-node-child parent 0 t)))
737741
(or (clojure-ts--symbol-node-p first-child)
738-
(clojure-ts--keyword-node-p first-child)))))
742+
(clojure-ts--keyword-node-p first-child)
743+
(clojure-ts--var-node-p first-child)))))
739744

740745
(defun clojure-ts--match-expression-in-body (node parent _bol)
741746
"Match NODE if it is an expression used in a body argument.

test/clojure-ts-mode-indentation-test.el

+6-1
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,9 @@ DESCRIPTION is a string with the description of the spec."
135135
(defn c
136136
\"hello\"
137137
[_foo]
138-
(+ 1 1))"))
138+
(+ 1 1))")
139+
140+
(when-indenting-it "should support function calls via vars"
141+
"
142+
(#'foo 5
143+
6)"))

test/samples/indentation.clj

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
(clojure.core/filter even?
6161
(range 1 10))
6262

63+
(#'filter even?
64+
(range 10))
6365

6466
(filter
6567
even?

0 commit comments

Comments
 (0)