@@ -514,6 +514,13 @@ literals with regex grammar."
514
514
(:equal " clojure.core" @ns))
515
515
name: (sym_name) @font-lock-keyword-face))
516
516
(:match , clojure-ts--builtin-symbol-regexp @font-lock-keyword-face))
517
+ ((anon_fn_lit meta: _ :* :anchor (sym_lit !namespace name: (sym_name) @font-lock-keyword-face))
518
+ (:match , clojure-ts--builtin-symbol-regexp @font-lock-keyword-face))
519
+ ((anon_fn_lit meta: _ :* :anchor
520
+ (sym_lit namespace: ((sym_ns) @ns
521
+ (:equal " clojure.core" @ns))
522
+ name: (sym_name) @font-lock-keyword-face))
523
+ (:match , clojure-ts--builtin-symbol-regexp @font-lock-keyword-face))
517
524
((sym_name) @font-lock-builtin-face
518
525
(:match , clojure-ts--builtin-dynamic-var-regexp @font-lock-builtin-face)))
519
526
@@ -726,6 +733,14 @@ literals with regex grammar."
726
733
" Return non-nil if NODE is a Clojure list."
727
734
(string-equal " list_lit" (treesit-node-type node)))
728
735
736
+ (defun clojure-ts--anon-fn-node-p (node )
737
+ " Return non-nil if NODE is a Clojure function literal."
738
+ (string-equal " anon_fn_lit" (treesit-node-type node)))
739
+
740
+ (defun clojure-ts--opening-paren-node-p (node )
741
+ " Return non-nil if NODE is an opening paren."
742
+ (string-equal " (" (treesit-node-text node)))
743
+
729
744
(defun clojure-ts--symbol-node-p (node )
730
745
" Return non-nil if NODE is a Clojure symbol."
731
746
(string-equal " sym_lit" (treesit-node-type node)))
@@ -1249,7 +1264,8 @@ PARENT not should be a list. If first symbol in the expression has an
1249
1264
indentation rule in `clojure-ts--semantic-indent-rules-defaults' or
1250
1265
`clojure-ts-semantic-indent-rules' check if NODE should be indented
1251
1266
according to the rule. If NODE is nil, use next node after BOL."
1252
- (and (clojure-ts--list-node-p parent)
1267
+ (and (or (clojure-ts--list-node-p parent)
1268
+ (clojure-ts--anon-fn-node-p parent))
1253
1269
(let* ((first-child (clojure-ts--node-child-skip-metadata parent 0 )))
1254
1270
(when-let* ((rule (clojure-ts--find-semantic-rule node parent 0 )))
1255
1271
(and (not (clojure-ts--match-with-metadata node))
@@ -1265,7 +1281,8 @@ according to the rule. If NODE is nil, use next node after BOL."
1265
1281
1266
1282
(defun clojure-ts--match-function-call-arg (node parent _bol )
1267
1283
" Match NODE if PARENT is a list expressing a function or macro call."
1268
- (and (clojure-ts--list-node-p parent)
1284
+ (and (or (clojure-ts--list-node-p parent)
1285
+ (clojure-ts--anon-fn-node-p parent))
1269
1286
; ; Can the following two clauses be replaced by checking indexes?
1270
1287
; ; Does the second child exist, and is it not equal to the current node?
1271
1288
(treesit-node-child parent 1 t )
@@ -1284,7 +1301,8 @@ according to the rule. If NODE is nil, use next node after BOL."
1284
1301
" Match NODE if it is an argument to a PARENT threading macro."
1285
1302
; ; We want threading macros to indent 2 only if the ->> is on it's own line.
1286
1303
; ; If not, then align function arg.
1287
- (and (clojure-ts--list-node-p parent)
1304
+ (and (or (clojure-ts--list-node-p parent)
1305
+ (clojure-ts--anon-fn-node-p parent))
1288
1306
(let ((first-child (treesit-node-child parent 0 t )))
1289
1307
(clojure-ts--symbol-matches-p
1290
1308
clojure-ts--threading-macro
@@ -1335,19 +1353,17 @@ according to the rule. If NODE is nil, use next node after BOL."
1335
1353
(and prev-sibling
1336
1354
(clojure-ts--metadata-node-p prev-sibling))))
1337
1355
1338
- (defun clojure-ts--anchor-parent-skip-metadata (_node parent _bol )
1356
+ (defun clojure-ts--anchor-parent-opening-paren (_node parent _bol )
1339
1357
" Return position of PARENT start for NODE.
1340
1358
1341
1359
If PARENT has optional metadata we skip it and return starting position
1342
1360
of the first child's opening paren.
1343
1361
1344
1362
NOTE: This serves as an anchor function to resolve an indentation issue
1345
1363
for forms with type hints."
1346
- (let ((first-child (treesit-node-child parent 0 t )))
1347
- (if (clojure-ts--metadata-node-p first-child)
1348
- ; ; We don't need named node here
1349
- (treesit-node-start (treesit-node-child parent 1 ))
1350
- (treesit-node-start parent))))
1364
+ (thread-first parent
1365
+ (treesit-search-subtree #'clojure-ts--opening-paren-node-p nil t 1 )
1366
+ (treesit-node-start)))
1351
1367
1352
1368
(defun clojure-ts--match-collection-item-with-metadata (node-type )
1353
1369
" Return a matcher for a collection item with metadata by NODE-TYPE.
@@ -1359,6 +1375,18 @@ if NODE has metadata and its parent has type NODE-TYPE."
1359
1375
(treesit-node-type
1360
1376
(clojure-ts--node-with-metadata-parent node)))))
1361
1377
1378
+ (defun clojure-ts--anchor-nth-sibling (n &optional named )
1379
+ " Return the start of the Nth child of PARENT.
1380
+
1381
+ NAMED non-nil means count only named nodes.
1382
+
1383
+ NOTE: This is a replacement for built-in `nth-sibling' anchor preset,
1384
+ which doesn't work properly for named nodes (see the bug
1385
+ https://debbugs.gnu.org/cgi/bugreport.cgi?bug=78065)"
1386
+ (lambda (_n parent &rest _ )
1387
+ (treesit-node-start
1388
+ (treesit-node-child parent n named))))
1389
+
1362
1390
(defun clojure-ts--semantic-indent-rules ()
1363
1391
" Return a list of indentation rules for `treesit-simple-indent-rules' ."
1364
1392
`((clojure
@@ -1385,11 +1413,11 @@ if NODE has metadata and its parent has type NODE-TYPE."
1385
1413
((parent-is " read_cond_lit" ) parent 3 )
1386
1414
((parent-is " tagged_or_ctor_lit" ) parent 0 )
1387
1415
; ; https://guide.clojure.style/#body-indentation
1388
- (clojure-ts--match-form-body clojure-ts--anchor-parent-skip-metadata 2 )
1416
+ (clojure-ts--match-form-body clojure-ts--anchor-parent-opening-paren 2 )
1389
1417
; ; https://guide.clojure.style/#threading-macros-alignment
1390
1418
(clojure-ts--match-threading-macro-arg prev-sibling 0 )
1391
1419
; ; https://guide.clojure.style/#vertically-align-fn-args
1392
- (clojure-ts--match-function-call-arg ( nth-sibling 2 nil ) 0 )
1420
+ (clojure-ts--match-function-call-arg ,(clojure-ts--anchor- nth-sibling 1 t ) 0 )
1393
1421
; ; https://guide.clojure.style/#one-space-indent
1394
1422
((parent-is " list_lit" ) parent 1 ))))
1395
1423
@@ -1561,6 +1589,14 @@ have changed."
1561
1589
((list_lit
1562
1590
((sym_lit) @sym
1563
1591
(:match ,(clojure-ts-symbol-regexp clojure-ts-align-cond-forms) @sym)))
1592
+ @cond)
1593
+ ((anon_fn_lit
1594
+ ((sym_lit) @sym
1595
+ (:match ,(clojure-ts-symbol-regexp clojure-ts-align-binding-forms) @sym))
1596
+ (vec_lit) @bindings-vec))
1597
+ ((anon_fn_lit
1598
+ ((sym_lit) @sym
1599
+ (:match ,(clojure-ts-symbol-regexp clojure-ts-align-cond-forms) @sym)))
1564
1600
@cond))
1565
1601
(when clojure-ts-align-reader-conditionals
1566
1602
'(((read_cond_lit) @read-cond)
0 commit comments