Skip to content

Commit

Permalink
Fix semantic indentation of quoted functions
Browse files Browse the repository at this point in the history
Fixes an error where quoted functions would not align correctly with
semantic indentation.

Adds an example test and updates the changelog
  • Loading branch information
rschmukler authored and bbatsov committed Nov 4, 2024
1 parent 177e8e1 commit 3ca382c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- [#42]: Fix imenu support for definitions with metadata.
- [#42]: Fix font locking of definitions with metadata
- [#42]: Fix indentation of definitions with metadata
- Fix semantic indentation of quoted functions

## 0.2.2 (2024-02-16)

Expand Down
15 changes: 10 additions & 5 deletions clojure-ts-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,10 @@ with the markdown_inline grammar."
"Return non-nil if NODE is a Clojure metadata node."
(string-equal "meta_lit" (treesit-node-type node)))

(defun clojure-ts--var-node-p (node)
"Return non-nil if NODE is a var (eg. #\\'foo)."
(string-equal "var_quoting_lit" (treesit-node-type node)))

(defun clojure-ts--named-node-text (node)
"Gets the name of a symbol or keyword NODE.
This does not include the NODE's namespace."
Expand Down Expand Up @@ -616,13 +620,13 @@ Includes a dispatch value when applicable (defmethods)."
"Return non-nil if NODE is a ns form."
(clojure-ts--definition-node-p "ns" node))

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

(defun clojure-ts--variable-node-p (node)
(defun clojure-ts--variable-definition-node-p (node)
"Return non-nil if NODE is a def or defonce form."
(clojure-ts--definition-node-match-p clojure-ts--variable-type-regexp node))
(clojure-ts--definition-node-match-p clojure-ts--variable-definition-type-regexp node))

(defvar clojure-ts--class-type-regexp
(rx string-start (or "deftype" "defrecord" "defstruct") string-end)
Expand All @@ -647,7 +651,7 @@ Includes a dispatch value when applicable (defmethods)."
;; Used instead of treesit-defun-name-function.
clojure-ts--function-node-name)
("Macro" "list_lit" clojure-ts--defmacro-node-p)
("Variable" "list_lit" clojure-ts--variable-node-p)
("Variable" "list_lit" clojure-ts--variable-definition-node-p)
("Interface" "list_lit" clojure-ts--interface-node-p)
("Class" "list_lit" clojure-ts--class-node-p))
"The value for `treesit-simple-imenu-settings'.
Expand Down Expand Up @@ -735,7 +739,8 @@ https://github.com/weavejester/cljfmt/blob/fb26b22f569724b05c93eb2502592dfc2de89
(not (treesit-node-eq (treesit-node-child parent 1 t) node))
(let ((first-child (treesit-node-child parent 0 t)))
(or (clojure-ts--symbol-node-p first-child)
(clojure-ts--keyword-node-p first-child)))))
(clojure-ts--keyword-node-p first-child)
(clojure-ts--var-node-p first-child)))))

(defun clojure-ts--match-expression-in-body (node parent _bol)
"Match NODE if it is an expression used in a body argument.
Expand Down
7 changes: 6 additions & 1 deletion test/clojure-ts-mode-indentation-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,9 @@ DESCRIPTION is a string with the description of the spec."
(defn c
\"hello\"
[_foo]
(+ 1 1))"))
(+ 1 1))")

(when-indenting-it "should support function calls via vars"
"
(#'foo 5
6)"))
2 changes: 2 additions & 0 deletions test/samples/indentation.clj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
(clojure.core/filter even?
(range 1 10))

(#'filter even?
(range 10))

(filter
even?
Expand Down

0 comments on commit 3ca382c

Please sign in to comment.