* bug#59251: 29.0.50; Fix-some-inconsistencies-in-ts-modes @ 2022-11-13 20:42 Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors [not found] ` <handler.59251.B.16683721605982.ack@debbugs.gnu.org> 2022-11-14 18:59 ` bug#59251: 29.0.50; Fix-some-inconsistencies-in-ts-modes Eli Zaretskii 0 siblings, 2 replies; 11+ messages in thread From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-11-13 20:42 UTC (permalink / raw) To: 59251; +Cc: casouri [-- Attachment #1: Type: text/plain, Size: 626 bytes --] Hi Yuan! I've make some changes to my *-ts-modes, and would appreciate a second opinion as well as a push to the feature/tree-sitter branch :-) I've extracted some of the relevant mode-init variables into defcustoms so that users can tweak their behavior. It also seems I forgot some electric indent configs in some of the other files, so I added that aswell. BTW, should we do the same thing we did with js-mode - add a js-ts-mode and don't change the js.el file at all? We could either go the same route as c-ts-mode, where we define both c and c++ in the same file, or keep them separate. What do you think? Theo [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-Fix-some-inconsistencies-in-ts-modes.patch --] [-- Type: text/x-diff, Size: 10970 bytes --] From 0c2181a0bd3dbcf8c896404932fbd8eb2d2ee897 Mon Sep 17 00:00:00 2001 From: Theodor Thornhill <theo@thornhill.no> Date: Sun, 13 Nov 2022 21:37:01 +0100 Subject: [PATCH] Fix some inconsistencies in *-ts-modes * lisp/progmodes/c-ts-mode.el (c-ts-mode-comment-style): New defcustom. (c-ts-mode-font-lock-feature-list): New defcustom. (c-ts-mode--base-mode): Extract comment-* so that we can separate between C and C++. Use the new font-lock-feature-list defcustom. (c-ts-mode, c++-ts-mode): Set comment-* variables. * lisp/progmodes/css-ts-mode.el (css-ts-mode): Add electric-indent. * lisp/progmodes/java-ts-mode.el (java-ts-mode-font-lock-feature-list): New defcustom. (java-ts-mode): Add electric-indent and use the font-lock-feature-list defcustom. * lisp/progmodes/json-ts-mode.el (json-ts-mode-font-lock-feature-list): New defcustom. (json-ts-mode--font-lock-settings): Make much more granular font lock features. (json-ts-mode): Add electric-indent and use the font-lock-feature-list defcustom. * lisp/progmodes/ts-mode.el (ts-mode-font-lock-feature-list): New defcustom. (ts-mode--font-lock-settings): Whitespace cleanup. (ts-mode): Add electric-indent and use the font-lock-feature-list defcustom. --- lisp/progmodes/c-ts-mode.el | 42 ++++++++++++++++++++++------- lisp/progmodes/css-ts-mode.el | 4 +++ lisp/progmodes/java-ts-mode.el | 21 ++++++++++++--- lisp/progmodes/json-ts-mode.el | 49 ++++++++++++++++++++++++---------- lisp/progmodes/ts-mode.el | 30 ++++++++++++++++++--- 5 files changed, 116 insertions(+), 30 deletions(-) diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 5617ea7d7c..75ab5ed737 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -31,6 +31,25 @@ (require 'treesit) (require 'rx) +(defcustom c-ts-mode-comment-style 'multi-line + "The comment style as decided by `comment-styles'" + :type 'symbol + :safe 'symbolp + :group 'c) + +(defcustom c-ts-mode-font-lock-feature-list + '((comment preprocessor operator constant string literal keyword) + (type definition expression statement) + ()) + "Language constructs to font-lock. + +See `treesit-font-lock-feature-list' for description of how to +use this variable. Supported features are as defined in +`c-ts-mode--font-lock-settings'." + :type 'list + :safe 'listp + :group 'c) + (defcustom c-ts-mode-indent-offset 2 "Number of spaces for each indentation step in `c-ts-mode'." :type 'integer @@ -399,11 +418,6 @@ c-ts-mode--base-mode :group 'c :syntax-table c-ts-mode--syntax-table - ;; Comments. - (setq-local comment-start "// ") - (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *") - (setq-local comment-end "") - ;; Navigation. (setq-local treesit-defun-type-regexp (rx (or "specifier" @@ -415,16 +429,14 @@ c-ts-mode--base-mode ;; Electric (setq-local electric-indent-chars - (append "{}():;," electric-indent-chars)) + (append "{}():;," electric-indent-chars)) ;; Imenu. (setq-local imenu-create-index-function #'c-ts-mode--imenu) (setq-local which-func-functions nil) (setq-local treesit-font-lock-feature-list - '((comment preprocessor operator constant string literal keyword) - (type definition expression statement) - (error)))) + c-ts-mode-font-lock-feature-list)) ;;;###autoload (define-derived-mode c-ts-mode c-ts-mode--base-mode "C" @@ -436,6 +448,12 @@ c-ts-mode (treesit-parser-create 'c) + ;; Comments. + (setq-local comment-start "/* ") + (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *") + (setq-local comment-end " */") + (setq-local comment-style c-ts-mode-comment-style) + (setq-local treesit-simple-indent-rules (c-ts-mode--set-indent-style 'c)) @@ -452,6 +470,12 @@ c++-ts-mode (unless (treesit-ready-p nil 'cpp) (error "Tree-sitter for C++ isn't available")) + ;; Comments. + (setq-local comment-start "// ") + (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *") + (setq-local comment-end "") + (setq-local comment-style c-ts-mode-comment-style) + (treesit-parser-create 'cpp) (setq-local treesit-simple-indent-rules diff --git a/lisp/progmodes/css-ts-mode.el b/lisp/progmodes/css-ts-mode.el index e22bf99c6c..8cb6074043 100644 --- a/lisp/progmodes/css-ts-mode.el +++ b/lisp/progmodes/css-ts-mode.el @@ -114,6 +114,10 @@ css-ts-mode ;; Indent. (setq-local treesit-simple-indent-rules css-ts-mode--indent-rules) + ;; Electric + (setq-local electric-indent-chars + (append "{}():;," electric-indent-chars)) + ;; Navigation. (setq-local treesit-defun-type-regexp "rule_set") ;; Font-lock. diff --git a/lisp/progmodes/java-ts-mode.el b/lisp/progmodes/java-ts-mode.el index 5ec7da9f5c..8aed2db9c6 100644 --- a/lisp/progmodes/java-ts-mode.el +++ b/lisp/progmodes/java-ts-mode.el @@ -31,6 +31,19 @@ (require 'treesit) (require 'rx) +(defcustom java-ts-mode-font-lock-feature-list + '((basic comment keyword constant string operator) + (type definition expression literal annotation) + ()) + "Language constructs to font-lock. + +See `treesit-font-lock-feature-list' for description of how to +use this variable. Supported features are as defined in +`java-ts-mode--font-lock-settings'." + :type 'list + :safe 'listp + :group 'java) + (defcustom java-ts-mode-indent-offset 4 "Number of spaces for each indentation step in `java-ts-mode'." :type 'integer @@ -268,6 +281,10 @@ java-ts-mode ;; Indent. (setq-local treesit-simple-indent-rules java-ts-mode--indent-rules) + ;; Electric + (setq-local electric-indent-chars + (append "{}():;," electric-indent-chars)) + ;; Navigation. (setq-local treesit-defun-type-regexp (rx (or "declaration"))) @@ -275,9 +292,7 @@ java-ts-mode ;; Font-lock. (setq-local treesit-font-lock-settings java-ts-mode--font-lock-settings) (setq-local treesit-font-lock-feature-list - '((basic comment keyword constant string operator) - (type definition expression literal annotation) - ())) + java-ts-mode-font-lock-feature-list) ;; Imenu. (setq-local imenu-create-index-function #'java-ts-mode--imenu) diff --git a/lisp/progmodes/json-ts-mode.el b/lisp/progmodes/json-ts-mode.el index 686640f98a..140ad5b523 100644 --- a/lisp/progmodes/json-ts-mode.el +++ b/lisp/progmodes/json-ts-mode.el @@ -31,6 +31,17 @@ (require 'treesit) (require 'rx) +(defcustom json-ts-mode-font-lock-feature-list + '((comment string number) (constant pair) ()) + "Language constructs to font-lock. + +See `treesit-font-lock-feature-list' for description of how to +use this variable. Supported features are as defined in +`json-ts-mode--font-lock-settings'." + :type 'list + :safe 'listp + :group 'json) + (defcustom json-ts-mode-indent-offset 2 "Number of spaces for each indentation step in `json-ts-mode'." :type 'integer @@ -67,20 +78,26 @@ json-ts--indent-rules (defvar json-ts-mode--font-lock-settings (treesit-font-lock-rules :language 'json - :feature 'minimal + :feature 'comment :override t - `((pair - key: (_) @font-lock-string-face) - - (string) @font-lock-string-face - - (number) @font-lock-constant-face - - [(null) (true) (false)] @font-lock-constant-face - - (escape_sequence) @font-lock-constant-face - - (comment) @font-lock-comment-face)) + '((comment) @font-lock-comment-face) + :language 'json + :feature 'string + :override t + '((escape_sequence) @font-lock-constant-face + (string) @font-lock-string-face) + :language 'json + :feature 'number + :override t + '((number) @font-lock-constant-face) + :language 'json + :feature 'constant + :override t + '([(null) (true) (false)] @font-lock-constant-face) + :language 'json + :feature 'pair + :override t + `((pair key: (_) @font-lock-variable-name-face))) "Font-lock settings for JSON.") (defun json-ts-mode--imenu-1 (node) @@ -127,6 +144,10 @@ json-ts-mode (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *") (setq-local comment-end "") + ;; Electric + (setq-local electric-indent-chars + (append "{}():;," electric-indent-chars)) + ;; Indent. (setq-local treesit-simple-indent-rules json-ts--indent-rules) @@ -137,7 +158,7 @@ json-ts-mode ;; Font-lock. (setq-local treesit-font-lock-settings json-ts-mode--font-lock-settings) (setq-local treesit-font-lock-feature-list - '((minimal) () ())) + json-ts-mode-font-lock-feature-list) ;; Imenu. (setq-local imenu-create-index-function #'json-ts-mode--imenu) diff --git a/lisp/progmodes/ts-mode.el b/lisp/progmodes/ts-mode.el index f4dfa2ae95..73f8c38238 100644 --- a/lisp/progmodes/ts-mode.el +++ b/lisp/progmodes/ts-mode.el @@ -28,6 +28,19 @@ (require 'rx) (require 'js) +(defcustom ts-mode-font-lock-feature-list + '((comment declaration) + (string keyword identifier expression constant) + (property pattern jsx)) + "Language constructs to font-lock. + +See `treesit-font-lock-feature-list' for description of how to +use this variable. Supported features are as defined in +`ts-mode--font-lock-settings'." + :type 'list + :safe 'listp + :group 'typescript) + (defcustom ts-mode-indent-offset 2 "Number of spaces for each indentation step in `ts-mode'." :type 'integer @@ -100,7 +113,6 @@ ts-mode--keywords (defvar ts-mode--font-lock-settings (treesit-font-lock-rules - :language 'tsx :override t :feature 'comment @@ -271,29 +283,39 @@ ts-mode ((treesit-ready-p nil 'tsx) ;; Tree-sitter. (treesit-parser-create 'tsx) + ;; Comments. (setq-local comment-start "// ") (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *") (setq-local comment-end "") + + ;; Electric + (setq-local electric-indent-chars + (append "{}():;," electric-indent-chars)) + ;; Indent. (setq-local treesit-simple-indent-rules ts-mode--indent-rules) + ;; Navigation. (setq-local treesit-defun-type-regexp (rx (or "class_declaration" "method_definition" "function_declaration" "lexical_declaration"))) + ;; Font-lock. (setq-local treesit-font-lock-settings ts-mode--font-lock-settings) (setq-local treesit-font-lock-feature-list - '((comment declaration) - (string keyword identifier expression constant) - (property pattern jsx))) + ts-mode-font-lock-feature-list) + ;; Imenu. (setq-local imenu-create-index-function #'js--treesit-imenu) + ;; Which-func (use imenu). (setq-local which-func-functions nil) + (treesit-major-mode-setup)) + ;; Elisp. (t (js-mode) -- 2.34.1 ^ permalink raw reply related [flat|nested] 11+ messages in thread
[parent not found: <handler.59251.B.16683721605982.ack@debbugs.gnu.org>]
* bug#59251: Acknowledgement (29.0.50; Fix-some-inconsistencies-in-ts-modes) [not found] ` <handler.59251.B.16683721605982.ack@debbugs.gnu.org> @ 2022-11-13 22:16 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors 2022-11-13 23:01 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors 0 siblings, 1 reply; 11+ messages in thread From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-11-13 22:16 UTC (permalink / raw) To: 59251 [-- Attachment #1: Type: text/plain, Size: 36 bytes --] Added a few more finishes. Theo [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-Fix-some-inconsistencies-in-ts-modes.patch --] [-- Type: text/x-diff, Size: 12261 bytes --] From bcbdc0a1261cd442aef8cd6bf0a80772eb0cda77 Mon Sep 17 00:00:00 2001 From: Theodor Thornhill <theo@thornhill.no> Date: Sun, 13 Nov 2022 21:37:01 +0100 Subject: [PATCH] Fix some inconsistencies in *-ts-modes * lisp/progmodes/c-ts-mode.el (c-ts-mode-comment-style): New defcustom. (c-ts-mode-font-lock-feature-list): New defcustom. (c-ts-mode--base-mode): Extract comment-* so that we can separate between C and C++. Use the new font-lock-feature-list defcustom. (c-ts-mode, c++-ts-mode): Set comment-* variables. * lisp/progmodes/css-ts-mode.el (css-ts-mode): Add electric-indent. * lisp/progmodes/java-ts-mode.el (java-ts-mode-font-lock-feature-list): New defcustom. (java-ts-mode): Add electric-indent and use the font-lock-feature-list defcustom. * lisp/progmodes/json-ts-mode.el (json-ts-mode-font-lock-feature-list): New defcustom. (json-ts-mode--font-lock-settings): Make much more granular font lock features. (json-ts-mode): Add electric-indent and use the font-lock-feature-list defcustom. * lisp/progmodes/ts-mode.el (ts-mode-font-lock-feature-list): New defcustom. (ts-mode--font-lock-settings): Whitespace cleanup. (ts-mode): Add electric-indent and use the font-lock-feature-list defcustom. --- lisp/progmodes/c-ts-mode.el | 47 ++++++++++++++++++++++++------- lisp/progmodes/css-ts-mode.el | 5 ++++ lisp/progmodes/java-ts-mode.el | 25 ++++++++++++++--- lisp/progmodes/json-ts-mode.el | 51 ++++++++++++++++++++++++---------- lisp/progmodes/ts-mode.el | 32 ++++++++++++++++++--- 5 files changed, 128 insertions(+), 32 deletions(-) diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 5617ea7d7c..eacc167909 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -31,8 +31,30 @@ (require 'treesit) (require 'rx) +(defcustom c-ts-mode-comment-style 'multi-line + "The comment style as decided by `comment-styles'" + :version "29.1" + :type 'symbol + :safe 'symbolp + :group 'c) + +(defcustom c-ts-mode-font-lock-feature-list + '((comment preprocessor operator constant string literal keyword) + (type definition expression statement) + ()) + "Language constructs to font-lock. + +See `treesit-font-lock-feature-list' for description of how to +use this variable. Supported features are as defined in +`c-ts-mode--font-lock-settings'." + :version "29.1" + :type 'list + :safe 'listp + :group 'c) + (defcustom c-ts-mode-indent-offset 2 "Number of spaces for each indentation step in `c-ts-mode'." + :version "29.1" :type 'integer :safe 'integerp :group 'c) @@ -44,6 +66,7 @@ c-ts-mode-indent-style one of the supplied styles doesn't suffice a function could be set instead. This function is expected return a list that follows the form of `treesit-simple-indent-rules'." + :version "29.1" :type '(choice (symbol :tag "Gnu" 'gnu) (symbol :tag "K&R" 'k&r) (symbol :tag "Linux" 'linux) @@ -396,14 +419,8 @@ c-ts-mode--imenu ;;;###autoload (define-derived-mode c-ts-mode--base-mode prog-mode "C" "Major mode for editing C, powered by tree-sitter." - :group 'c :syntax-table c-ts-mode--syntax-table - ;; Comments. - (setq-local comment-start "// ") - (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *") - (setq-local comment-end "") - ;; Navigation. (setq-local treesit-defun-type-regexp (rx (or "specifier" @@ -415,16 +432,14 @@ c-ts-mode--base-mode ;; Electric (setq-local electric-indent-chars - (append "{}():;," electric-indent-chars)) + (append "{}():;," electric-indent-chars)) ;; Imenu. (setq-local imenu-create-index-function #'c-ts-mode--imenu) (setq-local which-func-functions nil) (setq-local treesit-font-lock-feature-list - '((comment preprocessor operator constant string literal keyword) - (type definition expression statement) - (error)))) + c-ts-mode-font-lock-feature-list)) ;;;###autoload (define-derived-mode c-ts-mode c-ts-mode--base-mode "C" @@ -436,6 +451,12 @@ c-ts-mode (treesit-parser-create 'c) + ;; Comments. + (setq-local comment-start "/* ") + (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *") + (setq-local comment-end " */") + (setq-local comment-style c-ts-mode-comment-style) + (setq-local treesit-simple-indent-rules (c-ts-mode--set-indent-style 'c)) @@ -452,6 +473,12 @@ c++-ts-mode (unless (treesit-ready-p nil 'cpp) (error "Tree-sitter for C++ isn't available")) + ;; Comments. + (setq-local comment-start "// ") + (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *") + (setq-local comment-end "") + (setq-local comment-style c-ts-mode-comment-style) + (treesit-parser-create 'cpp) (setq-local treesit-simple-indent-rules diff --git a/lisp/progmodes/css-ts-mode.el b/lisp/progmodes/css-ts-mode.el index e22bf99c6c..d0f104eac3 100644 --- a/lisp/progmodes/css-ts-mode.el +++ b/lisp/progmodes/css-ts-mode.el @@ -34,6 +34,7 @@ (defcustom css-ts-mode-indent-offset 2 "Number of spaces for each indentation step in `ts-mode'." + :version "29.1" :type 'integer :safe 'integerp :group 'css) @@ -114,6 +115,10 @@ css-ts-mode ;; Indent. (setq-local treesit-simple-indent-rules css-ts-mode--indent-rules) + ;; Electric + (setq-local electric-indent-chars + (append "{}():;," electric-indent-chars)) + ;; Navigation. (setq-local treesit-defun-type-regexp "rule_set") ;; Font-lock. diff --git a/lisp/progmodes/java-ts-mode.el b/lisp/progmodes/java-ts-mode.el index 5ec7da9f5c..82343e6c52 100644 --- a/lisp/progmodes/java-ts-mode.el +++ b/lisp/progmodes/java-ts-mode.el @@ -31,8 +31,23 @@ (require 'treesit) (require 'rx) +(defcustom java-ts-mode-font-lock-feature-list + '((basic comment keyword constant string operator) + (type definition expression literal annotation) + ()) + "Language constructs to font-lock. + +See `treesit-font-lock-feature-list' for description of how to +use this variable. Supported features are as defined in +`java-ts-mode--font-lock-settings'." + :version "29.1" + :type 'list + :safe 'listp + :group 'java) + (defcustom java-ts-mode-indent-offset 4 "Number of spaces for each indentation step in `java-ts-mode'." + :version "29.1" :type 'integer :safe 'integerp :group 'java) @@ -252,7 +267,7 @@ java-ts-mode--imenu ;;;###autoload (define-derived-mode java-ts-mode prog-mode "Java" "Major mode for editing Java, powered by tree-sitter." - :group 'c + :group 'java :syntax-table java-ts-mode--syntax-table (unless (treesit-ready-p nil 'java) @@ -268,6 +283,10 @@ java-ts-mode ;; Indent. (setq-local treesit-simple-indent-rules java-ts-mode--indent-rules) + ;; Electric + (setq-local electric-indent-chars + (append "{}():;," electric-indent-chars)) + ;; Navigation. (setq-local treesit-defun-type-regexp (rx (or "declaration"))) @@ -275,9 +294,7 @@ java-ts-mode ;; Font-lock. (setq-local treesit-font-lock-settings java-ts-mode--font-lock-settings) (setq-local treesit-font-lock-feature-list - '((basic comment keyword constant string operator) - (type definition expression literal annotation) - ())) + java-ts-mode-font-lock-feature-list) ;; Imenu. (setq-local imenu-create-index-function #'java-ts-mode--imenu) diff --git a/lisp/progmodes/json-ts-mode.el b/lisp/progmodes/json-ts-mode.el index 686640f98a..f852cbcf58 100644 --- a/lisp/progmodes/json-ts-mode.el +++ b/lisp/progmodes/json-ts-mode.el @@ -31,8 +31,21 @@ (require 'treesit) (require 'rx) +(defcustom json-ts-mode-font-lock-feature-list + '((comment string number) (constant pair) ()) + "Language constructs to font-lock. + +See `treesit-font-lock-feature-list' for description of how to +use this variable. Supported features are as defined in +`json-ts-mode--font-lock-settings'." + :version "29.1" + :type 'list + :safe 'listp + :group 'json) + (defcustom json-ts-mode-indent-offset 2 "Number of spaces for each indentation step in `json-ts-mode'." + :version "29.1" :type 'integer :safe 'integerp :group 'json) @@ -67,20 +80,26 @@ json-ts--indent-rules (defvar json-ts-mode--font-lock-settings (treesit-font-lock-rules :language 'json - :feature 'minimal + :feature 'comment :override t - `((pair - key: (_) @font-lock-string-face) - - (string) @font-lock-string-face - - (number) @font-lock-constant-face - - [(null) (true) (false)] @font-lock-constant-face - - (escape_sequence) @font-lock-constant-face - - (comment) @font-lock-comment-face)) + '((comment) @font-lock-comment-face) + :language 'json + :feature 'string + :override t + '((escape_sequence) @font-lock-constant-face + (string) @font-lock-string-face) + :language 'json + :feature 'number + :override t + '((number) @font-lock-constant-face) + :language 'json + :feature 'constant + :override t + '([(null) (true) (false)] @font-lock-constant-face) + :language 'json + :feature 'pair + :override t + `((pair key: (_) @font-lock-variable-name-face))) "Font-lock settings for JSON.") (defun json-ts-mode--imenu-1 (node) @@ -127,6 +146,10 @@ json-ts-mode (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *") (setq-local comment-end "") + ;; Electric + (setq-local electric-indent-chars + (append "{}():;," electric-indent-chars)) + ;; Indent. (setq-local treesit-simple-indent-rules json-ts--indent-rules) @@ -137,7 +160,7 @@ json-ts-mode ;; Font-lock. (setq-local treesit-font-lock-settings json-ts-mode--font-lock-settings) (setq-local treesit-font-lock-feature-list - '((minimal) () ())) + json-ts-mode-font-lock-feature-list) ;; Imenu. (setq-local imenu-create-index-function #'json-ts-mode--imenu) diff --git a/lisp/progmodes/ts-mode.el b/lisp/progmodes/ts-mode.el index f4dfa2ae95..4f6a3f970b 100644 --- a/lisp/progmodes/ts-mode.el +++ b/lisp/progmodes/ts-mode.el @@ -28,8 +28,23 @@ (require 'rx) (require 'js) +(defcustom ts-mode-font-lock-feature-list + '((comment declaration) + (string keyword identifier expression constant) + (property pattern jsx)) + "Language constructs to font-lock. + +See `treesit-font-lock-feature-list' for description of how to +use this variable. Supported features are as defined in +`ts-mode--font-lock-settings'." + :version "29.1" + :type 'list + :safe 'listp + :group 'typescript) + (defcustom ts-mode-indent-offset 2 "Number of spaces for each indentation step in `ts-mode'." + :version "29.1" :type 'integer :safe 'integerp :group 'typescript) @@ -100,7 +115,6 @@ ts-mode--keywords (defvar ts-mode--font-lock-settings (treesit-font-lock-rules - :language 'tsx :override t :feature 'comment @@ -271,29 +285,39 @@ ts-mode ((treesit-ready-p nil 'tsx) ;; Tree-sitter. (treesit-parser-create 'tsx) + ;; Comments. (setq-local comment-start "// ") (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *") (setq-local comment-end "") + + ;; Electric + (setq-local electric-indent-chars + (append "{}():;," electric-indent-chars)) + ;; Indent. (setq-local treesit-simple-indent-rules ts-mode--indent-rules) + ;; Navigation. (setq-local treesit-defun-type-regexp (rx (or "class_declaration" "method_definition" "function_declaration" "lexical_declaration"))) + ;; Font-lock. (setq-local treesit-font-lock-settings ts-mode--font-lock-settings) (setq-local treesit-font-lock-feature-list - '((comment declaration) - (string keyword identifier expression constant) - (property pattern jsx))) + ts-mode-font-lock-feature-list) + ;; Imenu. (setq-local imenu-create-index-function #'js--treesit-imenu) + ;; Which-func (use imenu). (setq-local which-func-functions nil) + (treesit-major-mode-setup)) + ;; Elisp. (t (js-mode) -- 2.34.1 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* bug#59251: Acknowledgement (29.0.50; Fix-some-inconsistencies-in-ts-modes) 2022-11-13 22:16 ` bug#59251: Acknowledgement (29.0.50; Fix-some-inconsistencies-in-ts-modes) Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-11-13 23:01 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors 2022-11-14 0:51 ` Yuan Fu 0 siblings, 1 reply; 11+ messages in thread From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-11-13 23:01 UTC (permalink / raw) To: 59251 [-- Attachment #1: Type: text/plain, Size: 133 bytes --] Theodor Thornhill <theo@thornhill.no> writes: > Added a few more finishes. Aaand another. Last one for now. I promise... Theo [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-Fix-some-inconsistencies-in-ts-modes.patch --] [-- Type: text/x-diff, Size: 14044 bytes --] From d36a86b28609f1d060cf282bcdf75bdbef46b909 Mon Sep 17 00:00:00 2001 From: Theodor Thornhill <theo@thornhill.no> Date: Sun, 13 Nov 2022 21:37:01 +0100 Subject: [PATCH] Fix some inconsistencies in *-ts-modes * lisp/progmodes/c-ts-mode.el (c-ts-mode-comment-style): New defcustom. (c-ts-mode-font-lock-feature-list): New defcustom. (c-ts-mode--base-mode): Extract comment-* so that we can separate between C and C++. Use the new font-lock-feature-list defcustom. (c-ts-mode, c++-ts-mode): Set comment-* variables. * lisp/progmodes/css-ts-mode.el (css-ts-mode): Add electric-indent. * lisp/progmodes/java-ts-mode.el (java-ts-mode-font-lock-feature-list): New defcustom. (java-ts-mode--imenu): Add categories. Only display categories that exist in the file. (java-ts-mode): Add electric-indent and use the font-lock-feature-list defcustom. * lisp/progmodes/json-ts-mode.el (json-ts-mode-font-lock-feature-list): New defcustom. (json-ts-mode--font-lock-settings): Make much more granular font lock features. (json-ts-mode): Add electric-indent and use the font-lock-feature-list defcustom. * lisp/progmodes/ts-mode.el (ts-mode-font-lock-feature-list): New defcustom. (ts-mode--font-lock-settings): Whitespace cleanup. (ts-mode): Add electric-indent and use the font-lock-feature-list defcustom. --- lisp/progmodes/c-ts-mode.el | 47 +++++++++++++++++++------ lisp/progmodes/css-ts-mode.el | 5 +++ lisp/progmodes/java-ts-mode.el | 63 ++++++++++++++++++++++++++-------- lisp/progmodes/json-ts-mode.el | 51 +++++++++++++++++++-------- lisp/progmodes/ts-mode.el | 32 ++++++++++++++--- 5 files changed, 156 insertions(+), 42 deletions(-) diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 5617ea7d7c..eacc167909 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -31,8 +31,30 @@ (require 'treesit) (require 'rx) +(defcustom c-ts-mode-comment-style 'multi-line + "The comment style as decided by `comment-styles'" + :version "29.1" + :type 'symbol + :safe 'symbolp + :group 'c) + +(defcustom c-ts-mode-font-lock-feature-list + '((comment preprocessor operator constant string literal keyword) + (type definition expression statement) + ()) + "Language constructs to font-lock. + +See `treesit-font-lock-feature-list' for description of how to +use this variable. Supported features are as defined in +`c-ts-mode--font-lock-settings'." + :version "29.1" + :type 'list + :safe 'listp + :group 'c) + (defcustom c-ts-mode-indent-offset 2 "Number of spaces for each indentation step in `c-ts-mode'." + :version "29.1" :type 'integer :safe 'integerp :group 'c) @@ -44,6 +66,7 @@ c-ts-mode-indent-style one of the supplied styles doesn't suffice a function could be set instead. This function is expected return a list that follows the form of `treesit-simple-indent-rules'." + :version "29.1" :type '(choice (symbol :tag "Gnu" 'gnu) (symbol :tag "K&R" 'k&r) (symbol :tag "Linux" 'linux) @@ -396,14 +419,8 @@ c-ts-mode--imenu ;;;###autoload (define-derived-mode c-ts-mode--base-mode prog-mode "C" "Major mode for editing C, powered by tree-sitter." - :group 'c :syntax-table c-ts-mode--syntax-table - ;; Comments. - (setq-local comment-start "// ") - (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *") - (setq-local comment-end "") - ;; Navigation. (setq-local treesit-defun-type-regexp (rx (or "specifier" @@ -415,16 +432,14 @@ c-ts-mode--base-mode ;; Electric (setq-local electric-indent-chars - (append "{}():;," electric-indent-chars)) + (append "{}():;," electric-indent-chars)) ;; Imenu. (setq-local imenu-create-index-function #'c-ts-mode--imenu) (setq-local which-func-functions nil) (setq-local treesit-font-lock-feature-list - '((comment preprocessor operator constant string literal keyword) - (type definition expression statement) - (error)))) + c-ts-mode-font-lock-feature-list)) ;;;###autoload (define-derived-mode c-ts-mode c-ts-mode--base-mode "C" @@ -436,6 +451,12 @@ c-ts-mode (treesit-parser-create 'c) + ;; Comments. + (setq-local comment-start "/* ") + (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *") + (setq-local comment-end " */") + (setq-local comment-style c-ts-mode-comment-style) + (setq-local treesit-simple-indent-rules (c-ts-mode--set-indent-style 'c)) @@ -452,6 +473,12 @@ c++-ts-mode (unless (treesit-ready-p nil 'cpp) (error "Tree-sitter for C++ isn't available")) + ;; Comments. + (setq-local comment-start "// ") + (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *") + (setq-local comment-end "") + (setq-local comment-style c-ts-mode-comment-style) + (treesit-parser-create 'cpp) (setq-local treesit-simple-indent-rules diff --git a/lisp/progmodes/css-ts-mode.el b/lisp/progmodes/css-ts-mode.el index e22bf99c6c..d0f104eac3 100644 --- a/lisp/progmodes/css-ts-mode.el +++ b/lisp/progmodes/css-ts-mode.el @@ -34,6 +34,7 @@ (defcustom css-ts-mode-indent-offset 2 "Number of spaces for each indentation step in `ts-mode'." + :version "29.1" :type 'integer :safe 'integerp :group 'css) @@ -114,6 +115,10 @@ css-ts-mode ;; Indent. (setq-local treesit-simple-indent-rules css-ts-mode--indent-rules) + ;; Electric + (setq-local electric-indent-chars + (append "{}():;," electric-indent-chars)) + ;; Navigation. (setq-local treesit-defun-type-regexp "rule_set") ;; Font-lock. diff --git a/lisp/progmodes/java-ts-mode.el b/lisp/progmodes/java-ts-mode.el index 5ec7da9f5c..9977802f84 100644 --- a/lisp/progmodes/java-ts-mode.el +++ b/lisp/progmodes/java-ts-mode.el @@ -29,10 +29,24 @@ ;;; Code: (require 'treesit) -(require 'rx) + +(defcustom java-ts-mode-font-lock-feature-list + '((basic comment keyword constant string operator) + (type definition expression literal annotation) + ()) + "Language constructs to font-lock. + +See `treesit-font-lock-feature-list' for description of how to +use this variable. Supported features are as defined in +`java-ts-mode--font-lock-settings'." + :version "29.1" + :type 'list + :safe 'listp + :group 'java) (defcustom java-ts-mode-indent-offset 4 "Number of spaces for each indentation step in `java-ts-mode'." + :version "29.1" :type 'integer :safe 'integerp :group 'java) @@ -241,18 +255,38 @@ java-ts-mode--imenu-1 (defun java-ts-mode--imenu () "Return Imenu alist for the current buffer." (let* ((node (treesit-buffer-root-node)) - (tree (treesit-induce-sparse-tree - node (rx (or "class_declaration" - "interface_declaration" - "enum_declaration" - "record_declaration" - "method_declaration"))))) - (java-ts-mode--imenu-1 tree))) + (class-tree + `("Class" . ,(java-ts-mode--imenu-1 + (treesit-induce-sparse-tree + node "^class_declaration$")))) + (interface-tree + `("Interface" . ,(java-ts-mode--imenu-1 + (treesit-induce-sparse-tree + node "^interface_declaration$")))) + (enum-tree + `("Enum" . ,(java-ts-mode--imenu-1 + (treesit-induce-sparse-tree + node "^enum_declaration$")))) + (record-tree + `("Record" . ,(java-ts-mode--imenu-1 + (treesit-induce-sparse-tree + node "^record_declaration$")))) + (method-tree + `("Method" . ,(java-ts-mode--imenu-1 + (treesit-induce-sparse-tree + node "^method_declaration$"))))) + (cl-remove-if + #'null + `(,(when (cdr class-tree) class-tree) + ,(when (cdr interface-tree) interface-tree) + ,(when (cdr enum-tree) enum-tree) + ,(when (cdr record-tree) record-tree) + ,(when (cdr method-tree) method-tree))))) ;;;###autoload (define-derived-mode java-ts-mode prog-mode "Java" "Major mode for editing Java, powered by tree-sitter." - :group 'c + :group 'java :syntax-table java-ts-mode--syntax-table (unless (treesit-ready-p nil 'java) @@ -268,16 +302,17 @@ java-ts-mode ;; Indent. (setq-local treesit-simple-indent-rules java-ts-mode--indent-rules) + ;; Electric + (setq-local electric-indent-chars + (append "{}():;," electric-indent-chars)) + ;; Navigation. - (setq-local treesit-defun-type-regexp - (rx (or "declaration"))) + (setq-local treesit-defun-type-regexp "declaration") ;; Font-lock. (setq-local treesit-font-lock-settings java-ts-mode--font-lock-settings) (setq-local treesit-font-lock-feature-list - '((basic comment keyword constant string operator) - (type definition expression literal annotation) - ())) + java-ts-mode-font-lock-feature-list) ;; Imenu. (setq-local imenu-create-index-function #'java-ts-mode--imenu) diff --git a/lisp/progmodes/json-ts-mode.el b/lisp/progmodes/json-ts-mode.el index 686640f98a..f852cbcf58 100644 --- a/lisp/progmodes/json-ts-mode.el +++ b/lisp/progmodes/json-ts-mode.el @@ -31,8 +31,21 @@ (require 'treesit) (require 'rx) +(defcustom json-ts-mode-font-lock-feature-list + '((comment string number) (constant pair) ()) + "Language constructs to font-lock. + +See `treesit-font-lock-feature-list' for description of how to +use this variable. Supported features are as defined in +`json-ts-mode--font-lock-settings'." + :version "29.1" + :type 'list + :safe 'listp + :group 'json) + (defcustom json-ts-mode-indent-offset 2 "Number of spaces for each indentation step in `json-ts-mode'." + :version "29.1" :type 'integer :safe 'integerp :group 'json) @@ -67,20 +80,26 @@ json-ts--indent-rules (defvar json-ts-mode--font-lock-settings (treesit-font-lock-rules :language 'json - :feature 'minimal + :feature 'comment :override t - `((pair - key: (_) @font-lock-string-face) - - (string) @font-lock-string-face - - (number) @font-lock-constant-face - - [(null) (true) (false)] @font-lock-constant-face - - (escape_sequence) @font-lock-constant-face - - (comment) @font-lock-comment-face)) + '((comment) @font-lock-comment-face) + :language 'json + :feature 'string + :override t + '((escape_sequence) @font-lock-constant-face + (string) @font-lock-string-face) + :language 'json + :feature 'number + :override t + '((number) @font-lock-constant-face) + :language 'json + :feature 'constant + :override t + '([(null) (true) (false)] @font-lock-constant-face) + :language 'json + :feature 'pair + :override t + `((pair key: (_) @font-lock-variable-name-face))) "Font-lock settings for JSON.") (defun json-ts-mode--imenu-1 (node) @@ -127,6 +146,10 @@ json-ts-mode (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *") (setq-local comment-end "") + ;; Electric + (setq-local electric-indent-chars + (append "{}():;," electric-indent-chars)) + ;; Indent. (setq-local treesit-simple-indent-rules json-ts--indent-rules) @@ -137,7 +160,7 @@ json-ts-mode ;; Font-lock. (setq-local treesit-font-lock-settings json-ts-mode--font-lock-settings) (setq-local treesit-font-lock-feature-list - '((minimal) () ())) + json-ts-mode-font-lock-feature-list) ;; Imenu. (setq-local imenu-create-index-function #'json-ts-mode--imenu) diff --git a/lisp/progmodes/ts-mode.el b/lisp/progmodes/ts-mode.el index f4dfa2ae95..4f6a3f970b 100644 --- a/lisp/progmodes/ts-mode.el +++ b/lisp/progmodes/ts-mode.el @@ -28,8 +28,23 @@ (require 'rx) (require 'js) +(defcustom ts-mode-font-lock-feature-list + '((comment declaration) + (string keyword identifier expression constant) + (property pattern jsx)) + "Language constructs to font-lock. + +See `treesit-font-lock-feature-list' for description of how to +use this variable. Supported features are as defined in +`ts-mode--font-lock-settings'." + :version "29.1" + :type 'list + :safe 'listp + :group 'typescript) + (defcustom ts-mode-indent-offset 2 "Number of spaces for each indentation step in `ts-mode'." + :version "29.1" :type 'integer :safe 'integerp :group 'typescript) @@ -100,7 +115,6 @@ ts-mode--keywords (defvar ts-mode--font-lock-settings (treesit-font-lock-rules - :language 'tsx :override t :feature 'comment @@ -271,29 +285,39 @@ ts-mode ((treesit-ready-p nil 'tsx) ;; Tree-sitter. (treesit-parser-create 'tsx) + ;; Comments. (setq-local comment-start "// ") (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *") (setq-local comment-end "") + + ;; Electric + (setq-local electric-indent-chars + (append "{}():;," electric-indent-chars)) + ;; Indent. (setq-local treesit-simple-indent-rules ts-mode--indent-rules) + ;; Navigation. (setq-local treesit-defun-type-regexp (rx (or "class_declaration" "method_definition" "function_declaration" "lexical_declaration"))) + ;; Font-lock. (setq-local treesit-font-lock-settings ts-mode--font-lock-settings) (setq-local treesit-font-lock-feature-list - '((comment declaration) - (string keyword identifier expression constant) - (property pattern jsx))) + ts-mode-font-lock-feature-list) + ;; Imenu. (setq-local imenu-create-index-function #'js--treesit-imenu) + ;; Which-func (use imenu). (setq-local which-func-functions nil) + (treesit-major-mode-setup)) + ;; Elisp. (t (js-mode) -- 2.34.1 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* bug#59251: Acknowledgement (29.0.50; Fix-some-inconsistencies-in-ts-modes) 2022-11-13 23:01 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-11-14 0:51 ` Yuan Fu 2022-11-14 7:06 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors 2022-11-14 19:02 ` Eli Zaretskii 0 siblings, 2 replies; 11+ messages in thread From: Yuan Fu @ 2022-11-14 0:51 UTC (permalink / raw) To: Theodor Thornhill; +Cc: 59251 > On Nov 13, 2022, at 3:01 PM, Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors <bug-gnu-emacs@gnu.org> wrote: > > Theodor Thornhill <theo@thornhill.no> writes: > >> Added a few more finishes. > > Aaand another. Last one for now. I promise… Cool! Some comments: +(defcustom c-ts-mode-font-lock-feature-list + '((comment preprocessor operator constant string literal keyword) + (type definition expression statement) + ()) + "Language constructs to font-lock. + +See `treesit-font-lock-feature-list' for description of how to +use this variable. Supported features are as defined in +`c-ts-mode--font-lock-settings'." + :version "29.1" + :type 'list + :safe 'listp + :group 'c) + I think Stefan M’s opinion is to make feature-list private, and let users add/remove features. Right now they can add/remove features with treesit-recompute-feature-list. I guess we can keep them as defvar’s for now, so people as the option to redefine this list should they want to. (One argument against having them as custom options is that, if a user sets it as a custom option, they will miss out on future changes to this variable.) + (setq-local comment-style c-ts-mode-comment-style) Why don’t we let users set comment style themselves? Does cc-mode have a similar variable? Yuan ^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#59251: Acknowledgement (29.0.50; Fix-some-inconsistencies-in-ts-modes) 2022-11-14 0:51 ` Yuan Fu @ 2022-11-14 7:06 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors 2022-11-14 9:25 ` Yuan Fu 2022-11-15 12:22 ` Eli Zaretskii 2022-11-14 19:02 ` Eli Zaretskii 1 sibling, 2 replies; 11+ messages in thread From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-11-14 7:06 UTC (permalink / raw) To: Yuan Fu; +Cc: 59251 [-- Attachment #1: Type: text/plain, Size: 1526 bytes --] Yuan Fu <casouri@gmail.com> writes: >> On Nov 13, 2022, at 3:01 PM, Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors <bug-gnu-emacs@gnu.org> wrote: >> >> Theodor Thornhill <theo@thornhill.no> writes: >> >>> Added a few more finishes. >> >> Aaand another. Last one for now. I promise… > > Cool! Some comments: > > +(defcustom c-ts-mode-font-lock-feature-list > + '((comment preprocessor operator constant string literal keyword) > + (type definition expression statement) > + ()) > + "Language constructs to font-lock. > + > +See `treesit-font-lock-feature-list' for description of how to > +use this variable. Supported features are as defined in > +`c-ts-mode--font-lock-settings'." > + :version "29.1" > + :type 'list > + :safe 'listp > + :group 'c) > + > > I think Stefan M’s opinion is to make feature-list private, and let > users add/remove features. Right now they can add/remove features with > treesit-recompute-feature-list. I guess we can keep them as defvar’s > for now, so people as the option to redefine this list should they > want to. (One argument against having them as custom options is that, > if a user sets it as a custom option, they will miss out on future > changes to this variable.) > > > + (setq-local comment-style c-ts-mode-comment-style) > > Why don’t we let users set comment style themselves? Does cc-mode have a similar variable? > You have a point. Simplified the patch. Theo [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-Fix-some-inconsistencies-in-ts-modes.patch --] [-- Type: text/x-diff, Size: 10619 bytes --] From 60d1dcf08d2d5fc365958263dafa0e731bfbc110 Mon Sep 17 00:00:00 2001 From: Theodor Thornhill <theo@thornhill.no> Date: Mon, 14 Nov 2022 08:03:11 +0100 Subject: [PATCH] Fix some inconsistencies in *-ts-modes (c-ts-mode--base-mode): Extract comment-* so that we can separate between C and C++. (c-ts-mode, c++-ts-mode): Set comment-* variables. * lisp/progmodes/css-ts-mode.el (css-ts-mode): Add electric-indent. * lisp/progmodes/java-ts-mode.el (java-ts-mode--imenu): Add categories. Only display categories that exist in the file. (java-ts-mode): Add electric-indent. * lisp/progmodes/json-ts-mode.el (json-ts-mode): Add electric-indent. * lisp/progmodes/ts-mode.el (ts-mode--font-lock-settings): Whitespace cleanup. (ts-mode): Add electric-indent. --- lisp/progmodes/c-ts-mode.el | 20 +++++++++------ lisp/progmodes/css-ts-mode.el | 5 ++++ lisp/progmodes/java-ts-mode.el | 45 +++++++++++++++++++++++++--------- lisp/progmodes/json-ts-mode.el | 39 ++++++++++++++++++----------- lisp/progmodes/ts-mode.el | 13 +++++++++- 5 files changed, 89 insertions(+), 33 deletions(-) diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 5617ea7d7c..8d18c23da9 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -33,6 +33,7 @@ (defcustom c-ts-mode-indent-offset 2 "Number of spaces for each indentation step in `c-ts-mode'." + :version "29.1" :type 'integer :safe 'integerp :group 'c) @@ -44,6 +45,7 @@ c-ts-mode-indent-style one of the supplied styles doesn't suffice a function could be set instead. This function is expected return a list that follows the form of `treesit-simple-indent-rules'." + :version "29.1" :type '(choice (symbol :tag "Gnu" 'gnu) (symbol :tag "K&R" 'k&r) (symbol :tag "Linux" 'linux) @@ -396,14 +398,8 @@ c-ts-mode--imenu ;;;###autoload (define-derived-mode c-ts-mode--base-mode prog-mode "C" "Major mode for editing C, powered by tree-sitter." - :group 'c :syntax-table c-ts-mode--syntax-table - ;; Comments. - (setq-local comment-start "// ") - (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *") - (setq-local comment-end "") - ;; Navigation. (setq-local treesit-defun-type-regexp (rx (or "specifier" @@ -415,7 +411,7 @@ c-ts-mode--base-mode ;; Electric (setq-local electric-indent-chars - (append "{}():;," electric-indent-chars)) + (append "{}():;," electric-indent-chars)) ;; Imenu. (setq-local imenu-create-index-function #'c-ts-mode--imenu) @@ -436,6 +432,11 @@ c-ts-mode (treesit-parser-create 'c) + ;; Comments. + (setq-local comment-start "/* ") + (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *") + (setq-local comment-end " */") + (setq-local treesit-simple-indent-rules (c-ts-mode--set-indent-style 'c)) @@ -452,6 +453,11 @@ c++-ts-mode (unless (treesit-ready-p nil 'cpp) (error "Tree-sitter for C++ isn't available")) + ;; Comments. + (setq-local comment-start "// ") + (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *") + (setq-local comment-end "") + (treesit-parser-create 'cpp) (setq-local treesit-simple-indent-rules diff --git a/lisp/progmodes/css-ts-mode.el b/lisp/progmodes/css-ts-mode.el index e22bf99c6c..d0f104eac3 100644 --- a/lisp/progmodes/css-ts-mode.el +++ b/lisp/progmodes/css-ts-mode.el @@ -34,6 +34,7 @@ (defcustom css-ts-mode-indent-offset 2 "Number of spaces for each indentation step in `ts-mode'." + :version "29.1" :type 'integer :safe 'integerp :group 'css) @@ -114,6 +115,10 @@ css-ts-mode ;; Indent. (setq-local treesit-simple-indent-rules css-ts-mode--indent-rules) + ;; Electric + (setq-local electric-indent-chars + (append "{}():;," electric-indent-chars)) + ;; Navigation. (setq-local treesit-defun-type-regexp "rule_set") ;; Font-lock. diff --git a/lisp/progmodes/java-ts-mode.el b/lisp/progmodes/java-ts-mode.el index 5ec7da9f5c..ee75753027 100644 --- a/lisp/progmodes/java-ts-mode.el +++ b/lisp/progmodes/java-ts-mode.el @@ -29,10 +29,10 @@ ;;; Code: (require 'treesit) -(require 'rx) (defcustom java-ts-mode-indent-offset 4 "Number of spaces for each indentation step in `java-ts-mode'." + :version "29.1" :type 'integer :safe 'integerp :group 'java) @@ -241,18 +241,38 @@ java-ts-mode--imenu-1 (defun java-ts-mode--imenu () "Return Imenu alist for the current buffer." (let* ((node (treesit-buffer-root-node)) - (tree (treesit-induce-sparse-tree - node (rx (or "class_declaration" - "interface_declaration" - "enum_declaration" - "record_declaration" - "method_declaration"))))) - (java-ts-mode--imenu-1 tree))) + (class-tree + `("Class" . ,(java-ts-mode--imenu-1 + (treesit-induce-sparse-tree + node "^class_declaration$")))) + (interface-tree + `("Interface" . ,(java-ts-mode--imenu-1 + (treesit-induce-sparse-tree + node "^interface_declaration$")))) + (enum-tree + `("Enum" . ,(java-ts-mode--imenu-1 + (treesit-induce-sparse-tree + node "^enum_declaration$")))) + (record-tree + `("Record" . ,(java-ts-mode--imenu-1 + (treesit-induce-sparse-tree + node "^record_declaration$")))) + (method-tree + `("Method" . ,(java-ts-mode--imenu-1 + (treesit-induce-sparse-tree + node "^method_declaration$"))))) + (cl-remove-if + #'null + `(,(when (cdr class-tree) class-tree) + ,(when (cdr interface-tree) interface-tree) + ,(when (cdr enum-tree) enum-tree) + ,(when (cdr record-tree) record-tree) + ,(when (cdr method-tree) method-tree))))) ;;;###autoload (define-derived-mode java-ts-mode prog-mode "Java" "Major mode for editing Java, powered by tree-sitter." - :group 'c + :group 'java :syntax-table java-ts-mode--syntax-table (unless (treesit-ready-p nil 'java) @@ -268,9 +288,12 @@ java-ts-mode ;; Indent. (setq-local treesit-simple-indent-rules java-ts-mode--indent-rules) + ;; Electric + (setq-local electric-indent-chars + (append "{}():;," electric-indent-chars)) + ;; Navigation. - (setq-local treesit-defun-type-regexp - (rx (or "declaration"))) + (setq-local treesit-defun-type-regexp "declaration") ;; Font-lock. (setq-local treesit-font-lock-settings java-ts-mode--font-lock-settings) diff --git a/lisp/progmodes/json-ts-mode.el b/lisp/progmodes/json-ts-mode.el index 686640f98a..c1d3d283b8 100644 --- a/lisp/progmodes/json-ts-mode.el +++ b/lisp/progmodes/json-ts-mode.el @@ -33,6 +33,7 @@ (defcustom json-ts-mode-indent-offset 2 "Number of spaces for each indentation step in `json-ts-mode'." + :version "29.1" :type 'integer :safe 'integerp :group 'json) @@ -67,20 +68,26 @@ json-ts--indent-rules (defvar json-ts-mode--font-lock-settings (treesit-font-lock-rules :language 'json - :feature 'minimal + :feature 'comment :override t - `((pair - key: (_) @font-lock-string-face) - - (string) @font-lock-string-face - - (number) @font-lock-constant-face - - [(null) (true) (false)] @font-lock-constant-face - - (escape_sequence) @font-lock-constant-face - - (comment) @font-lock-comment-face)) + '((comment) @font-lock-comment-face) + :language 'json + :feature 'string + :override t + '((escape_sequence) @font-lock-constant-face + (string) @font-lock-string-face) + :language 'json + :feature 'number + :override t + '((number) @font-lock-constant-face) + :language 'json + :feature 'constant + :override t + '([(null) (true) (false)] @font-lock-constant-face) + :language 'json + :feature 'pair + :override t + `((pair key: (_) @font-lock-variable-name-face))) "Font-lock settings for JSON.") (defun json-ts-mode--imenu-1 (node) @@ -127,6 +134,10 @@ json-ts-mode (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *") (setq-local comment-end "") + ;; Electric + (setq-local electric-indent-chars + (append "{}():;," electric-indent-chars)) + ;; Indent. (setq-local treesit-simple-indent-rules json-ts--indent-rules) @@ -137,7 +148,7 @@ json-ts-mode ;; Font-lock. (setq-local treesit-font-lock-settings json-ts-mode--font-lock-settings) (setq-local treesit-font-lock-feature-list - '((minimal) () ())) + '((comment string number) (constant pair) ())) ;; Imenu. (setq-local imenu-create-index-function #'json-ts-mode--imenu) diff --git a/lisp/progmodes/ts-mode.el b/lisp/progmodes/ts-mode.el index f4dfa2ae95..c5a6f5fc60 100644 --- a/lisp/progmodes/ts-mode.el +++ b/lisp/progmodes/ts-mode.el @@ -30,6 +30,7 @@ (defcustom ts-mode-indent-offset 2 "Number of spaces for each indentation step in `ts-mode'." + :version "29.1" :type 'integer :safe 'integerp :group 'typescript) @@ -100,7 +101,6 @@ ts-mode--keywords (defvar ts-mode--font-lock-settings (treesit-font-lock-rules - :language 'tsx :override t :feature 'comment @@ -271,18 +271,26 @@ ts-mode ((treesit-ready-p nil 'tsx) ;; Tree-sitter. (treesit-parser-create 'tsx) + ;; Comments. (setq-local comment-start "// ") (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *") (setq-local comment-end "") + + ;; Electric + (setq-local electric-indent-chars + (append "{}():;," electric-indent-chars)) + ;; Indent. (setq-local treesit-simple-indent-rules ts-mode--indent-rules) + ;; Navigation. (setq-local treesit-defun-type-regexp (rx (or "class_declaration" "method_definition" "function_declaration" "lexical_declaration"))) + ;; Font-lock. (setq-local treesit-font-lock-settings ts-mode--font-lock-settings) (setq-local treesit-font-lock-feature-list @@ -291,9 +299,12 @@ ts-mode (property pattern jsx))) ;; Imenu. (setq-local imenu-create-index-function #'js--treesit-imenu) + ;; Which-func (use imenu). (setq-local which-func-functions nil) + (treesit-major-mode-setup)) + ;; Elisp. (t (js-mode) -- 2.34.1 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* bug#59251: Acknowledgement (29.0.50; Fix-some-inconsistencies-in-ts-modes) 2022-11-14 7:06 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-11-14 9:25 ` Yuan Fu 2022-11-15 12:22 ` Eli Zaretskii 1 sibling, 0 replies; 11+ messages in thread From: Yuan Fu @ 2022-11-14 9:25 UTC (permalink / raw) To: Theodor Thornhill; +Cc: 59251, done-59251 > On Nov 13, 2022, at 11:06 PM, Theodor Thornhill <theo@thornhill.no> wrote: > > Yuan Fu <casouri@gmail.com> writes: > >>> On Nov 13, 2022, at 3:01 PM, Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors <bug-gnu-emacs@gnu.org> wrote: >>> >>> Theodor Thornhill <theo@thornhill.no> writes: >>> >>>> Added a few more finishes. >>> >>> Aaand another. Last one for now. I promise… >> >> Cool! Some comments: >> >> +(defcustom c-ts-mode-font-lock-feature-list >> + '((comment preprocessor operator constant string literal keyword) >> + (type definition expression statement) >> + ()) >> + "Language constructs to font-lock. >> + >> +See `treesit-font-lock-feature-list' for description of how to >> +use this variable. Supported features are as defined in >> +`c-ts-mode--font-lock-settings'." >> + :version "29.1" >> + :type 'list >> + :safe 'listp >> + :group 'c) >> + >> >> I think Stefan M’s opinion is to make feature-list private, and let >> users add/remove features. Right now they can add/remove features with >> treesit-recompute-feature-list. I guess we can keep them as defvar’s >> for now, so people as the option to redefine this list should they >> want to. (One argument against having them as custom options is that, >> if a user sets it as a custom option, they will miss out on future >> changes to this variable.) >> >> >> + (setq-local comment-style c-ts-mode-comment-style) >> >> Why don’t we let users set comment style themselves? Does cc-mode have a similar variable? >> > > You have a point. Simplified the patch. > > Theo > > <0001-Fix-some-inconsistencies-in-ts-modes.patch> Thanks, merged and pushed. Yuan ^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#59251: Acknowledgement (29.0.50; Fix-some-inconsistencies-in-ts-modes) 2022-11-14 7:06 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors 2022-11-14 9:25 ` Yuan Fu @ 2022-11-15 12:22 ` Eli Zaretskii 2022-11-15 14:22 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors 1 sibling, 1 reply; 11+ messages in thread From: Eli Zaretskii @ 2022-11-15 12:22 UTC (permalink / raw) To: Theodor Thornhill; +Cc: 59251, casouri > Cc: 59251@debbugs.gnu.org > Date: Mon, 14 Nov 2022 08:06:31 +0100 > From: Theodor Thornhill via "Bug reports for GNU Emacs, > the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org> > > > + (setq-local comment-style c-ts-mode-comment-style) > > > > Why don’t we let users set comment style themselves? Does cc-mode have a similar variable? > > > > You have a point. Simplified the patch. This still makes it a fixed value that cannot be easily customized? Or did I miss something? ^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#59251: Acknowledgement (29.0.50; Fix-some-inconsistencies-in-ts-modes) 2022-11-15 12:22 ` Eli Zaretskii @ 2022-11-15 14:22 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors 0 siblings, 0 replies; 11+ messages in thread From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-11-15 14:22 UTC (permalink / raw) To: Eli Zaretskii; +Cc: 59251, casouri On 15 November 2022 13:22:38 CET, Eli Zaretskii <eliz@gnu.org> wrote: >> Cc: 59251@debbugs.gnu.org >> Date: Mon, 14 Nov 2022 08:06:31 +0100 >> From: Theodor Thornhill via "Bug reports for GNU Emacs, >> the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org> >> >> > + (setq-local comment-style c-ts-mode-comment-style) >> > >> > Why don’t we let users set comment style themselves? Does cc-mode have a similar variable? >> > >> >> You have a point. Simplified the patch. > >This still makes it a fixed value that cannot be easily customized? >Or did I miss something? You could set it through the defcustom that was included ^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#59251: Acknowledgement (29.0.50; Fix-some-inconsistencies-in-ts-modes) 2022-11-14 0:51 ` Yuan Fu 2022-11-14 7:06 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-11-14 19:02 ` Eli Zaretskii 1 sibling, 0 replies; 11+ messages in thread From: Eli Zaretskii @ 2022-11-14 19:02 UTC (permalink / raw) To: Yuan Fu; +Cc: 59251, theo > Cc: 59251@debbugs.gnu.org > From: Yuan Fu <casouri@gmail.com> > Date: Sun, 13 Nov 2022 16:51:52 -0800 > > + (setq-local comment-style c-ts-mode-comment-style) > > Why don’t we let users set comment style themselves? Does cc-mode have a similar variable? It's a minor mode there, see "C-c C-k" (c-toggle-comment-style). ^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#59251: 29.0.50; Fix-some-inconsistencies-in-ts-modes 2022-11-13 20:42 bug#59251: 29.0.50; Fix-some-inconsistencies-in-ts-modes Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors [not found] ` <handler.59251.B.16683721605982.ack@debbugs.gnu.org> @ 2022-11-14 18:59 ` Eli Zaretskii 2022-11-14 19:12 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors 1 sibling, 1 reply; 11+ messages in thread From: Eli Zaretskii @ 2022-11-14 18:59 UTC (permalink / raw) To: Theodor Thornhill; +Cc: 59251, casouri > Cc: casouri@gmail.com > Date: Sun, 13 Nov 2022 21:42:19 +0100 > From: Theodor Thornhill via "Bug reports for GNU Emacs, > the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org> > > BTW, should we do the same thing we did with js-mode - add a js-ts-mode > and don't change the js.el file at all? We could either go the same > route as c-ts-mode, where we define both c and c++ in the same file, or > keep them separate. What do you think? From my POV, it is best not to introduce new modes if that is possible. That way, we minimize confusion and allow users to adapt more easily. Only where the new mode is radically different from the old one and cannot be easily be an optional addition to the old one, is a completely new mode justified. ^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#59251: 29.0.50; Fix-some-inconsistencies-in-ts-modes 2022-11-14 18:59 ` bug#59251: 29.0.50; Fix-some-inconsistencies-in-ts-modes Eli Zaretskii @ 2022-11-14 19:12 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors 0 siblings, 0 replies; 11+ messages in thread From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-11-14 19:12 UTC (permalink / raw) To: Eli Zaretskii; +Cc: 59251, casouri Eli Zaretskii <eliz@gnu.org> writes: >> Cc: casouri@gmail.com >> Date: Sun, 13 Nov 2022 21:42:19 +0100 >> From: Theodor Thornhill via "Bug reports for GNU Emacs, >> the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org> >> >> BTW, should we do the same thing we did with js-mode - add a js-ts-mode >> and don't change the js.el file at all? We could either go the same >> route as c-ts-mode, where we define both c and c++ in the same file, or >> keep them separate. What do you think? > > From my POV, it is best not to introduce new modes if that is > possible. That way, we minimize confusion and allow users to adapt > more easily. Only where the new mode is radically different from the > old one and cannot be easily be an optional addition to the old one, > is a completely new mode justified. Then I think we should do something like one of the first suggestions I made weeks ago - separate the inits so that as little as possible is shared between them. If we do that, then it would at least make sense to merge css and javascript. ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2022-11-15 14:22 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-11-13 20:42 bug#59251: 29.0.50; Fix-some-inconsistencies-in-ts-modes Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors [not found] ` <handler.59251.B.16683721605982.ack@debbugs.gnu.org> 2022-11-13 22:16 ` bug#59251: Acknowledgement (29.0.50; Fix-some-inconsistencies-in-ts-modes) Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors 2022-11-13 23:01 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors 2022-11-14 0:51 ` Yuan Fu 2022-11-14 7:06 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors 2022-11-14 9:25 ` Yuan Fu 2022-11-15 12:22 ` Eli Zaretskii 2022-11-15 14:22 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors 2022-11-14 19:02 ` Eli Zaretskii 2022-11-14 18:59 ` bug#59251: 29.0.50; Fix-some-inconsistencies-in-ts-modes Eli Zaretskii 2022-11-14 19:12 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.