@@ -195,7 +195,7 @@ Only intended for use at development time.")
195
195
'((t (:inherit font-lock-string-face )))
196
196
" Face used to font-lock Clojure character literals." )
197
197
198
- (defconst clojure-ts--definition-keyword -regexp
198
+ (defconst clojure-ts--definition-symbol -regexp
199
199
(rx
200
200
line-start
201
201
(or (group (or " ns" " fn" ))
@@ -205,14 +205,33 @@ Only intended for use at development time.")
205
205
" -" " _" " !" " @" " #" " $" " %" " ^" " &" " *" " |" " ?" " <" " >" " +" " =" " :" ))))
206
206
line-end))
207
207
208
- (defconst clojure-ts--variable-keyword-regexp
209
- (rx line-start (or " def" " defonce" ) line-end))
208
+ (defconst clojure-ts--variable-definition-symbol-regexp
209
+ (eval-and-compile
210
+ (rx line-start (or " def" " defonce" ) line-end))
211
+ " A regular expression matching a symbol used to define a variable." )
210
212
211
- (defconst clojure-ts--type-keyword-regexp
212
- (rx line-start
213
+ (defconst clojure-ts--typedef-symbol-regexp
214
+ (eval-and-compile
215
+ (rx line-start
213
216
(or " defprotocol" " defmulti" " deftype" " defrecord"
214
217
" definterface" " defmethod" " defstruct" )
215
218
line-end))
219
+ " A regular expression matching a symbol used to define a type" )
220
+
221
+ (defconst clojure-ts-type-symbol-regexp
222
+ (eval-and-compile
223
+ (rx line-start
224
+ (or " deftype" " defrecord"
225
+ ; ; While not reifying, helps with doc strings
226
+ " defprotocol" " definterface"
227
+ " reify" " proxy" " extend-type" " extend-protocol" )
228
+ line-end))
229
+ " A regular expression matching a symbol used to define or instantiate a type." )
230
+
231
+ (defconst clojure-ts--interface-def-symbol-regexp
232
+ (eval-and-compile
233
+ (rx line-start (or " defprotocol" " definterface" ) line-end))
234
+ " A regular expression matching a symbol used to define an interface." )
216
235
217
236
(defun clojure-ts--font-lock-settings ()
218
237
" Return font lock settings suitable for use in `treesit-font-lock-settings' ."
@@ -273,23 +292,23 @@ Only intended for use at development time.")
273
292
:language 'clojure
274
293
`(((list_lit :anchor (sym_lit (sym_name) @def)
275
294
:anchor (sym_lit (sym_name) @font-lock-function-name-face))
276
- (:match , clojure-ts--definition-keyword -regexp @def))
295
+ (:match , clojure-ts--definition-symbol -regexp @def))
277
296
((anon_fn_lit
278
297
marker: " #" @font-lock-property-face)))
279
298
280
299
:feature 'variable ; ; def, defonce
281
300
:language 'clojure
282
301
`(((list_lit :anchor (sym_lit (sym_name) @def)
283
302
:anchor (sym_lit (sym_name) @font-lock-variable-name-face))
284
- (:match , clojure-ts--variable-keyword -regexp @def)))
303
+ (:match , clojure-ts--variable-definition-symbol -regexp @def)))
285
304
286
305
; ; Can we support declarations in the namespace form?
287
306
:feature 'type
288
307
:language 'clojure
289
308
`(; ; Type Declarations
290
309
((list_lit :anchor (sym_lit (sym_name) @def)
291
310
:anchor (sym_lit (sym_name) @font-lock-type-face))
292
- (:match , clojure-ts--type-keyword -regexp @def))
311
+ (:match , clojure-ts--typedef-symbol -regexp @def))
293
312
; ; Type Hints
294
313
(meta_lit
295
314
marker: " ^" @font-lock-operator-face
@@ -314,16 +333,29 @@ Only intended for use at development time.")
314
333
'((tagged_or_ctor_lit marker: " #" @font-lock-preprocessor-face
315
334
tag: (sym_lit) @font-lock-preprocessor-face))
316
335
317
- ; ; TODO, also account for `def'
318
336
; ; Figure out how to highlight symbols in docstrings.
319
337
; ; Might require a markdown grammar
320
338
:feature 'doc
321
339
:language 'clojure
322
340
:override t
323
- `(((list_lit :anchor (sym_lit) @def_symbol
324
- :anchor (sym_lit) @function_name
341
+ `(; ; Captures docstrings in def, defonce
342
+ ((list_lit :anchor (sym_lit) @def_symbol
343
+ :anchor (sym_lit) ; variable name
344
+ :anchor (str_lit) @font-lock-doc-face
345
+ :anchor (_)) ; the variable's value
346
+ (:match , clojure-ts--variable-definition-symbol-regexp @def_symbol))
347
+ ; ; Captures docstrings defn, defmacro, ns, and things like that
348
+ ((list_lit :anchor (sym_lit) @def_symbol
349
+ :anchor (sym_lit) ; function_name
325
350
:anchor (str_lit) @font-lock-doc-face)
326
- (:match , clojure-ts--definition-keyword-regexp @def_symbol)))
351
+ (:match , clojure-ts--definition-symbol-regexp @def_symbol))
352
+ ; ; Captures docstrings in defprotcol, definterface
353
+ ((list_lit :anchor (sym_lit) @def_symbol
354
+ (list_lit
355
+ :anchor (sym_lit) (vec_lit) :*
356
+ (str_lit) @font-lock-doc-face :anchor )
357
+ :* )
358
+ (:match , clojure-ts--interface-def-symbol-regexp @def_symbol)))
327
359
328
360
:feature 'quote
329
361
:language 'clojure
@@ -615,13 +647,6 @@ See `treesit-simple-indent-rules'."
615
647
clojure-ts--symbols-with-body-expressions-regexp
616
648
first-child)))))
617
649
618
- (defconst clojure-ts--reifying-symbol-regexp
619
- (eval-and-compile
620
- (rx line-start
621
- (or " deftype" " defrecord"
622
- " reify" " proxy" " extend-type" " extend-protocol" )))
623
- " A regular expression matching a symbol used to define a concrete type." )
624
-
625
650
(defun clojure-ts--match-method-body (node parent _bol )
626
651
" Matches a `NODE' in the body of a `PARENT' method implementation.
627
652
A method implementation referes to concrete implemntations being defined in
@@ -632,7 +657,7 @@ forms like deftype, defrecord, reify, proxy, etc."
632
657
; ; auncle: gender neutral sibling of parent, aka child of grandparent
633
658
(first-auncle (treesit-node-child grandparent 0 t )))
634
659
(and (clojure-ts--list-node-p grandparent)
635
- (clojure-ts--symbol-matches-p clojure-ts--reifying -symbol-regexp
660
+ (clojure-ts--symbol-matches-p clojure-ts-type -symbol-regexp
636
661
first-auncle)))))
637
662
638
663
(defvar clojure-ts--threading-macro
@@ -734,7 +759,7 @@ forms like deftype, defrecord, reify, proxy, etc."
734
759
treesit-font-lock-feature-list
735
760
'((comment definition variable)
736
761
(keyword string char symbol builtin type)
737
- (constant number quote metadata)
762
+ (constant number quote metadata doc )
738
763
(bracket deref function regex tagged-literals)))
739
764
(when (boundp 'treesit-thing-settings ) ; ; Emacs 30+
740
765
(setq-local treesit-thing-settings clojure-ts--thing-settings))
0 commit comments