diff --git a/CHANGELOG.md b/CHANGELOG.md index 666bc9a..c167910 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/clojure-ts-mode.el b/clojure-ts-mode.el index 09247cc..f45763c 100644 --- a/clojure-ts-mode.el +++ b/clojure-ts-mode.el @@ -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." @@ -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) @@ -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'. @@ -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. diff --git a/test/samples/indentation.clj b/test/samples/indentation.clj index 2996229..f87870d 100644 --- a/test/samples/indentation.clj +++ b/test/samples/indentation.clj @@ -60,6 +60,8 @@ (clojure.core/filter even? (range 1 10)) +(#'filter even? + (range 10)) (filter even?