From 9d2e740737467363fca71e2f21894a1ae37117c2 Mon Sep 17 00:00:00 2001 From: Vincenzo Pupillo Date: Mon, 9 Sep 2024 09:20:42 +0200 Subject: [PATCH] Add user option to enable Doxygen syntax highlighting (bug#72814) Both 'c-ts-mode' and 'java-ts-mode' have a new user option, 'c-ts-mode-enable-doxygen' and 'java-ts-mode-enable-doxygen' (defaults to nil) which allow to enable syntax highlighting of comment blocks based on the Doxygen grammar. * lisp/progmodes/c-ts-mode.el: Add the 'c-ts-mode-enable-doxygen' user option variable to disable doxygen grammar. Notifies the user if doxygen grammar is not available. * lisp/progmodes/c-ts-mode.el (c-ts-mode, c++-ts-mode): Use the new 'c-ts-mode-enable-doxygen' option. * lisp/progmodes/java-ts-mode.el: Add the 'java-ts-mode-enable-doxygen' user option variable to disable doxygen grammar. Notifies the user if doxygen grammar is not available. * lisp/progmodes/java-ts-mode.el (java-ts-mode): Use the new 'java-ts-mode-enable-doxygen' option. * etc/NEWS: Document the change. (cherry picked from commit b0523dffabbec8acd9c5c92711af849a11867884) --- etc/NEWS | 16 ++++++++++++++++ lisp/progmodes/c-ts-mode.el | 20 +++++++++++++++++--- lisp/progmodes/java-ts-mode.el | 18 ++++++++++++++++-- 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 63e4dcc2a54..57362f3bc01 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -220,6 +220,22 @@ package of the current buffer. It is bound to 'C-c C-t p' in 'go-ts-mode'. The 'go-ts-mode-build-tags' user option is available to set a list of build tags for the test commands. +** C-ts mode + ++++ +*** New user option 'c-ts-mode-enable-doxygen'. +By default, 'c-ts-mode-enable-doxygen' is nil, and the comment blocks +are highlighted like other comments. When Non-nil doxygen comment +blocks are syntax-highlighted if the doxygen grammar is available. + +** Java-ts mode + ++++ +*** New user option 'java-ts-mode-enable-doxygen'. +By default, 'java-ts-mode-enable-doxygen' is nil, and the comment blocks +are highlighted like other comments. When Non-nil doxygen comment +blocks are syntax-highlighted if the doxygen grammar is available. + ** Emacs Lisp mode --- diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 804d0040f5c..303c994637c 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -65,7 +65,7 @@ ;; libraries installed. ;; ;; If the tree-sitter doxygen grammar is available, then the comment -;; blocks will be highlighted according to this grammar. +;; blocks can be highlighted according to this grammar. ;;; Code: @@ -216,6 +216,17 @@ again." :safe 'booleanp :group 'c) +(defcustom c-ts-mode-enable-doxygen nil + "Enable doxygen syntax highlighting. +If Non-nil, enable doxygen based font lock for comment blocks. +This needs to be set before enabling `c-ts-mode'; if you change +the value after enabling `c-ts-mode', toggle the mode off and on +again." + :version "31.1" + :type 'boolean + :safe 'booleanp + :group 'c) + ;;; Syntax table (defvar c-ts-mode--syntax-table @@ -1365,7 +1376,7 @@ in your init files." (treesit-font-lock-recompute-features '(emacs-devel))) ;; Inject doxygen parser for comment. - (when (treesit-ready-p 'doxygen t) + (when (and c-ts-mode-enable-doxygen (treesit-ready-p 'doxygen t)) (setq-local treesit-primary-parser primary-parser) (setq-local treesit-font-lock-settings (append @@ -1426,7 +1437,7 @@ recommended to enable `electric-pair-mode' with this mode." #'c-ts-mode--emacs-current-defun-name)) ;; Inject doxygen parser for comment. - (when (treesit-ready-p 'doxygen t) + (when (and c-ts-mode-enable-doxygen (treesit-ready-p 'doxygen t)) (setq-local treesit-primary-parser primary-parser) (setq-local treesit-font-lock-settings (append @@ -1538,6 +1549,9 @@ the code is C or C++, and based on that chooses whether to enable (treesit-ready-p 'c)) (add-to-list 'major-mode-remap-defaults '(c-or-c++-mode . c-or-c++-ts-mode))) +(when (and c-ts-mode-enable-doxygen (not (treesit-ready-p 'doxygen t))) + (message "Doxygen syntax highlighting can't be enabled, please install the language grammar.")) + (provide 'c-ts-mode) (provide 'c++-ts-mode) diff --git a/lisp/progmodes/java-ts-mode.el b/lisp/progmodes/java-ts-mode.el index ac104534734..177f914160c 100644 --- a/lisp/progmodes/java-ts-mode.el +++ b/lisp/progmodes/java-ts-mode.el @@ -25,7 +25,7 @@ ;;; Commentary: ;; ;; If the tree-sitter doxygen grammar is available, then the comment -;; blocks will be highlighted according to this grammar. +;; blocks can be highlighted according to this grammar. ;;; Code: @@ -48,6 +48,17 @@ :safe 'integerp :group 'java) +(defcustom java-ts-mode-enable-doxygen nil + "Enable doxygen syntax highlighting. +If Non-nil, enable doxygen based font lock for comment blocks. +This needs to be set before enabling `java-ts-mode'; if you change +the value after enabling `java-ts-mode', toggle the mode off and on +again." + :version "31.1" + :type 'boolean + :safe 'booleanp + :group 'java) + (defvar java-ts-mode--syntax-table (let ((table (make-syntax-table))) ;; Taken from the cc-langs version @@ -401,7 +412,7 @@ Return nil if there is no name or if NODE is not a defun node." java-ts-mode--font-lock-settings) ;; Inject doxygen parser for comment. - (when (treesit-ready-p 'doxygen t) + (when (and java-ts-mode-enable-doxygen (treesit-ready-p 'doxygen t)) (setq-local treesit-primary-parser primary-parser) (setq-local treesit-font-lock-settings (append treesit-font-lock-settings @@ -428,6 +439,9 @@ Return nil if there is no name or if NODE is not a defun node." (if (treesit-ready-p 'java) (add-to-list 'auto-mode-alist '("\\.java\\'" . java-ts-mode))) +(when (and java-ts-mode-enable-doxygen (not (treesit-ready-p 'doxygen t))) + (message "Doxygen syntax highlighting can't be enabled, please install the language grammar.")) + (provide 'java-ts-mode) ;;; java-ts-mode.el ends here -- 2.39.5