Skip to content

Commit 3169821

Browse files
committed
Fix font locking of defintions with metadata
1 parent dc74c45 commit 3169821

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- [#46]: Fix missing `comment-add` variable in `clojure-ts-mode-variables` mentioned in [#26]
77
- Add imenu support for `deftest` definitions.
88
- [#53]: Let `clojure-ts-mode` derive from `clojure-mode` for Emacs 30+.
9+
- [#42]: Fix font locking of definitions with metadata
910

1011
## 0.2.2 (2024-02-16)
1112

Diff for: clojure-ts-mode.el

+9-5
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ if a third argument (the value) is provided.
260260
(defun clojure-ts--docstring-query (capture-symbol)
261261
"Return a query that captures docstrings with CAPTURE-SYMBOL."
262262
`(;; Captures docstrings in def
263-
((list_lit :anchor (sym_lit) @_def_symbol
263+
((list_lit :anchor (meta_lit) :?
264+
:anchor (sym_lit) @_def_symbol
264265
:anchor (comment) :?
265266
:anchor (sym_lit) ; variable name
266267
:anchor (comment) :?
@@ -288,7 +289,8 @@ if a third argument (the value) is provided.
288289
@_def_symbol)
289290
(:equal @_doc-keyword ":doc"))
290291
;; Captures docstrings defn, defmacro, ns, and things like that
291-
((list_lit :anchor (sym_lit) @_def_symbol
292+
((list_lit :anchor (meta_lit) :?
293+
:anchor (sym_lit) @_def_symbol
292294
:anchor (comment) :?
293295
:anchor (sym_lit) ; function_name
294296
:anchor (comment) :?
@@ -347,7 +349,7 @@ with the markdown_inline grammar."
347349

348350
:feature 'builtin
349351
:language 'clojure
350-
`(((list_lit :anchor (sym_lit (sym_name) @font-lock-keyword-face))
352+
`(((list_lit meta: _ :? :anchor (sym_lit (sym_name) @font-lock-keyword-face))
351353
(:match ,clojure-ts--builtin-symbol-regexp @font-lock-keyword-face))
352354
((sym_name) @font-lock-builtin-face
353355
(:match ,clojure-ts--builtin-dynamic-var-regexp @font-lock-builtin-face)))
@@ -369,7 +371,8 @@ with the markdown_inline grammar."
369371
;; No wonder the tree-sitter-clojure grammar only touches syntax, and not semantics
370372
:feature 'definition ;; defn and defn like macros
371373
:language 'clojure
372-
`(((list_lit :anchor (sym_lit (sym_name) @def)
374+
`(((list_lit :anchor meta: _ :?
375+
:anchor (sym_lit (sym_name) @def)
373376
:anchor (sym_lit (sym_name) @font-lock-function-name-face))
374377
(:match ,(rx-to-string
375378
`(seq bol
@@ -410,7 +413,8 @@ with the markdown_inline grammar."
410413

411414
:feature 'variable ;; def, defonce
412415
:language 'clojure
413-
`(((list_lit :anchor (sym_lit (sym_name) @def)
416+
`(((list_lit :anchor meta: _ :?
417+
:anchor (sym_lit (sym_name) @def)
414418
:anchor (sym_lit (sym_name) @font-lock-variable-name-face))
415419
(:match ,clojure-ts--variable-definition-symbol-regexp @def)))
416420

Diff for: test/samples/test.clj

+3
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ clojure.core/map
289289

290290
(def ^Integer x 1)
291291

292+
^{:foo true}
293+
(defn b "hello" [] "world")
294+
292295
(comment
293296
(defrecord TestRecord [field]
294297
AutoCloseable

0 commit comments

Comments
 (0)