1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

Fontify doxygen support to 'c-ts-mode', 'c++-ts-mode' and 'java-ts-mode'

Add doxygen support to 'c-ts-mode', 'c++-ts-mode' and
'java-ts-mode' using tree-sitter-doxygen from
github.com/tree-sitter-grammars.
* lisp/progmodes/c-ts-common.el
(c-ts-mode-doxygen-comment-font-lock-settings): Add font locking
rules for doxygen comment.

* lisp/progmodes/c-ts-mode.el (c-ts-mode--feature-list): Add
'document' feature.
(c-ts-mode--doxygen-comment-regex): New regular expression for
doxygen comments.
(c-ts-mode, c++-ts-mode): Add support for doxygen parser.
* lisp/progmodes/java-ts-mode.el (java-ts-mode): Add support for
doxygen parser.  (Bug#71874)
This commit is contained in:
Vincenzo Pupillo 2024-07-01 12:34:01 +02:00 committed by Eli Zaretskii
parent b23ab37175
commit c77a9b934b
3 changed files with 179 additions and 100 deletions

View file

@ -24,6 +24,8 @@
;;; Commentary:
;;
;; If the tree-sitter doxygen grammar is available, then the comment
;; blocks will be highlighted according to this grammar.
;;; Code:
@ -312,7 +314,7 @@ Return nil if there is no name or if NODE is not a defun node."
(defvar java-ts-mode--feature-list
'(( comment definition )
'(( comment document definition )
( constant keyword string type)
( annotation expression literal)
( bracket delimiter operator)))
@ -326,76 +328,91 @@ Return nil if there is no name or if NODE is not a defun node."
(unless (treesit-ready-p 'java)
(error "Tree-sitter for Java isn't available"))
(treesit-parser-create 'java)
(let ((primary-parser (treesit-parser-create 'java)))
;; Comments.
(c-ts-common-comment-setup)
;; Comments.
(c-ts-common-comment-setup)
;; Indent.
(setq-local c-ts-common-indent-type-regexp-alist
`((block . ,(rx (or "class_body"
"array_initializer"
"constructor_body"
"annotation_type_body"
"interface_body"
"lambda_expression"
"enum_body"
"switch_block"
"record_declaration_body"
"block")))
(close-bracket . "}")
(if . "if_statement")
(else . ("if_statement" . "alternative"))
(for . "for_statement")
(while . "while_statement")
(do . "do_statement")))
(setq-local c-ts-common-indent-offset 'java-ts-mode-indent-offset)
(setq-local treesit-simple-indent-rules java-ts-mode--indent-rules)
;; Indent.
(setq-local c-ts-common-indent-type-regexp-alist
`((block . ,(rx (or "class_body"
"array_initializer"
"constructor_body"
"annotation_type_body"
"interface_body"
"lambda_expression"
"enum_body"
"switch_block"
"record_declaration_body"
"block")))
(close-bracket . "}")
(if . "if_statement")
(else . ("if_statement" . "alternative"))
(for . "for_statement")
(while . "while_statement")
(do . "do_statement")))
(setq-local c-ts-common-indent-offset 'java-ts-mode-indent-offset)
(setq-local treesit-simple-indent-rules java-ts-mode--indent-rules)
;; Electric
(setq-local electric-indent-chars
(append "{}():;," electric-indent-chars))
;; Electric
(setq-local electric-indent-chars
(append "{}():;," electric-indent-chars))
;; Navigation.
(setq-local treesit-defun-type-regexp
(regexp-opt '("method_declaration"
"class_declaration"
"record_declaration"
"interface_declaration"
"enum_declaration"
"import_declaration"
"package_declaration"
"module_declaration"
"constructor_declaration")))
(setq-local treesit-defun-name-function #'java-ts-mode--defun-name)
;; Navigation.
(setq-local treesit-defun-type-regexp
(regexp-opt '("method_declaration"
"class_declaration"
"record_declaration"
"interface_declaration"
"enum_declaration"
"import_declaration"
"package_declaration"
"module_declaration"
"constructor_declaration")))
(setq-local treesit-defun-name-function #'java-ts-mode--defun-name)
(setq-local treesit-thing-settings
`((java
(sexp ,(rx (or "annotation"
"parenthesized_expression"
"argument_list"
"identifier"
"modifiers"
"block"
"body"
"literal"
"access"
"reference"
"_type"
"true"
"false")))
(sentence ,(rx (or "statement"
"local_variable_declaration"
"field_declaration"
"module_declaration"
"package_declaration"
"import_declaration")))
(text ,(regexp-opt '("line_comment"
"block_comment"
"text_block"))))))
(setq-local treesit-thing-settings
`((java
(sexp ,(rx (or "annotation"
"parenthesized_expression"
"argument_list"
"identifier"
"modifiers"
"block"
"body"
"literal"
"access"
"reference"
"_type"
"true"
"false")))
(sentence ,(rx (or "statement"
"local_variable_declaration"
"field_declaration"
"module_declaration"
"package_declaration"
"import_declaration")))
(text ,(regexp-opt '("line_comment"
"block_comment"
"text_block"))))))
;; Font-lock.
(setq-local treesit-font-lock-settings
java-ts-mode--font-lock-settings)
;; Inject doxygen parser for comment.
(when (treesit-ready-p 'doxygen)
(setq-local treesit-primary-parser primary-parser)
(setq-local treesit-font-lock-settings
(append treesit-font-lock-settings
c-ts-mode-doxygen-comment-font-lock-settings))
(setq-local treesit-range-settings
(treesit-range-rules
:embed 'doxygen
:host 'java
:local t
`(((block_comment) @cap (:match "/\\*\\*" @cap)))))))
;; Font-lock.
(setq-local treesit-font-lock-settings java-ts-mode--font-lock-settings)
(setq-local treesit-font-lock-feature-list java-ts-mode--feature-list)
;; Imenu.