From ac9bc819bc438f21bd38a995812d756727ed8e2a Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Sat, 19 Nov 2022 17:59:14 -0800 Subject: Fix tree-sitter comment indentation for C-like languages The goal is to indent like this: /* comment comment --> This line aligns with the beginning of the first line */ --> This line aligns with the opening comment token * lisp/treesit.el (treesit-comment-start) (treesit-comment-end): New variables. (treesit-simple-indent-presets): New preset comment-end, comment-start, comment-start-skip * lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles) (c-ts-mode) * lisp/progmodes/java-ts-mode.el (java-ts-mode--indent-rules) (java-ts-mode) * lisp/progmodes/js.el (js--treesit-indent-rules) (js-ts-mode) * lisp/progmodes/ts-mode.el (ts-mode--indent-rules) (ts-mode): Add identical indent rules to each mode, and set identical treesit-comment-start/end's. * doc/lispref/modes.texi (Parser-based Indentation) * doc/lispref/parsing.texi (Tree-sitter major modes): Update manual. --- doc/lispref/parsing.texi | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'doc/lispref/parsing.texi') diff --git a/doc/lispref/parsing.texi b/doc/lispref/parsing.texi index feb92345ff4..6a23b0feb33 100644 --- a/doc/lispref/parsing.texi +++ b/doc/lispref/parsing.texi @@ -1731,6 +1731,20 @@ For more information of these built-in tree-sitter features, For supporting mixing of multiple languages in a major mode, @pxref{Multiple Languages}. +Setting the following local variables allows tree-sitter's indentation +engine to correctly indent multi-line comments: + +@defvar treesit-comment-start +This should be a regular expression matching an opening comment token. +For example, it should match @samp{//}, @samp{////}, @samp{/*}, +@samp{/****}, etc., in C. +@end defvar + +@defvar treesit-comment-end +This should be a regular expression matching an closing comment token. +For example, it should match @samp{*/}, @samp{****/}, etc., in C. +@end defvar + @node Tree-sitter C API @section Tree-sitter C API Correspondence -- cgit v1.2.3