From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#59251: Acknowledgement (29.0.50; Fix-some-inconsistencies-in-ts-modes) Date: Mon, 14 Nov 2022 08:06:31 +0100 Message-ID: <877czy2ex4.fsf@thornhill.no> References: <87k03ya8no.fsf@thornhill.no> <87cz9qa4ab.fsf@thornhill.no> <87a64u31d0.fsf@thornhill.no> <6C5721BF-2FA2-45A4-A970-483D662A6414@gmail.com> Reply-To: Theodor Thornhill Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6143"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 59251@debbugs.gnu.org To: Yuan Fu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Nov 15 00:25:13 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ouipE-0001N3-O5 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 15 Nov 2022 00:25:12 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouioy-0001CM-6g; Mon, 14 Nov 2022 18:24:57 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ouig6-0004wo-Px for bug-gnu-emacs@gnu.org; Mon, 14 Nov 2022 18:15:47 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ouTYd-0006qj-1f for bug-gnu-emacs@gnu.org; Mon, 14 Nov 2022 02:07:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ouTYc-0000SZ-JA for bug-gnu-emacs@gnu.org; Mon, 14 Nov 2022 02:07:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Theodor Thornhill Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 14 Nov 2022 07:07:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59251 X-GNU-PR-Package: emacs Original-Received: via spool by 59251-submit@debbugs.gnu.org id=B59251.16684096051742 (code B ref 59251); Mon, 14 Nov 2022 07:07:02 +0000 Original-Received: (at 59251) by debbugs.gnu.org; 14 Nov 2022 07:06:45 +0000 Original-Received: from localhost ([127.0.0.1]:48827 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ouTYK-0000S2-V3 for submit@debbugs.gnu.org; Mon, 14 Nov 2022 02:06:45 -0500 Original-Received: from out2.migadu.com ([188.165.223.204]:22007) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ouTYF-0000Rn-4S for 59251@debbugs.gnu.org; Mon, 14 Nov 2022 02:06:43 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1668409596; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=99/mejPMpV6lAWCEbk7URV8IjvmCsq+XhyMBgnCvK6Q=; b=1BMoWeEObgXIAVNvCAIcvwm6coLhf2aWTpVsI2qTT4JSKAIKrPMid+WzwisT9hPjql8ASX MfhY1Oo/Mb991Ub9jxO/zsTDTTQyXQ4A4ARYXzRCUp+761tdP0LuUCzyjbz79mgHSvJZ5h d6UHxp/FwzMMDl6ZZ0C2Mg0coQIXHXr5/nkx5SrUIuY9J33Q04pc7kuQQXSmjlzoaDaR5s edkkSYXKQynrq458D0aPUPZrQProIlpT8bynPHbzAwRbaciVpyB7YrUVfkI6bRF2VXgQ5H pSYEOo1Nojudx8GjpgtYxzzxFWB9mWAVRkAMekXLgpfcr7nZ4psSHJeIu8OuoQ== In-Reply-To: <6C5721BF-2FA2-45A4-A970-483D662A6414@gmail.com> X-Migadu-Flow: FLOW_OUT X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:247828 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Yuan Fu writes: >> On Nov 13, 2022, at 3:01 PM, Theodor Thornhill via Bug reports for GNU E= macs, the Swiss army knife of text editors wrote: >>=20 >> Theodor Thornhill writes: >>=20 >>> Added a few more finishes. >>=20 >> Aaand another. Last one for now. I promise=E2=80=A6 > > 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=E2=80=99s opinion is to make feature-list private, and l= et > users add/remove features. Right now they can add/remove features with > treesit-recompute-feature-list. I guess we can keep them as defvar=E2=80= =99s > 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=E2=80=99t we let users set comment style themselves? Does cc-mode= have a similar variable? > You have a point. Simplified the patch. Theo --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Fix-some-inconsistencies-in-ts-modes.patch >From 60d1dcf08d2d5fc365958263dafa0e731bfbc110 Mon Sep 17 00:00:00 2001 From: Theodor Thornhill 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 --=-=-=--