445
445
(back-to-indentation )
446
446
(point ))))))
447
447
448
+ (defun scala-ts--move-out-of-indented-block (&rest _ )
449
+ " Correction when jumping at the beginning of a defun.
450
+ If point is in \" indented_block\" move it at the beginning of the
451
+ block. End search as soon as either \" indented_block\" is found
452
+ or node matching `treesit-defun-type-regexp' is found."
453
+ (let* ((pred (lambda (node )
454
+ (let ((type (treesit-node-type node)))
455
+ (or
456
+ (string= " indented_block" type)
457
+ (string-match-p treesit-defun-type-regexp type)))))
458
+ (node (treesit-parent-until (treesit-node-at (point )) pred t )))
459
+ (when (string= " indented_block" (treesit-node-type node))
460
+ (goto-char (treesit-node-start node)))))
461
+
448
462
(defvar scala-ts--indent-rules
449
463
(let ((offset scala-ts-indent-offset))
450
464
`((scala
@@ -549,6 +563,10 @@ Return nil if there is no name or if NODE is not a defun node."
549
563
(treesit-node-text
550
564
(treesit-node-child-by-field-name node " name" )
551
565
t ))
566
+ (" val_definition"
567
+ (treesit-node-text
568
+ (treesit-node-child-by-field-name node " pattern" )
569
+ t ))
552
570
(" function_declaration"
553
571
(treesit-node-text
554
572
(treesit-node-child node 0 )
@@ -579,6 +597,14 @@ Return nil if there is no name or if NODE is not a defun node."
579
597
(setq-local
580
598
treesit-simple-indent-rules scala-ts--indent-rules)
581
599
600
+ ; ; Navigation.
601
+ (setq-local treesit-defun-type-regexp
602
+ (rx (or " class_definition"
603
+ " object_definition"
604
+ " trait_definition"
605
+ " function_definition"
606
+ " val_definition" )))
607
+
582
608
(setq-local treesit-defun-name-function #'scala-ts--defun-name )
583
609
; ; TODO (could possibly be more complex?)
584
610
(setq-local treesit-simple-imenu-settings
@@ -588,7 +614,9 @@ Return nil if there is no name or if NODE is not a defun node."
588
614
(" Object" " \\ `object_definition\\ '" nil nil)
589
615
(" Function" " \\ `function_definition\\ '" nil nil)
590
616
(" Definition" " \\ `function_declaration'" nil nil)))
591
-
617
+
618
+ (advice-add 'treesit-beginning-of-defun :before #'scala-ts--move-out-of-indented-block)
619
+
592
620
(treesit-major-mode-setup)))
593
621
594
622
;;;###autoload
0 commit comments