@@ -503,6 +503,13 @@ literals with regex grammar."
503
503
(:equal " clojure.core" @ns))
504
504
name: (sym_name) @font-lock-keyword-face))
505
505
(:match , clojure-ts--builtin-symbol-regexp @font-lock-keyword-face))
506
+ ((anon_fn_lit meta: _ :* :anchor (sym_lit !namespace name: (sym_name) @font-lock-keyword-face))
507
+ (:match , clojure-ts--builtin-symbol-regexp @font-lock-keyword-face))
508
+ ((anon_fn_lit meta: _ :* :anchor
509
+ (sym_lit namespace: ((sym_ns) @ns
510
+ (:equal " clojure.core" @ns))
511
+ name: (sym_name) @font-lock-keyword-face))
512
+ (:match , clojure-ts--builtin-symbol-regexp @font-lock-keyword-face))
506
513
((sym_name) @font-lock-builtin-face
507
514
(:match , clojure-ts--builtin-dynamic-var-regexp @font-lock-builtin-face)))
508
515
@@ -715,6 +722,14 @@ literals with regex grammar."
715
722
" Return non-nil if NODE is a Clojure list."
716
723
(string-equal " list_lit" (treesit-node-type node)))
717
724
725
+ (defun clojure-ts--anon-fn-node-p (node )
726
+ " Return non-nil if NODE is a Clojure anonymous lambda."
727
+ (string-equal " anon_fn_lit" (treesit-node-type node)))
728
+
729
+ (defun clojure-ts--opening-paren-node-p (node )
730
+ " Return non-nil if NODE is an opening paren."
731
+ (string-equal " (" (treesit-node-text node)))
732
+
718
733
(defun clojure-ts--symbol-node-p (node )
719
734
" Return non-nil if NODE is a Clojure symbol."
720
735
(string-equal " sym_lit" (treesit-node-type node)))
@@ -1224,7 +1239,8 @@ PARENT not should be a list. If first symbol in the expression has an
1224
1239
indentation rule in `clojure-ts--semantic-indent-rules-defaults' or
1225
1240
`clojure-ts-semantic-indent-rules' check if NODE should be indented
1226
1241
according to the rule. If NODE is nil, use next node after BOL."
1227
- (and (clojure-ts--list-node-p parent)
1242
+ (and (or (clojure-ts--list-node-p parent)
1243
+ (clojure-ts--anon-fn-node-p parent))
1228
1244
(let* ((first-child (clojure-ts--node-child-skip-metadata parent 0 )))
1229
1245
(when-let* ((rule (clojure-ts--find-semantic-rule node parent 0 )))
1230
1246
(and (not (clojure-ts--match-with-metadata node))
@@ -1240,7 +1256,8 @@ according to the rule. If NODE is nil, use next node after BOL."
1240
1256
1241
1257
(defun clojure-ts--match-function-call-arg (node parent _bol )
1242
1258
" Match NODE if PARENT is a list expressing a function or macro call."
1243
- (and (clojure-ts--list-node-p parent)
1259
+ (and (or (clojure-ts--list-node-p parent)
1260
+ (clojure-ts--anon-fn-node-p parent))
1244
1261
; ; Can the following two clauses be replaced by checking indexes?
1245
1262
; ; Does the second child exist, and is it not equal to the current node?
1246
1263
(treesit-node-child parent 1 t )
@@ -1259,7 +1276,8 @@ according to the rule. If NODE is nil, use next node after BOL."
1259
1276
" Match NODE if it is an argument to a PARENT threading macro."
1260
1277
; ; We want threading macros to indent 2 only if the ->> is on it's own line.
1261
1278
; ; If not, then align function arg.
1262
- (and (clojure-ts--list-node-p parent)
1279
+ (and (or (clojure-ts--list-node-p parent)
1280
+ (clojure-ts--anon-fn-node-p parent))
1263
1281
(let ((first-child (treesit-node-child parent 0 t )))
1264
1282
(clojure-ts--symbol-matches-p
1265
1283
clojure-ts--threading-macro
@@ -1310,19 +1328,17 @@ according to the rule. If NODE is nil, use next node after BOL."
1310
1328
(and prev-sibling
1311
1329
(clojure-ts--metadata-node-p prev-sibling))))
1312
1330
1313
- (defun clojure-ts--anchor-parent-skip-metadata (_node parent _bol )
1331
+ (defun clojure-ts--anchor-parent-opening-paren (_node parent _bol )
1314
1332
" Return position of PARENT start for NODE.
1315
1333
1316
1334
If PARENT has optional metadata we skip it and return starting position
1317
1335
of the first child's opening paren.
1318
1336
1319
1337
NOTE: This serves as an anchor function to resolve an indentation issue
1320
1338
for forms with type hints."
1321
- (let ((first-child (treesit-node-child parent 0 t )))
1322
- (if (clojure-ts--metadata-node-p first-child)
1323
- ; ; We don't need named node here
1324
- (treesit-node-start (treesit-node-child parent 1 ))
1325
- (treesit-node-start parent))))
1339
+ (thread-first parent
1340
+ (treesit-search-subtree #'clojure-ts--opening-paren-node-p nil t 1 )
1341
+ (treesit-node-start)))
1326
1342
1327
1343
(defun clojure-ts--match-collection-item-with-metadata (node-type )
1328
1344
" Return a matcher for a collection item with metadata by NODE-TYPE.
@@ -1334,6 +1350,18 @@ if NODE has metadata and its parent has type NODE-TYPE."
1334
1350
(treesit-node-type
1335
1351
(clojure-ts--node-with-metadata-parent node)))))
1336
1352
1353
+ (defun clojure-ts--anchor-nth-sibling (n &optional named )
1354
+ " Return the start of the Nth child of PARENT.
1355
+
1356
+ NAMED non-nil means count only named nodes.
1357
+
1358
+ NOTE: This is a replacement for built-in `nth-sibling' anchor preset,
1359
+ which doesn't work properly for named nodes (see the bug
1360
+ https://debbugs.gnu.org/cgi/bugreport.cgi?bug=78065)"
1361
+ (lambda (_n parent &rest _ )
1362
+ (treesit-node-start
1363
+ (treesit-node-child parent n named))))
1364
+
1337
1365
(defun clojure-ts--semantic-indent-rules ()
1338
1366
" Return a list of indentation rules for `treesit-simple-indent-rules' ."
1339
1367
`((clojure
@@ -1360,11 +1388,11 @@ if NODE has metadata and its parent has type NODE-TYPE."
1360
1388
((parent-is " read_cond_lit" ) parent 3 )
1361
1389
((parent-is " tagged_or_ctor_lit" ) parent 0 )
1362
1390
; ; https://guide.clojure.style/#body-indentation
1363
- (clojure-ts--match-form-body clojure-ts--anchor-parent-skip-metadata 2 )
1391
+ (clojure-ts--match-form-body clojure-ts--anchor-parent-opening-paren 2 )
1364
1392
; ; https://guide.clojure.style/#threading-macros-alignment
1365
1393
(clojure-ts--match-threading-macro-arg prev-sibling 0 )
1366
1394
; ; https://guide.clojure.style/#vertically-align-fn-args
1367
- (clojure-ts--match-function-call-arg ( nth-sibling 2 nil ) 0 )
1395
+ (clojure-ts--match-function-call-arg ,(clojure-ts--anchor- nth-sibling 1 t ) 0 )
1368
1396
; ; https://guide.clojure.style/#one-space-indent
1369
1397
((parent-is " list_lit" ) parent 1 ))))
1370
1398
@@ -1536,6 +1564,14 @@ have changed."
1536
1564
((list_lit
1537
1565
((sym_lit) @sym
1538
1566
(:match ,(clojure-ts-symbol-regexp clojure-ts-align-cond-forms) @sym)))
1567
+ @cond)
1568
+ ((anon_fn_lit
1569
+ ((sym_lit) @sym
1570
+ (:match ,(clojure-ts-symbol-regexp clojure-ts-align-binding-forms) @sym))
1571
+ (vec_lit) @bindings-vec))
1572
+ ((anon_fn_lit
1573
+ ((sym_lit) @sym
1574
+ (:match ,(clojure-ts-symbol-regexp clojure-ts-align-cond-forms) @sym)))
1539
1575
@cond))
1540
1576
(when clojure-ts-align-reader-conditionals
1541
1577
'(((read_cond_lit) @read-cond)
0 commit comments