Skip to content

Commit

Permalink
Fix font locking of defintions with metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
kommen committed Oct 26, 2024
1 parent 76438f6 commit 89e0e71
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Add imenu support for `deftest` definitions.
- [#53]: Let `clojure-ts-mode` derive from `clojure-mode` for Emacs 30+.
- [#42]: Fix imenu support for definitions with metadata.
- [#42]: Fix font locking of definitions with metadata

## 0.2.2 (2024-02-16)

Expand Down
14 changes: 9 additions & 5 deletions clojure-ts-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ if a third argument (the value) is provided.
(defun clojure-ts--docstring-query (capture-symbol)
"Return a query that captures docstrings with CAPTURE-SYMBOL."
`(;; Captures docstrings in def
((list_lit :anchor (sym_lit) @_def_symbol
((list_lit :anchor (meta_lit) :?
:anchor (sym_lit) @_def_symbol
:anchor (comment) :?
:anchor (sym_lit) ; variable name
:anchor (comment) :?
Expand Down Expand Up @@ -288,7 +289,8 @@ if a third argument (the value) is provided.
@_def_symbol)
(:equal @_doc-keyword ":doc"))
;; Captures docstrings defn, defmacro, ns, and things like that
((list_lit :anchor (sym_lit) @_def_symbol
((list_lit :anchor (meta_lit) :?
:anchor (sym_lit) @_def_symbol
:anchor (comment) :?
:anchor (sym_lit) ; function_name
:anchor (comment) :?
Expand Down Expand Up @@ -347,7 +349,7 @@ with the markdown_inline grammar."

:feature 'builtin
:language 'clojure
`(((list_lit :anchor (sym_lit (sym_name) @font-lock-keyword-face))
`(((list_lit meta: _ :? :anchor (sym_lit (sym_name) @font-lock-keyword-face))
(:match ,clojure-ts--builtin-symbol-regexp @font-lock-keyword-face))
((sym_name) @font-lock-builtin-face
(:match ,clojure-ts--builtin-dynamic-var-regexp @font-lock-builtin-face)))
Expand All @@ -369,7 +371,8 @@ with the markdown_inline grammar."
;; No wonder the tree-sitter-clojure grammar only touches syntax, and not semantics
:feature 'definition ;; defn and defn like macros
:language 'clojure
`(((list_lit :anchor (sym_lit (sym_name) @def)
`(((list_lit :anchor meta: _ :?
:anchor (sym_lit (sym_name) @def)
:anchor (sym_lit (sym_name) @font-lock-function-name-face))
(:match ,(rx-to-string
`(seq bol
Expand Down Expand Up @@ -410,7 +413,8 @@ with the markdown_inline grammar."

:feature 'variable ;; def, defonce
:language 'clojure
`(((list_lit :anchor (sym_lit (sym_name) @def)
`(((list_lit :anchor meta: _ :?
:anchor (sym_lit (sym_name) @def)
:anchor (sym_lit (sym_name) @font-lock-variable-name-face))
(:match ,clojure-ts--variable-definition-symbol-regexp @def)))

Expand Down
3 changes: 3 additions & 0 deletions test/samples/test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ clojure.core/map

(def ^Integer x 1)

^{:foo true}
(defn b "hello" [] "world")

(comment
(defrecord TestRecord [field]
AutoCloseable
Expand Down

0 comments on commit 89e0e71

Please sign in to comment.