Skip to content

Commit 0fc8e1f

Browse files
committed
scala-ts-mode properly recognizes line comments as comment syntax
These syntax-table entries are the same as java-ts-mode's. This lets Emacs recognize "// line comment" as proper comment syntax, rather than just unformatted text. The behavior of "/* block comments */" is unchanged.
1 parent 831f64a commit 0fc8e1f

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

scala-ts-mode.el

+19-19
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@
6868
(modify-syntax-entry ?\\ "\\" table) ; Escape seq start
6969
(modify-syntax-entry ?\" "\"" table) ; String start
7070
(modify-syntax-entry ?' "/" table) ; Char start
71-
(modify-syntax-entry ?/ "< 12" table) ; Comment seq a, first two char are /
72-
(modify-syntax-entry ?\n ">" table) ; Comment seq a, ends with a newline
73-
(modify-syntax-entry ?/ ". 14b" table) ; Comment seq b, starts and ends with /
74-
(modify-syntax-entry ?* ". 23b" table) ; Comment seq b, second start and first end char is *
71+
(modify-syntax-entry ?/ ". 124b" table) ; Line/block comment // or /* */
72+
(modify-syntax-entry ?* ". 23n" table) ; Block comment /* */
73+
(modify-syntax-entry ?\n "> b" table) ; Comment ends with newline
74+
(modify-syntax-entry ?\r "> b" table) ; Comment ends with carriage return
7575
table)
7676
"Syntax table for `scala-ts-mode'.")
7777

@@ -144,7 +144,7 @@
144144
:feature 'extra
145145
`([,@scala-ts--brackets] @font-lock-bracket-face
146146
[,@scala-ts--delimiters] @font-lock-delimiter-face)
147-
147+
148148
:language 'scala
149149
:feature 'comment
150150
'((comment) @font-lock-comment-face
@@ -197,7 +197,7 @@
197197
(:match "^[A-Z]" @font-lock-function-call-face))
198198
(generic_function
199199
function: (identifier) @font-lock-function-call-face)
200-
200+
201201

202202
;; function definitions
203203
(function_definition
@@ -355,7 +355,7 @@
355355
(string= (treesit-node-type node)
356356
"then"))
357357
0)
358-
358+
359359
;; indented and non
360360
(t offset))))
361361

@@ -392,7 +392,7 @@
392392
"identifier")
393393
offset
394394
0)))
395-
395+
396396
((rx (| scala-ts--indent-keywords scala-ts--indent) eol)
397397
offset)
398398

@@ -408,7 +408,7 @@
408408
(pcase (treesit-node-type last-node)
409409
("ERROR"
410410
(scala-ts--indent-error-anchor nil last-node pos))
411-
411+
412412
((rx scala-ts--indent-keywords eol)
413413
(goto-char (treesit-node-start last-node))
414414
(back-to-indentation)
@@ -440,7 +440,7 @@
440440
(pcase (treesit-node-type last-node)
441441
("ERROR"
442442
(scala-ts--indent-error-offset nil last-node pos))
443-
443+
444444
((rx scala-ts--indent-keywords eol)
445445
(goto-char (treesit-node-start last-node))
446446
(back-to-indentation)
@@ -480,21 +480,21 @@ or node matching `treesit-defun-type-regexp' is found."
480480
(let ((offset scala-ts-indent-offset))
481481
`((scala
482482
((node-is "^comment$") no-indent 0)
483-
483+
484484
((node-is "^}$") parent-bol 0)
485485
((node-is "^)$") parent-bol 0)
486-
486+
487487
((parent-is "^if_expression$")
488488
scala-ts--indent-if-anchor
489489
scala-ts--indent-if-offset)
490490
;; Handle else-if
491491
((n-p-gp "^postfix_expression$" "^indented_block$" "^if_expression$") grand-parent 0)
492-
492+
493493
((n-p-gp "^enumerators$" "^for_expression$" nil) parent-bol ,offset)
494494
((n-p-gp "^enumerator$" "^enumerators$" nil) parent 0)
495495
((n-p-gp "^ERROR$" "^enumerators$" nil) prev-line ,(- offset))
496496
((n-p-gp "^yield$" "^for_expression$" nil) parent-bol 0)
497-
497+
498498
((n-p-gp "^catch_clause$" "^try_expression$" nil) parent 0)
499499
((n-p-gp "^finally_clause$" "^try_expression$" nil) parent 0)
500500

@@ -510,9 +510,9 @@ or node matching `treesit-defun-type-regexp' is found."
510510
(- ,offset)
511511
,offset)))
512512
((parent-is "^case_clause$") parent ,offset)
513-
513+
514514
((node-is "^end$") scala-ts--indent-end 0)
515-
515+
516516
;; Handle function annotations
517517
((n-p-gp "^def$" "^function_definition$" nil) parent 0)
518518

@@ -539,7 +539,7 @@ or node matching `treesit-defun-type-regexp' is found."
539539
((parent-is "^parameters$") parent-bol ,offset)
540540
((parent-is "^arguments$") parent-bol ,offset)
541541
((parent-is "^tuple_expression$") parent ,offset)
542-
542+
543543
((node-is "definition") prev-sibling 0)
544544
((node-is "declaration") prev-sibling 0)
545545
((node-is "^enum_body$") prev-sibling 0)
@@ -555,7 +555,7 @@ or node matching `treesit-defun-type-regexp' is found."
555555
"finally"))
556556
(- ,offset)
557557
0)))
558-
558+
559559
((n-p-gp "^call_expression$" "^indented_block$" nil)
560560
(lambda (node parent _bol)
561561
parent
@@ -573,7 +573,7 @@ or node matching `treesit-defun-type-regexp' is found."
573573
"block")))
574574
(- ,offset)
575575
0)))
576-
576+
577577
((n-p-gp "^indented_block$" "^ERROR$" nil) no-indent 0)
578578
((parent-is "^indented_block$") parent 0)
579579
((parent-is "^block$") parent-bol ,offset)

0 commit comments

Comments
 (0)