Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scala-ts-mode properly recognizes line comments as comment syntax #20

Merged
merged 1 commit into from
Sep 4, 2024

Conversation

KarlJoad
Copy link
Contributor

@KarlJoad KarlJoad commented Sep 2, 2024

This lets Emacs recognize // line comment as proper comment syntax, rather than just unformatted text. The behavior of /* block comments */ is unchanged.

These syntax-table entries are the same as java-ts-mode's, since both languages use the same comment syntax.

Closes #17.

KarlJoad added a commit to KarlJoad/Emacs_dotfiles that referenced this pull request Sep 2, 2024
This can be removed when [1] is merged into the upstream
scala-ts-mode.

[1] KaranAhlawat/scala-ts-mode#20
@KaranAhlawat
Copy link
Owner

I think it would be good to check the syntax table we have here with https://github.com/hvesalai/emacs-scala-mode and see if we're doing the correct thing for comments. If the two are same for comments, please let me know and I'll merge. Otherwise please fix any discrepencies. Thanks for your contribution!

@KarlJoad
Copy link
Contributor Author

KarlJoad commented Sep 3, 2024

I just checked, and it looks like emacs-scala-mode uses the exact same thing as Java's. I omitted the carriage return character though. I will add that and push.

@KarlJoad KarlJoad force-pushed the fix-comments-syntax-table branch from 42da974 to 47ddc23 Compare September 3, 2024 15:38
@KaranAhlawat
Copy link
Owner

It also looks like scala-mode (no TS) allows for nested multi-line comments, here , could you take a look at that?

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.
@KarlJoad KarlJoad force-pushed the fix-comments-syntax-table branch from 47ddc23 to 0fc8e1f Compare September 4, 2024 16:20
@KarlJoad
Copy link
Contributor Author

KarlJoad commented Sep 4, 2024

From just a quick test, this change (without n) also handled nested multi-line comments.

sealed trait Test {
  // TODO: This is a quick note
  // Another
  /* The start of a large comment block.
   * Now inside of the comment block, we nest another comment.
   * /* The nested comment that is also
   *  * multi-line! */
   * */
  def foo(): Unit = {}
}

Placing point anywhere inside of the comment block, including inside the nested one, and running the following command: M-: (nth 8 (syntax-ppss)) returns non-nil, which means Emacs understands the contents as comments. If you run that same command on the def keyword, you will get nil back.

I can add n, sure.

Not even Emacs' built-in java-ts-mode does not use n, so I am not sure how important it really is.
https://github.com/emacs-mirror/emacs/blob/2847106f3b6174f25ab43551f96612209fe951c8/lisp/progmodes/java-ts-mode.el#L66-L69

@KaranAhlawat
Copy link
Owner

Alright, everything looks good to me. Thank you for your patience and contribution!

@KaranAhlawat KaranAhlawat merged commit 0c0099b into KaranAhlawat:main Sep 4, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Comment starting position is not correctlty detected
2 participants