* bug#59617: 29.0.50; Add indent styles to all tree-sitter modes
@ 2022-11-26 18:59 Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
[not found] ` <handler.59617.B.166948920014495.ack@debbugs.gnu.org>
` (2 more replies)
0 siblings, 3 replies; 19+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-11-26 18:59 UTC (permalink / raw)
To: 59617; +Cc: casouri
[-- Attachment #1: Type: text/plain, Size: 241 bytes --]
Hi Yuan and others!
I've added in the ability for users to set their own indentation style
should that be needed.
I just followed what I already did in c-ts-mode and c++-ts-mode, so I
believe this shouldn't be too controversial :-)
Theo
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-indent-styles-to-all-tree-sitter-modes.patch --]
[-- Type: text/x-diff, Size: 11285 bytes --]
From 5f5695916b71af4f9e778f4bd5c51edb2c85067e Mon Sep 17 00:00:00 2001
From: Theodor Thornhill <theo@thornhill.no>
Date: Sat, 26 Nov 2022 19:54:47 +0100
Subject: [PATCH] Add indent styles to all tree-sitter modes
Enable users to provide their own function to control the indentation
style. Even though we don't supply any extra styles for indentation,
this should give the users an escape hatch should the provided style
not suit their needs.
* lisp/progmodes/c-ts-mode.el (c-ts-mode-indent-style): Fix typo.
* lisp/progmodes/csharp-mode.el (csharp-ts-mode-indent-style)
(csharp-ts-mode--set-indent-style, csharp-ts-mode): New defcustom and
helper.
* lisp/progmodes/java-ts-mode.el (java-ts-mode-indent-style)
(java-ts-mode--set-indent-style, java-ts-mode): New defcustom and
helper.
* lisp/progmodes/js.el (js-ts-mode-indent-style)
(js--treesit-set-indent-style, js-ts-mode): New defcustom and helper.
* lisp/progmodes/json-ts-mode.el (json-ts-mode-indent-style)
(json-ts-mode--set-indent-style, json-ts-mode): Enable custom indent
style.
* lisp/progmodes/typescript-ts-mode.el (typescript-ts-mode-indent-style)
(typescript-ts-mode--set-indent-style, typescript-ts-mode): Enable
custom indent style.
* lisp/progmodes/css.el (css-ts-mode-indent-style)
(css--treesit-set-indent-style, css-ts-mode): New defcustom and
helper.
---
lisp/progmodes/c-ts-mode.el | 2 +-
lisp/progmodes/csharp-mode.el | 21 ++++++++++++++++++++-
lisp/progmodes/java-ts-mode.el | 21 ++++++++++++++++++++-
lisp/progmodes/js.el | 21 ++++++++++++++++++++-
lisp/progmodes/json-ts-mode.el | 21 ++++++++++++++++++++-
lisp/progmodes/typescript-ts-mode.el | 21 ++++++++++++++++++++-
lisp/textmodes/css-mode.el | 21 ++++++++++++++++++++-
7 files changed, 121 insertions(+), 7 deletions(-)
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index fc35d9aedd..c384182772 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -52,7 +52,7 @@ c-ts-mode-indent-style
The selected style could be one of GNU, K&R, LINUX or BSD. If
one of the supplied styles doesn't suffice a function could be
-set instead. This function is expected return a list that
+set instead. This function is expected to return a list that
follows the form of `treesit-simple-indent-rules'."
:version "29.1"
:type '(choice (symbol :tag "Gnu" 'gnu)
diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el
index a544a4b5cb..a6373b5826 100644
--- a/lisp/progmodes/csharp-mode.el
+++ b/lisp/progmodes/csharp-mode.el
@@ -696,6 +696,24 @@ csharp-ts-mode-indent-offset
:safe 'integerp
:group 'csharp)
+(defcustom csharp-ts-mode-indent-style 'csharp-ts-mode--default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function is expected to
+return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'csharp-ts-mode--default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'csharp)
+
+(defun csharp-ts-mode--set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp csharp-ts-mode-indent-style)
+ (funcall csharp-ts-mode-indent-style)
+ csharp-ts-mode--indent-rules))
+
(defvar csharp-ts-mode--indent-rules
`((c-sharp
((parent-is "compilation_unit") parent-bol 0)
@@ -962,7 +980,8 @@ csharp-ts-mode
(setq-local comment-end "")
;; Indent.
- (setq-local treesit-simple-indent-rules csharp-ts-mode--indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (csharp-ts-mode--set-indent-style))
;; Electric
(setq-local electric-indent-chars
diff --git a/lisp/progmodes/java-ts-mode.el b/lisp/progmodes/java-ts-mode.el
index ee2934f53c..29de2ccb28 100644
--- a/lisp/progmodes/java-ts-mode.el
+++ b/lisp/progmodes/java-ts-mode.el
@@ -42,6 +42,24 @@ java-ts-mode-indent-offset
:safe 'integerp
:group 'java)
+(defcustom java-ts-mode-indent-style 'java-ts-mode--default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function is expected to
+return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'java-ts-mode--default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'java)
+
+(defun java-ts-mode--set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp java-ts-mode-indent-style)
+ (funcall java-ts-mode-indent-style)
+ java-ts-mode--indent-rules))
+
(defvar java-ts-mode--syntax-table
(let ((table (make-syntax-table)))
;; Taken from the cc-langs version
@@ -305,7 +323,8 @@ java-ts-mode
(setq-local treesit-comment-end (rx (+ (or "*")) "/"))
;; Indent.
- (setq-local treesit-simple-indent-rules java-ts-mode--indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (java-ts-mode--set-indent-style))
;; Electric
(setq-local electric-indent-chars
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index da05b7b364..9535d4986f 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3457,6 +3457,24 @@ js--treesit-indent-rules
((node-is "/") parent 0)
((parent-is "jsx_self_closing_element") parent js-indent-level)))))
+(defcustom js-ts-mode-indent-style 'js--treesit-default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function is expected to
+return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'js--treesit-default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'javascript)
+
+(defun js--treesit-set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp js-ts-mode-indent-style)
+ (funcall js-ts-mode-indent-style)
+ js--treesit-indent-rules))
+
(defvar js--treesit-keywords
'("as" "async" "await" "break" "case" "catch" "class" "const" "continue"
"debugger" "default" "delete" "do" "else" "export" "extends" "finally"
@@ -3862,7 +3880,8 @@ js-ts-mode
;; Tree-sitter setup.
(treesit-parser-create 'javascript)
;; Indent.
- (setq-local treesit-simple-indent-rules js--treesit-indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (js--treesit-set-indent-style))
;; Navigation.
(setq-local treesit-defun-type-regexp
(rx (or "class_declaration"
diff --git a/lisp/progmodes/json-ts-mode.el b/lisp/progmodes/json-ts-mode.el
index 101e873cf6..4ee2cad9da 100644
--- a/lisp/progmodes/json-ts-mode.el
+++ b/lisp/progmodes/json-ts-mode.el
@@ -44,6 +44,24 @@ json-ts-mode-indent-offset
:safe 'integerp
:group 'json)
+(defcustom json-ts-mode-indent-style 'json-ts-mode--default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function is expected to
+return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'json-ts-mode--default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'json)
+
+(defun json-ts-mode--set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp json-ts-mode-indent-style)
+ (funcall json-ts-mode-indent-style)
+ json-ts-mode--indent-rules))
+
(defvar json-ts-mode--syntax-table
(let ((table (make-syntax-table)))
;; Taken from the cc-langs version
@@ -147,7 +165,8 @@ json-ts-mode
(append "{}():;," electric-indent-chars))
;; Indent.
- (setq-local treesit-simple-indent-rules json-ts--indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (json-ts-mode--set-indent-style))
;; Navigation.
(setq-local treesit-defun-type-regexp
diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el
index 763686bf66..106b8363f0 100644
--- a/lisp/progmodes/typescript-ts-mode.el
+++ b/lisp/progmodes/typescript-ts-mode.el
@@ -37,6 +37,24 @@ typescript-ts-mode-indent-offset
:safe 'integerp
:group 'typescript)
+(defcustom typescript-ts-mode-indent-style 'typescript-ts-mode--default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function is expected to
+return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'typescript-ts-mode--default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'typescript)
+
+(defun typescript-ts-mode--set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp typescript-ts-mode-indent-style)
+ (funcall typescript-ts-mode-indent-style)
+ typescript-ts-mode--indent-rules))
+
(defvar typescript-ts-mode--syntax-table
(let ((table (make-syntax-table)))
;; Taken from the cc-langs version
@@ -308,7 +326,8 @@ typescript-ts-mode
(append "{}():;," electric-indent-chars))
;; Indent.
- (setq-local treesit-simple-indent-rules typescript-ts-mode--indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (typescript-ts-mode--set-indent-style))
;; Navigation.
(setq-local treesit-defun-type-regexp
diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index 734252ee66..eaf3fec939 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -1343,6 +1343,24 @@ css--treesit-indent-rules
((match nil "declaration" nil 3) (nth-sibling 2) 0)))
"Tree-sitter indentation rules for `css-ts-mode'.")
+(defcustom css-ts-mode-indent-style 'css--treesit-default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function is expected to
+return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'css--treesit-default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'css)
+
+(defun css--treesit-set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp css-ts-mode-indent-style)
+ (funcall css-ts-mode-indent-style)
+ css--treesit-indent-rules))
+
(defvar css--treesit-settings
(treesit-font-lock-rules
:feature 'comment
@@ -1804,7 +1822,8 @@ css-ts-mode
;; Tree-sitter specific setup.
(treesit-parser-create 'css)
- (setq-local treesit-simple-indent-rules css--treesit-indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (css--treesit-set-indent-style))
(setq-local treesit-defun-type-regexp "rule_set")
(setq-local treesit-font-lock-settings css--treesit-settings)
(setq-local treesit-font-lock-feature-list
--
2.34.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
[parent not found: <handler.59617.B.166948920014495.ack@debbugs.gnu.org>]
* bug#59617: 29.0.50; Add indent styles to all tree-sitter modes
[not found] ` <handler.59617.B.166948920014495.ack@debbugs.gnu.org>
@ 2022-11-27 11:50 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-27 23:38 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
1 sibling, 0 replies; 19+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-11-27 11:50 UTC (permalink / raw)
To: 59617; +Cc: eliz, larsi
Hi Eli and Lars :-)
I have some other ideas and improvements I'm planning in the tree-sitter
modes, and it would be really nice to be able to do this myself. I know
we've discussed this already, but do you still think it's premature
giving me write access? Building commits on top of eachother, then
splitting up and so on is a hassle while waiting for things to be
committed for me. And it causes extra work for you guys.
If you still think so that's ok, but I'd like to still get some more
stuff in before the split!
Theo
^ permalink raw reply [flat|nested] 19+ messages in thread
* bug#59617: 29.0.50; Add indent styles to all tree-sitter modes
[not found] ` <handler.59617.B.166948920014495.ack@debbugs.gnu.org>
2022-11-27 11:50 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-11-27 23:38 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-28 6:59 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
1 sibling, 1 reply; 19+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-11-27 23:38 UTC (permalink / raw)
To: 59617
[-- Attachment #1: Type: text/plain, Size: 39 bytes --]
Fixed a typo - see this patch:
Theo
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-indent-styles-to-all-tree-sitter-modes.patch --]
[-- Type: text/x-diff, Size: 11602 bytes --]
From be876fa59bb2999a70f183081bbd682245350d0b Mon Sep 17 00:00:00 2001
From: Theodor Thornhill <theo@thornhill.no>
Date: Sat, 26 Nov 2022 19:54:47 +0100
Subject: [PATCH] Add indent styles to all tree-sitter modes
Enable users to provide their own function to control the indentation
style. Even though we don't supply any extra styles for indentation,
this should give the users an escape hatch should the provided style
not suit their needs.
* lisp/progmodes/c-ts-mode.el (c-ts-mode-indent-style): Fix typo.
* lisp/progmodes/csharp-mode.el (csharp-ts-mode-indent-style)
(csharp-ts-mode--set-indent-style, csharp-ts-mode): New defcustom and
helper.
* lisp/progmodes/java-ts-mode.el (java-ts-mode-indent-style)
(java-ts-mode--set-indent-style, java-ts-mode): New defcustom and
helper.
* lisp/progmodes/js.el (js-ts-mode-indent-style)
(js--treesit-set-indent-style, js-ts-mode): New defcustom and helper.
* lisp/progmodes/json-ts-mode.el (json-ts-mode-indent-style)
(json-ts-mode--set-indent-style, json-ts-mode): Enable custom indent
style.
(json-ts-mode--indent-rules): Rename from 'json-ts--indent-rules'
* lisp/progmodes/typescript-ts-mode.el (typescript-ts-mode-indent-style)
(typescript-ts-mode--set-indent-style, typescript-ts-mode): Enable
custom indent style.
* lisp/progmodes/css.el (css-ts-mode-indent-style)
(css--treesit-set-indent-style, css-ts-mode): New defcustom and
helper.
(Bug#59617)
---
lisp/progmodes/c-ts-mode.el | 2 +-
lisp/progmodes/csharp-mode.el | 21 ++++++++++++++++++++-
lisp/progmodes/java-ts-mode.el | 21 ++++++++++++++++++++-
lisp/progmodes/js.el | 21 ++++++++++++++++++++-
lisp/progmodes/json-ts-mode.el | 23 +++++++++++++++++++++--
lisp/progmodes/typescript-ts-mode.el | 21 ++++++++++++++++++++-
lisp/textmodes/css-mode.el | 21 ++++++++++++++++++++-
7 files changed, 122 insertions(+), 8 deletions(-)
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 086257483e..ae0d163d6f 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -52,7 +52,7 @@ c-ts-mode-indent-style
The selected style could be one of GNU, K&R, LINUX or BSD. If
one of the supplied styles doesn't suffice a function could be
-set instead. This function is expected return a list that
+set instead. This function is expected to return a list that
follows the form of `treesit-simple-indent-rules'."
:version "29.1"
:type '(choice (symbol :tag "Gnu" 'gnu)
diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el
index 3f691956f8..01b8a7a502 100644
--- a/lisp/progmodes/csharp-mode.el
+++ b/lisp/progmodes/csharp-mode.el
@@ -625,6 +625,24 @@ csharp-ts-mode-indent-offset
:safe 'integerp
:group 'csharp)
+(defcustom csharp-ts-mode-indent-style 'csharp-ts-mode--default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function is expected to
+return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'csharp-ts-mode--default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'csharp)
+
+(defun csharp-ts-mode--set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp csharp-ts-mode-indent-style)
+ (funcall csharp-ts-mode-indent-style)
+ csharp-ts-mode--indent-rules))
+
(defvar csharp-ts-mode--indent-rules
`((c-sharp
((parent-is "compilation_unit") parent-bol 0)
@@ -892,7 +910,8 @@ csharp-ts-mode
(setq-local comment-end "")
;; Indent.
- (setq-local treesit-simple-indent-rules csharp-ts-mode--indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (csharp-ts-mode--set-indent-style))
;; Electric
(setq-local electric-indent-chars
diff --git a/lisp/progmodes/java-ts-mode.el b/lisp/progmodes/java-ts-mode.el
index dd3d6d31e0..561168008a 100644
--- a/lisp/progmodes/java-ts-mode.el
+++ b/lisp/progmodes/java-ts-mode.el
@@ -42,6 +42,24 @@ java-ts-mode-indent-offset
:safe 'integerp
:group 'java)
+(defcustom java-ts-mode-indent-style 'java-ts-mode--default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function is expected to
+return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'java-ts-mode--default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'java)
+
+(defun java-ts-mode--set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp java-ts-mode-indent-style)
+ (funcall java-ts-mode-indent-style)
+ java-ts-mode--indent-rules))
+
(defvar java-ts-mode--syntax-table
(let ((table (make-syntax-table)))
;; Taken from the cc-langs version
@@ -305,7 +323,8 @@ java-ts-mode
(setq-local treesit-comment-end (rx (+ (or "*")) "/"))
;; Indent.
- (setq-local treesit-simple-indent-rules java-ts-mode--indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (java-ts-mode--set-indent-style))
;; Electric
(setq-local electric-indent-chars
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index f2016deb5d..82c33e5b58 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3457,6 +3457,24 @@ js--treesit-indent-rules
((node-is "/") parent 0)
((parent-is "jsx_self_closing_element") parent js-indent-level)))))
+(defcustom js-ts-mode-indent-style 'js--treesit-default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function is expected to
+return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'js--treesit-default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'javascript)
+
+(defun js--treesit-set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp js-ts-mode-indent-style)
+ (funcall js-ts-mode-indent-style)
+ js--treesit-indent-rules))
+
(defvar js--treesit-keywords
'("as" "async" "await" "break" "case" "catch" "class" "const" "continue"
"debugger" "default" "delete" "do" "else" "export" "extends" "finally"
@@ -3862,7 +3880,8 @@ js-ts-mode
;; Tree-sitter setup.
(treesit-parser-create 'javascript)
;; Indent.
- (setq-local treesit-simple-indent-rules js--treesit-indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (js--treesit-set-indent-style))
;; Navigation.
(setq-local treesit-defun-type-regexp
(rx (or "class_declaration"
diff --git a/lisp/progmodes/json-ts-mode.el b/lisp/progmodes/json-ts-mode.el
index 101e873cf6..113b25a899 100644
--- a/lisp/progmodes/json-ts-mode.el
+++ b/lisp/progmodes/json-ts-mode.el
@@ -44,6 +44,24 @@ json-ts-mode-indent-offset
:safe 'integerp
:group 'json)
+(defcustom json-ts-mode-indent-style 'json-ts-mode--default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function is expected to
+return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'json-ts-mode--default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'json)
+
+(defun json-ts-mode--set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp json-ts-mode-indent-style)
+ (funcall json-ts-mode-indent-style)
+ json-ts-mode--indent-rules))
+
(defvar json-ts-mode--syntax-table
(let ((table (make-syntax-table)))
;; Taken from the cc-langs version
@@ -64,7 +82,7 @@ json-ts-mode--syntax-table
"Syntax table for `json-ts-mode'.")
-(defvar json-ts--indent-rules
+(defvar json-ts-mode--indent-rules
`((json
((node-is "}") parent-bol 0)
((node-is ")") parent-bol 0)
@@ -147,7 +165,8 @@ json-ts-mode
(append "{}():;," electric-indent-chars))
;; Indent.
- (setq-local treesit-simple-indent-rules json-ts--indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (json-ts-mode--set-indent-style))
;; Navigation.
(setq-local treesit-defun-type-regexp
diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el
index 8a9d540bd3..61e13d1723 100644
--- a/lisp/progmodes/typescript-ts-mode.el
+++ b/lisp/progmodes/typescript-ts-mode.el
@@ -37,6 +37,24 @@ typescript-ts-mode-indent-offset
:safe 'integerp
:group 'typescript)
+(defcustom typescript-ts-mode-indent-style 'typescript-ts-mode--default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function is expected to
+return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'typescript-ts-mode--default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'typescript)
+
+(defun typescript-ts-mode--set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp typescript-ts-mode-indent-style)
+ (funcall typescript-ts-mode-indent-style)
+ typescript-ts-mode--indent-rules))
+
(defvar typescript-ts-mode--syntax-table
(let ((table (make-syntax-table)))
;; Taken from the cc-langs version
@@ -304,7 +322,8 @@ typescript-ts-mode
(append "{}():;," electric-indent-chars))
;; Indent.
- (setq-local treesit-simple-indent-rules typescript-ts-mode--indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (typescript-ts-mode--set-indent-style))
;; Navigation.
(setq-local treesit-defun-type-regexp
diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index 734252ee66..eaf3fec939 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -1343,6 +1343,24 @@ css--treesit-indent-rules
((match nil "declaration" nil 3) (nth-sibling 2) 0)))
"Tree-sitter indentation rules for `css-ts-mode'.")
+(defcustom css-ts-mode-indent-style 'css--treesit-default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function is expected to
+return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'css--treesit-default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'css)
+
+(defun css--treesit-set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp css-ts-mode-indent-style)
+ (funcall css-ts-mode-indent-style)
+ css--treesit-indent-rules))
+
(defvar css--treesit-settings
(treesit-font-lock-rules
:feature 'comment
@@ -1804,7 +1822,8 @@ css-ts-mode
;; Tree-sitter specific setup.
(treesit-parser-create 'css)
- (setq-local treesit-simple-indent-rules css--treesit-indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (css--treesit-set-indent-style))
(setq-local treesit-defun-type-regexp "rule_set")
(setq-local treesit-font-lock-settings css--treesit-settings)
(setq-local treesit-font-lock-feature-list
--
2.34.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* bug#59617: 29.0.50; Add indent styles to all tree-sitter modes
2022-11-27 23:38 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-11-28 6:59 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-28 12:26 ` Eli Zaretskii
0 siblings, 1 reply; 19+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-11-28 6:59 UTC (permalink / raw)
To: 59617; +Cc: Yuan Fu
[-- Attachment #1: Type: text/plain, Size: 153 bytes --]
Theodor Thornhill <theo@thornhill.no> writes:
> Fixed a typo - see this patch:
>
Rebased the patch on top of origin/master:
What do you think, Yuan?
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-indent-styles-to-all-tree-sitter-modes.patch --]
[-- Type: text/x-diff, Size: 11602 bytes --]
From be876fa59bb2999a70f183081bbd682245350d0b Mon Sep 17 00:00:00 2001
From: Theodor Thornhill <theo@thornhill.no>
Date: Sat, 26 Nov 2022 19:54:47 +0100
Subject: [PATCH] Add indent styles to all tree-sitter modes
Enable users to provide their own function to control the indentation
style. Even though we don't supply any extra styles for indentation,
this should give the users an escape hatch should the provided style
not suit their needs.
* lisp/progmodes/c-ts-mode.el (c-ts-mode-indent-style): Fix typo.
* lisp/progmodes/csharp-mode.el (csharp-ts-mode-indent-style)
(csharp-ts-mode--set-indent-style, csharp-ts-mode): New defcustom and
helper.
* lisp/progmodes/java-ts-mode.el (java-ts-mode-indent-style)
(java-ts-mode--set-indent-style, java-ts-mode): New defcustom and
helper.
* lisp/progmodes/js.el (js-ts-mode-indent-style)
(js--treesit-set-indent-style, js-ts-mode): New defcustom and helper.
* lisp/progmodes/json-ts-mode.el (json-ts-mode-indent-style)
(json-ts-mode--set-indent-style, json-ts-mode): Enable custom indent
style.
(json-ts-mode--indent-rules): Rename from 'json-ts--indent-rules'
* lisp/progmodes/typescript-ts-mode.el (typescript-ts-mode-indent-style)
(typescript-ts-mode--set-indent-style, typescript-ts-mode): Enable
custom indent style.
* lisp/progmodes/css.el (css-ts-mode-indent-style)
(css--treesit-set-indent-style, css-ts-mode): New defcustom and
helper.
(Bug#59617)
---
lisp/progmodes/c-ts-mode.el | 2 +-
lisp/progmodes/csharp-mode.el | 21 ++++++++++++++++++++-
lisp/progmodes/java-ts-mode.el | 21 ++++++++++++++++++++-
lisp/progmodes/js.el | 21 ++++++++++++++++++++-
lisp/progmodes/json-ts-mode.el | 23 +++++++++++++++++++++--
lisp/progmodes/typescript-ts-mode.el | 21 ++++++++++++++++++++-
lisp/textmodes/css-mode.el | 21 ++++++++++++++++++++-
7 files changed, 122 insertions(+), 8 deletions(-)
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 086257483e..ae0d163d6f 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -52,7 +52,7 @@ c-ts-mode-indent-style
The selected style could be one of GNU, K&R, LINUX or BSD. If
one of the supplied styles doesn't suffice a function could be
-set instead. This function is expected return a list that
+set instead. This function is expected to return a list that
follows the form of `treesit-simple-indent-rules'."
:version "29.1"
:type '(choice (symbol :tag "Gnu" 'gnu)
diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el
index 3f691956f8..01b8a7a502 100644
--- a/lisp/progmodes/csharp-mode.el
+++ b/lisp/progmodes/csharp-mode.el
@@ -625,6 +625,24 @@ csharp-ts-mode-indent-offset
:safe 'integerp
:group 'csharp)
+(defcustom csharp-ts-mode-indent-style 'csharp-ts-mode--default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function is expected to
+return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'csharp-ts-mode--default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'csharp)
+
+(defun csharp-ts-mode--set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp csharp-ts-mode-indent-style)
+ (funcall csharp-ts-mode-indent-style)
+ csharp-ts-mode--indent-rules))
+
(defvar csharp-ts-mode--indent-rules
`((c-sharp
((parent-is "compilation_unit") parent-bol 0)
@@ -892,7 +910,8 @@ csharp-ts-mode
(setq-local comment-end "")
;; Indent.
- (setq-local treesit-simple-indent-rules csharp-ts-mode--indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (csharp-ts-mode--set-indent-style))
;; Electric
(setq-local electric-indent-chars
diff --git a/lisp/progmodes/java-ts-mode.el b/lisp/progmodes/java-ts-mode.el
index dd3d6d31e0..561168008a 100644
--- a/lisp/progmodes/java-ts-mode.el
+++ b/lisp/progmodes/java-ts-mode.el
@@ -42,6 +42,24 @@ java-ts-mode-indent-offset
:safe 'integerp
:group 'java)
+(defcustom java-ts-mode-indent-style 'java-ts-mode--default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function is expected to
+return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'java-ts-mode--default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'java)
+
+(defun java-ts-mode--set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp java-ts-mode-indent-style)
+ (funcall java-ts-mode-indent-style)
+ java-ts-mode--indent-rules))
+
(defvar java-ts-mode--syntax-table
(let ((table (make-syntax-table)))
;; Taken from the cc-langs version
@@ -305,7 +323,8 @@ java-ts-mode
(setq-local treesit-comment-end (rx (+ (or "*")) "/"))
;; Indent.
- (setq-local treesit-simple-indent-rules java-ts-mode--indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (java-ts-mode--set-indent-style))
;; Electric
(setq-local electric-indent-chars
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index f2016deb5d..82c33e5b58 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3457,6 +3457,24 @@ js--treesit-indent-rules
((node-is "/") parent 0)
((parent-is "jsx_self_closing_element") parent js-indent-level)))))
+(defcustom js-ts-mode-indent-style 'js--treesit-default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function is expected to
+return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'js--treesit-default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'javascript)
+
+(defun js--treesit-set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp js-ts-mode-indent-style)
+ (funcall js-ts-mode-indent-style)
+ js--treesit-indent-rules))
+
(defvar js--treesit-keywords
'("as" "async" "await" "break" "case" "catch" "class" "const" "continue"
"debugger" "default" "delete" "do" "else" "export" "extends" "finally"
@@ -3862,7 +3880,8 @@ js-ts-mode
;; Tree-sitter setup.
(treesit-parser-create 'javascript)
;; Indent.
- (setq-local treesit-simple-indent-rules js--treesit-indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (js--treesit-set-indent-style))
;; Navigation.
(setq-local treesit-defun-type-regexp
(rx (or "class_declaration"
diff --git a/lisp/progmodes/json-ts-mode.el b/lisp/progmodes/json-ts-mode.el
index 101e873cf6..113b25a899 100644
--- a/lisp/progmodes/json-ts-mode.el
+++ b/lisp/progmodes/json-ts-mode.el
@@ -44,6 +44,24 @@ json-ts-mode-indent-offset
:safe 'integerp
:group 'json)
+(defcustom json-ts-mode-indent-style 'json-ts-mode--default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function is expected to
+return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'json-ts-mode--default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'json)
+
+(defun json-ts-mode--set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp json-ts-mode-indent-style)
+ (funcall json-ts-mode-indent-style)
+ json-ts-mode--indent-rules))
+
(defvar json-ts-mode--syntax-table
(let ((table (make-syntax-table)))
;; Taken from the cc-langs version
@@ -64,7 +82,7 @@ json-ts-mode--syntax-table
"Syntax table for `json-ts-mode'.")
-(defvar json-ts--indent-rules
+(defvar json-ts-mode--indent-rules
`((json
((node-is "}") parent-bol 0)
((node-is ")") parent-bol 0)
@@ -147,7 +165,8 @@ json-ts-mode
(append "{}():;," electric-indent-chars))
;; Indent.
- (setq-local treesit-simple-indent-rules json-ts--indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (json-ts-mode--set-indent-style))
;; Navigation.
(setq-local treesit-defun-type-regexp
diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el
index 8a9d540bd3..61e13d1723 100644
--- a/lisp/progmodes/typescript-ts-mode.el
+++ b/lisp/progmodes/typescript-ts-mode.el
@@ -37,6 +37,24 @@ typescript-ts-mode-indent-offset
:safe 'integerp
:group 'typescript)
+(defcustom typescript-ts-mode-indent-style 'typescript-ts-mode--default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function is expected to
+return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'typescript-ts-mode--default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'typescript)
+
+(defun typescript-ts-mode--set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp typescript-ts-mode-indent-style)
+ (funcall typescript-ts-mode-indent-style)
+ typescript-ts-mode--indent-rules))
+
(defvar typescript-ts-mode--syntax-table
(let ((table (make-syntax-table)))
;; Taken from the cc-langs version
@@ -304,7 +322,8 @@ typescript-ts-mode
(append "{}():;," electric-indent-chars))
;; Indent.
- (setq-local treesit-simple-indent-rules typescript-ts-mode--indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (typescript-ts-mode--set-indent-style))
;; Navigation.
(setq-local treesit-defun-type-regexp
diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index 734252ee66..eaf3fec939 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -1343,6 +1343,24 @@ css--treesit-indent-rules
((match nil "declaration" nil 3) (nth-sibling 2) 0)))
"Tree-sitter indentation rules for `css-ts-mode'.")
+(defcustom css-ts-mode-indent-style 'css--treesit-default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function is expected to
+return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'css--treesit-default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'css)
+
+(defun css--treesit-set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp css-ts-mode-indent-style)
+ (funcall css-ts-mode-indent-style)
+ css--treesit-indent-rules))
+
(defvar css--treesit-settings
(treesit-font-lock-rules
:feature 'comment
@@ -1804,7 +1822,8 @@ css-ts-mode
;; Tree-sitter specific setup.
(treesit-parser-create 'css)
- (setq-local treesit-simple-indent-rules css--treesit-indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (css--treesit-set-indent-style))
(setq-local treesit-defun-type-regexp "rule_set")
(setq-local treesit-font-lock-settings css--treesit-settings)
(setq-local treesit-font-lock-feature-list
--
2.34.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* bug#59617: 29.0.50; Add indent styles to all tree-sitter modes
2022-11-28 6:59 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-11-28 12:26 ` Eli Zaretskii
2022-11-28 12:38 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 19+ messages in thread
From: Eli Zaretskii @ 2022-11-28 12:26 UTC (permalink / raw)
To: Theodor Thornhill; +Cc: casouri, 59617
> Cc: Yuan Fu <casouri@gmail.com>
> Date: Mon, 28 Nov 2022 07:59:10 +0100
> From: Theodor Thornhill via "Bug reports for GNU Emacs,
> the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
>
> Theodor Thornhill <theo@thornhill.no> writes:
>
> > Fixed a typo - see this patch:
> >
>
> Rebased the patch on top of origin/master:
>
> What do you think, Yuan?
FWIW, I consider user options that require functions as values not a good
UI. Many users, especially newbies, will not be able to use such options,
because they cannot come up with functions that do what they want.
It is okay to have a function value as one of N alternatives, where N > 5,
say, so that such users could still choose from "simpler" values, where the
"function" was pre-arranged by us for them. But having just the default and
a function is definitely not good enough IMO.
Cannot we come up with a couple of popular styles for each language, and
have those styles ready to be selected by simple atom values in the
defcustom?
Thanks.
P.S. Btw, what about other indentation-related facilities, like "C-c C-q" in
CC Mode?
^ permalink raw reply [flat|nested] 19+ messages in thread
* bug#59617: 29.0.50; Add indent styles to all tree-sitter modes
2022-11-28 12:26 ` Eli Zaretskii
@ 2022-11-28 12:38 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-28 13:25 ` Eli Zaretskii
0 siblings, 1 reply; 19+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-11-28 12:38 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: casouri, 59617
Eli Zaretskii <eliz@gnu.org> writes:
>> Cc: Yuan Fu <casouri@gmail.com>
>> Date: Mon, 28 Nov 2022 07:59:10 +0100
>> From: Theodor Thornhill via "Bug reports for GNU Emacs,
>> the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
>>
>> Theodor Thornhill <theo@thornhill.no> writes:
>>
>> > Fixed a typo - see this patch:
>> >
>>
>> Rebased the patch on top of origin/master:
>>
>> What do you think, Yuan?
>
> FWIW, I consider user options that require functions as values not a good
> UI. Many users, especially newbies, will not be able to use such options,
> because they cannot come up with functions that do what they want.
>
> It is okay to have a function value as one of N alternatives, where N > 5,
> say, so that such users could still choose from "simpler" values, where the
> "function" was pre-arranged by us for them. But having just the default and
> a function is definitely not good enough IMO.
>
> Cannot we come up with a couple of popular styles for each language, and
> have those styles ready to be selected by simple atom values in the
> defcustom?
>
I guess we could, but most other languages provided here have a pretty
standard coding style, IIRC. Not saying it's not any variations. This
is meant mostly as an escape hatch if needed, so that a user _can_
provide their own indentation style should they need it.
>
> P.S. Btw, what about other indentation-related facilities, like "C-c C-q" in
> CC Mode?
I'm planning on making those, yes
^ permalink raw reply [flat|nested] 19+ messages in thread
* bug#59617: 29.0.50; Add indent styles to all tree-sitter modes
2022-11-28 12:38 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-11-28 13:25 ` Eli Zaretskii
2022-11-28 13:41 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 19+ messages in thread
From: Eli Zaretskii @ 2022-11-28 13:25 UTC (permalink / raw)
To: Theodor Thornhill; +Cc: casouri, 59617
> From: Theodor Thornhill <theo@thornhill.no>
> Cc: 59617@debbugs.gnu.org, casouri@gmail.com
> Date: Mon, 28 Nov 2022 13:38:30 +0100
>
> > Cannot we come up with a couple of popular styles for each language, and
> > have those styles ready to be selected by simple atom values in the
> > defcustom?
> >
>
> I guess we could, but most other languages provided here have a pretty
> standard coding style, IIRC.
Only one standard style? I'm surprised. Even if the variations are much
less popular, they still deserve to be supported OOTB, IMO.
> Not saying it's not any variations. This is meant mostly as an escape
> hatch if needed, so that a user _can_ provide their own indentation style
> should they need it.
If we don't expect anyone reasonable to try that, fine. But if we do (and
a defcustom seems to say we do), then I'd provide a couple of other styles,
even if they are used much more rarely.
> > P.S. Btw, what about other indentation-related facilities, like "C-c C-q" in
> > CC Mode?
>
> I'm planning on making those, yes
Thanks!
^ permalink raw reply [flat|nested] 19+ messages in thread
* bug#59617: 29.0.50; Add indent styles to all tree-sitter modes
2022-11-28 13:25 ` Eli Zaretskii
@ 2022-11-28 13:41 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-28 13:44 ` Eli Zaretskii
0 siblings, 1 reply; 19+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-11-28 13:41 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: casouri, 59617
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Theodor Thornhill <theo@thornhill.no>
>> Cc: 59617@debbugs.gnu.org, casouri@gmail.com
>> Date: Mon, 28 Nov 2022 13:38:30 +0100
>>
>> > Cannot we come up with a couple of popular styles for each language, and
>> > have those styles ready to be selected by simple atom values in the
>> > defcustom?
>> >
>>
>> I guess we could, but most other languages provided here have a pretty
>> standard coding style, IIRC.
>
> Only one standard style? I'm surprised. Even if the variations are much
> less popular, they still deserve to be supported OOTB, IMO.
>
>> Not saying it's not any variations. This is meant mostly as an escape
>> hatch if needed, so that a user _can_ provide their own indentation style
>> should they need it.
>
> If we don't expect anyone reasonable to try that, fine. But if we do (and
> a defcustom seems to say we do), then I'd provide a couple of other styles,
> even if they are used much more rarely.
>
Ok, I can supply some more styles. This bug or a subsequent bug?
>> > P.S. Btw, what about other indentation-related facilities, like "C-c C-q" in
>> > CC Mode?
>>
>> I'm planning on making those, yes
>
> Thanks!
No problem.
Theo
^ permalink raw reply [flat|nested] 19+ messages in thread
* bug#59617: 29.0.50; Add indent styles to all tree-sitter modes
2022-11-28 13:41 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-11-28 13:44 ` Eli Zaretskii
2022-11-28 15:00 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 19+ messages in thread
From: Eli Zaretskii @ 2022-11-28 13:44 UTC (permalink / raw)
To: Theodor Thornhill; +Cc: casouri, 59617
> From: Theodor Thornhill <theo@thornhill.no>
> Cc: 59617@debbugs.gnu.org, casouri@gmail.com
> Date: Mon, 28 Nov 2022 14:41:57 +0100
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> > If we don't expect anyone reasonable to try that, fine. But if we do (and
> > a defcustom seems to say we do), then I'd provide a couple of other styles,
> > even if they are used much more rarely.
> >
>
> Ok, I can supply some more styles. This bug or a subsequent bug?
This one, I think. It's the same issue.
^ permalink raw reply [flat|nested] 19+ messages in thread
* bug#59617: 29.0.50; Add indent styles to all tree-sitter modes
2022-11-28 13:44 ` Eli Zaretskii
@ 2022-11-28 15:00 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-28 15:05 ` Eli Zaretskii
0 siblings, 1 reply; 19+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-11-28 15:00 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: casouri, 59617
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Theodor Thornhill <theo@thornhill.no>
>> Cc: 59617@debbugs.gnu.org, casouri@gmail.com
>> Date: Mon, 28 Nov 2022 14:41:57 +0100
>>
>> Eli Zaretskii <eliz@gnu.org> writes:
>>
>> > If we don't expect anyone reasonable to try that, fine. But if we do (and
>> > a defcustom seems to say we do), then I'd provide a couple of other styles,
>> > even if they are used much more rarely.
>> >
>>
>> Ok, I can supply some more styles. This bug or a subsequent bug?
>
> This one, I think. It's the same issue.
Hmm, I really cannot seem to find any very specific, recognized styles
for any of the languages. I think either we go with this like it is
now, or wait until later altogether. My reasoning was that _if_ some
people have very specific needs we can accomodate that, but IMO it's a
little too time-consuming looking all around after styles that noone
uses :-) I'd rather focus on improving what we have.
Should we just close this? I'm fine either way.
Theo
^ permalink raw reply [flat|nested] 19+ messages in thread
* bug#59617: 29.0.50; Add indent styles to all tree-sitter modes
2022-11-28 15:00 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-11-28 15:05 ` Eli Zaretskii
2022-11-28 15:08 ` Eli Zaretskii
0 siblings, 1 reply; 19+ messages in thread
From: Eli Zaretskii @ 2022-11-28 15:05 UTC (permalink / raw)
To: Theodor Thornhill; +Cc: casouri, 59617
> From: Theodor Thornhill <theo@thornhill.no>
> Cc: 59617@debbugs.gnu.org, casouri@gmail.com
> Date: Mon, 28 Nov 2022 16:00:58 +0100
>
> Hmm, I really cannot seem to find any very specific, recognized styles
> for any of the languages. I think either we go with this like it is
> now, or wait until later altogether. My reasoning was that _if_ some
> people have very specific needs we can accomodate that, but IMO it's a
> little too time-consuming looking all around after styles that noone
> uses :-) I'd rather focus on improving what we have.
>
> Should we just close this?
Feel free.
^ permalink raw reply [flat|nested] 19+ messages in thread
* bug#59617: 29.0.50; Add indent styles to all tree-sitter modes
2022-11-28 15:05 ` Eli Zaretskii
@ 2022-11-28 15:08 ` Eli Zaretskii
2022-11-28 16:30 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 19+ messages in thread
From: Eli Zaretskii @ 2022-11-28 15:08 UTC (permalink / raw)
To: theo; +Cc: casouri, 59617
> Cc: casouri@gmail.com, 59617@debbugs.gnu.org
> Date: Mon, 28 Nov 2022 17:05:07 +0200
> From: Eli Zaretskii <eliz@gnu.org>
>
> > From: Theodor Thornhill <theo@thornhill.no>
> > Cc: 59617@debbugs.gnu.org, casouri@gmail.com
> > Date: Mon, 28 Nov 2022 16:00:58 +0100
> >
> > Hmm, I really cannot seem to find any very specific, recognized styles
> > for any of the languages. I think either we go with this like it is
> > now, or wait until later altogether. My reasoning was that _if_ some
> > people have very specific needs we can accomodate that, but IMO it's a
> > little too time-consuming looking all around after styles that noone
> > uses :-) I'd rather focus on improving what we have.
> >
> > Should we just close this?
>
> Feel free.
But please say in the doc string that the custom function is called with no
arguments.
^ permalink raw reply [flat|nested] 19+ messages in thread
* bug#59617: 29.0.50; Add indent styles to all tree-sitter modes
2022-11-28 15:08 ` Eli Zaretskii
@ 2022-11-28 16:30 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-29 6:11 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 19+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-11-28 16:30 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: casouri, 59617
[-- Attachment #1: Type: text/plain, Size: 942 bytes --]
Eli Zaretskii <eliz@gnu.org> writes:
>> Cc: casouri@gmail.com, 59617@debbugs.gnu.org
>> Date: Mon, 28 Nov 2022 17:05:07 +0200
>> From: Eli Zaretskii <eliz@gnu.org>
>>
>> > From: Theodor Thornhill <theo@thornhill.no>
>> > Cc: 59617@debbugs.gnu.org, casouri@gmail.com
>> > Date: Mon, 28 Nov 2022 16:00:58 +0100
>> >
>> > Hmm, I really cannot seem to find any very specific, recognized styles
>> > for any of the languages. I think either we go with this like it is
>> > now, or wait until later altogether. My reasoning was that _if_ some
>> > people have very specific needs we can accomodate that, but IMO it's a
>> > little too time-consuming looking all around after styles that noone
>> > uses :-) I'd rather focus on improving what we have.
>> >
>> > Should we just close this?
>>
>> Feel free.
>
> But please say in the doc string that the custom function is called with no
> arguments.
Ok, added in this patch. Thanks!
Theo
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-indent-styles-to-all-tree-sitter-modes.patch --]
[-- Type: text/x-diff, Size: 11755 bytes --]
From 7480e472ffd4ec2cd22df2825f5b2c07b2fefc64 Mon Sep 17 00:00:00 2001
From: Theodor Thornhill <theo@thornhill.no>
Date: Sat, 26 Nov 2022 19:54:47 +0100
Subject: [PATCH] Add indent styles to all tree-sitter modes
Enable users to provide their own function to control the indentation
style. Even though we don't supply any extra styles for indentation,
this should give the users an escape hatch should the provided style
not suit their needs.
* lisp/progmodes/c-ts-mode.el (c-ts-mode-indent-style): Fix typo.
* lisp/progmodes/csharp-mode.el (csharp-ts-mode-indent-style)
(csharp-ts-mode--set-indent-style, csharp-ts-mode): New defcustom and
helper.
* lisp/progmodes/java-ts-mode.el (java-ts-mode-indent-style)
(java-ts-mode--set-indent-style, java-ts-mode): New defcustom and
helper.
* lisp/progmodes/js.el (js-ts-mode-indent-style)
(js--treesit-set-indent-style, js-ts-mode): New defcustom and helper.
* lisp/progmodes/json-ts-mode.el (json-ts-mode-indent-style)
(json-ts-mode--set-indent-style, json-ts-mode): Enable custom indent
style.
(json-ts-mode--indent-rules): Rename from 'json-ts--indent-rules'
* lisp/progmodes/typescript-ts-mode.el (typescript-ts-mode-indent-style)
(typescript-ts-mode--set-indent-style, typescript-ts-mode): Enable
custom indent style.
* lisp/progmodes/css.el (css-ts-mode-indent-style)
(css--treesit-set-indent-style, css-ts-mode): New defcustom and
helper.
(Bug#59617)
---
lisp/progmodes/c-ts-mode.el | 2 +-
lisp/progmodes/csharp-mode.el | 21 ++++++++++++++++++++-
lisp/progmodes/java-ts-mode.el | 21 ++++++++++++++++++++-
lisp/progmodes/js.el | 21 ++++++++++++++++++++-
lisp/progmodes/json-ts-mode.el | 23 +++++++++++++++++++++--
lisp/progmodes/typescript-ts-mode.el | 21 ++++++++++++++++++++-
lisp/textmodes/css-mode.el | 21 ++++++++++++++++++++-
7 files changed, 122 insertions(+), 8 deletions(-)
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index a79dabcd31..b72c17a8bd 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -52,7 +52,7 @@ c-ts-mode-indent-style
The selected style could be one of GNU, K&R, LINUX or BSD. If
one of the supplied styles doesn't suffice a function could be
-set instead. This function is expected return a list that
+set instead. This function is expected to return a list that
follows the form of `treesit-simple-indent-rules'."
:version "29.1"
:type '(choice (symbol :tag "Gnu" 'gnu)
diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el
index 6712fcc57e..59fc71356f 100644
--- a/lisp/progmodes/csharp-mode.el
+++ b/lisp/progmodes/csharp-mode.el
@@ -626,6 +626,24 @@ csharp-ts-mode-indent-offset
:safe 'integerp
:group 'csharp)
+(defcustom csharp-ts-mode-indent-style 'csharp-ts-mode--default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function takes no arguments
+and is expected to return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'csharp-ts-mode--default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'csharp)
+
+(defun csharp-ts-mode--set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp csharp-ts-mode-indent-style)
+ (funcall csharp-ts-mode-indent-style)
+ csharp-ts-mode--indent-rules))
+
(defvar csharp-ts-mode--indent-rules
`((c-sharp
((parent-is "compilation_unit") parent-bol 0)
@@ -898,7 +916,8 @@ csharp-ts-mode
(seq (+ "*") "/")))))
;; Indent.
- (setq-local treesit-simple-indent-rules csharp-ts-mode--indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (csharp-ts-mode--set-indent-style))
;; Electric
(setq-local electric-indent-chars
diff --git a/lisp/progmodes/java-ts-mode.el b/lisp/progmodes/java-ts-mode.el
index cf2482bb6e..9806b23d34 100644
--- a/lisp/progmodes/java-ts-mode.el
+++ b/lisp/progmodes/java-ts-mode.el
@@ -43,6 +43,24 @@ java-ts-mode-indent-offset
:safe 'integerp
:group 'java)
+(defcustom java-ts-mode-indent-style 'java-ts-mode--default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function takes no arguments
+and is expected to return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'java-ts-mode--default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'java)
+
+(defun java-ts-mode--set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp java-ts-mode-indent-style)
+ (funcall java-ts-mode-indent-style)
+ java-ts-mode--indent-rules))
+
(defvar java-ts-mode--syntax-table
(let ((table (make-syntax-table)))
;; Taken from the cc-langs version
@@ -309,7 +327,8 @@ java-ts-mode
(seq (+ "*") "/")))))
;; Indent.
- (setq-local treesit-simple-indent-rules java-ts-mode--indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (java-ts-mode--set-indent-style))
;; Electric
(setq-local electric-indent-chars
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index ad1fe62d42..1f25412796 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3457,6 +3457,24 @@ js--treesit-indent-rules
((node-is "/") parent 0)
((parent-is "jsx_self_closing_element") parent js-indent-level)))))
+(defcustom js-ts-mode-indent-style 'js--treesit-default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function takes no arguments
+and is expected to return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'js--treesit-default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'javascript)
+
+(defun js--treesit-set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp js-ts-mode-indent-style)
+ (funcall js-ts-mode-indent-style)
+ js--treesit-indent-rules))
+
(defvar js--treesit-keywords
'("as" "async" "await" "break" "case" "catch" "class" "const" "continue"
"debugger" "default" "delete" "do" "else" "export" "extends" "finally"
@@ -3865,7 +3883,8 @@ js-ts-mode
;; Tree-sitter setup.
(treesit-parser-create 'javascript)
;; Indent.
- (setq-local treesit-simple-indent-rules js--treesit-indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (js--treesit-set-indent-style))
;; Navigation.
(setq-local treesit-defun-type-regexp
(rx (or "class_declaration"
diff --git a/lisp/progmodes/json-ts-mode.el b/lisp/progmodes/json-ts-mode.el
index 101e873cf6..0a6debf788 100644
--- a/lisp/progmodes/json-ts-mode.el
+++ b/lisp/progmodes/json-ts-mode.el
@@ -44,6 +44,24 @@ json-ts-mode-indent-offset
:safe 'integerp
:group 'json)
+(defcustom json-ts-mode-indent-style 'json-ts-mode--default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function takes no arguments
+and is expected to return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'json-ts-mode--default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'json)
+
+(defun json-ts-mode--set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp json-ts-mode-indent-style)
+ (funcall json-ts-mode-indent-style)
+ json-ts-mode--indent-rules))
+
(defvar json-ts-mode--syntax-table
(let ((table (make-syntax-table)))
;; Taken from the cc-langs version
@@ -64,7 +82,7 @@ json-ts-mode--syntax-table
"Syntax table for `json-ts-mode'.")
-(defvar json-ts--indent-rules
+(defvar json-ts-mode--indent-rules
`((json
((node-is "}") parent-bol 0)
((node-is ")") parent-bol 0)
@@ -147,7 +165,8 @@ json-ts-mode
(append "{}():;," electric-indent-chars))
;; Indent.
- (setq-local treesit-simple-indent-rules json-ts--indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (json-ts-mode--set-indent-style))
;; Navigation.
(setq-local treesit-defun-type-regexp
diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el
index bf483a31d3..5790959e3f 100644
--- a/lisp/progmodes/typescript-ts-mode.el
+++ b/lisp/progmodes/typescript-ts-mode.el
@@ -37,6 +37,24 @@ typescript-ts-mode-indent-offset
:safe 'integerp
:group 'typescript)
+(defcustom typescript-ts-mode-indent-style 'typescript-ts-mode--default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function takes no arguments
+and is expected to return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'typescript-ts-mode--default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'typescript)
+
+(defun typescript-ts-mode--set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp typescript-ts-mode-indent-style)
+ (funcall typescript-ts-mode-indent-style)
+ typescript-ts-mode--indent-rules))
+
(defvar typescript-ts-mode--syntax-table
(let ((table (make-syntax-table)))
;; Taken from the cc-langs version
@@ -307,7 +325,8 @@ typescript-ts-mode
(append "{}():;," electric-indent-chars))
;; Indent.
- (setq-local treesit-simple-indent-rules typescript-ts-mode--indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (typescript-ts-mode--set-indent-style))
;; Navigation.
(setq-local treesit-defun-type-regexp
diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index 734252ee66..5ac456b02f 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -1343,6 +1343,24 @@ css--treesit-indent-rules
((match nil "declaration" nil 3) (nth-sibling 2) 0)))
"Tree-sitter indentation rules for `css-ts-mode'.")
+(defcustom css-ts-mode-indent-style 'css--treesit-default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function takes no arguments
+and is expected to return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'css--treesit-default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'css)
+
+(defun css--treesit-set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp css-ts-mode-indent-style)
+ (funcall css-ts-mode-indent-style)
+ css--treesit-indent-rules))
+
(defvar css--treesit-settings
(treesit-font-lock-rules
:feature 'comment
@@ -1804,7 +1822,8 @@ css-ts-mode
;; Tree-sitter specific setup.
(treesit-parser-create 'css)
- (setq-local treesit-simple-indent-rules css--treesit-indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (css--treesit-set-indent-style))
(setq-local treesit-defun-type-regexp "rule_set")
(setq-local treesit-font-lock-settings css--treesit-settings)
(setq-local treesit-font-lock-feature-list
--
2.34.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* bug#59617: 29.0.50; Add indent styles to all tree-sitter modes
2022-11-28 16:30 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-11-29 6:11 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-29 15:19 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 19+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-11-29 6:11 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: casouri, 59617
[-- Attachment #1: Type: text/plain, Size: 29 bytes --]
Rebased on emacs-29.
Theo
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-indent-styles-to-all-tree-sitter-modes.patch --]
[-- Type: text/x-diff, Size: 11755 bytes --]
From 7690dbbd4359e4bc7dad3272cc4190af0692961a Mon Sep 17 00:00:00 2001
From: Theodor Thornhill <theo@thornhill.no>
Date: Sat, 26 Nov 2022 19:54:47 +0100
Subject: [PATCH] Add indent styles to all tree-sitter modes
Enable users to provide their own function to control the indentation
style. Even though we don't supply any extra styles for indentation,
this should give the users an escape hatch should the provided style
not suit their needs.
* lisp/progmodes/c-ts-mode.el (c-ts-mode-indent-style): Fix typo.
* lisp/progmodes/csharp-mode.el (csharp-ts-mode-indent-style)
(csharp-ts-mode--set-indent-style, csharp-ts-mode): New defcustom and
helper.
* lisp/progmodes/java-ts-mode.el (java-ts-mode-indent-style)
(java-ts-mode--set-indent-style, java-ts-mode): New defcustom and
helper.
* lisp/progmodes/js.el (js-ts-mode-indent-style)
(js--treesit-set-indent-style, js-ts-mode): New defcustom and helper.
* lisp/progmodes/json-ts-mode.el (json-ts-mode-indent-style)
(json-ts-mode--set-indent-style, json-ts-mode): Enable custom indent
style.
(json-ts-mode--indent-rules): Rename from 'json-ts--indent-rules'
* lisp/progmodes/typescript-ts-mode.el (typescript-ts-mode-indent-style)
(typescript-ts-mode--set-indent-style, typescript-ts-mode): Enable
custom indent style.
* lisp/progmodes/css.el (css-ts-mode-indent-style)
(css--treesit-set-indent-style, css-ts-mode): New defcustom and
helper.
(Bug#59617)
---
lisp/progmodes/c-ts-mode.el | 2 +-
lisp/progmodes/csharp-mode.el | 21 ++++++++++++++++++++-
lisp/progmodes/java-ts-mode.el | 21 ++++++++++++++++++++-
lisp/progmodes/js.el | 21 ++++++++++++++++++++-
lisp/progmodes/json-ts-mode.el | 23 +++++++++++++++++++++--
lisp/progmodes/typescript-ts-mode.el | 21 ++++++++++++++++++++-
lisp/textmodes/css-mode.el | 21 ++++++++++++++++++++-
7 files changed, 122 insertions(+), 8 deletions(-)
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index a79dabcd31..b72c17a8bd 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -52,7 +52,7 @@ c-ts-mode-indent-style
The selected style could be one of GNU, K&R, LINUX or BSD. If
one of the supplied styles doesn't suffice a function could be
-set instead. This function is expected return a list that
+set instead. This function is expected to return a list that
follows the form of `treesit-simple-indent-rules'."
:version "29.1"
:type '(choice (symbol :tag "Gnu" 'gnu)
diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el
index 3da3079f08..426ac141a0 100644
--- a/lisp/progmodes/csharp-mode.el
+++ b/lisp/progmodes/csharp-mode.el
@@ -626,6 +626,24 @@ csharp-ts-mode-indent-offset
:safe 'integerp
:group 'csharp)
+(defcustom csharp-ts-mode-indent-style 'csharp-ts-mode--default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function takes no arguments
+and is expected to return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'csharp-ts-mode--default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'csharp)
+
+(defun csharp-ts-mode--set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp csharp-ts-mode-indent-style)
+ (funcall csharp-ts-mode-indent-style)
+ csharp-ts-mode--indent-rules))
+
(defvar csharp-ts-mode--indent-rules
`((c-sharp
((parent-is "compilation_unit") parent-bol 0)
@@ -908,7 +926,8 @@ csharp-ts-mode
(seq (+ "*") "/")))))
;; Indent.
- (setq-local treesit-simple-indent-rules csharp-ts-mode--indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (csharp-ts-mode--set-indent-style))
;; Electric
(setq-local electric-indent-chars
diff --git a/lisp/progmodes/java-ts-mode.el b/lisp/progmodes/java-ts-mode.el
index cf2482bb6e..9806b23d34 100644
--- a/lisp/progmodes/java-ts-mode.el
+++ b/lisp/progmodes/java-ts-mode.el
@@ -43,6 +43,24 @@ java-ts-mode-indent-offset
:safe 'integerp
:group 'java)
+(defcustom java-ts-mode-indent-style 'java-ts-mode--default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function takes no arguments
+and is expected to return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'java-ts-mode--default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'java)
+
+(defun java-ts-mode--set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp java-ts-mode-indent-style)
+ (funcall java-ts-mode-indent-style)
+ java-ts-mode--indent-rules))
+
(defvar java-ts-mode--syntax-table
(let ((table (make-syntax-table)))
;; Taken from the cc-langs version
@@ -309,7 +327,8 @@ java-ts-mode
(seq (+ "*") "/")))))
;; Indent.
- (setq-local treesit-simple-indent-rules java-ts-mode--indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (java-ts-mode--set-indent-style))
;; Electric
(setq-local electric-indent-chars
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index ad1fe62d42..1f25412796 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3457,6 +3457,24 @@ js--treesit-indent-rules
((node-is "/") parent 0)
((parent-is "jsx_self_closing_element") parent js-indent-level)))))
+(defcustom js-ts-mode-indent-style 'js--treesit-default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function takes no arguments
+and is expected to return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'js--treesit-default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'javascript)
+
+(defun js--treesit-set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp js-ts-mode-indent-style)
+ (funcall js-ts-mode-indent-style)
+ js--treesit-indent-rules))
+
(defvar js--treesit-keywords
'("as" "async" "await" "break" "case" "catch" "class" "const" "continue"
"debugger" "default" "delete" "do" "else" "export" "extends" "finally"
@@ -3865,7 +3883,8 @@ js-ts-mode
;; Tree-sitter setup.
(treesit-parser-create 'javascript)
;; Indent.
- (setq-local treesit-simple-indent-rules js--treesit-indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (js--treesit-set-indent-style))
;; Navigation.
(setq-local treesit-defun-type-regexp
(rx (or "class_declaration"
diff --git a/lisp/progmodes/json-ts-mode.el b/lisp/progmodes/json-ts-mode.el
index 101e873cf6..0a6debf788 100644
--- a/lisp/progmodes/json-ts-mode.el
+++ b/lisp/progmodes/json-ts-mode.el
@@ -44,6 +44,24 @@ json-ts-mode-indent-offset
:safe 'integerp
:group 'json)
+(defcustom json-ts-mode-indent-style 'json-ts-mode--default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function takes no arguments
+and is expected to return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'json-ts-mode--default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'json)
+
+(defun json-ts-mode--set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp json-ts-mode-indent-style)
+ (funcall json-ts-mode-indent-style)
+ json-ts-mode--indent-rules))
+
(defvar json-ts-mode--syntax-table
(let ((table (make-syntax-table)))
;; Taken from the cc-langs version
@@ -64,7 +82,7 @@ json-ts-mode--syntax-table
"Syntax table for `json-ts-mode'.")
-(defvar json-ts--indent-rules
+(defvar json-ts-mode--indent-rules
`((json
((node-is "}") parent-bol 0)
((node-is ")") parent-bol 0)
@@ -147,7 +165,8 @@ json-ts-mode
(append "{}():;," electric-indent-chars))
;; Indent.
- (setq-local treesit-simple-indent-rules json-ts--indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (json-ts-mode--set-indent-style))
;; Navigation.
(setq-local treesit-defun-type-regexp
diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el
index 6c926a4e3e..cf4e8512c0 100644
--- a/lisp/progmodes/typescript-ts-mode.el
+++ b/lisp/progmodes/typescript-ts-mode.el
@@ -37,6 +37,24 @@ typescript-ts-mode-indent-offset
:safe 'integerp
:group 'typescript)
+(defcustom typescript-ts-mode-indent-style 'typescript-ts-mode--default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function takes no arguments
+and is expected to return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'typescript-ts-mode--default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'typescript)
+
+(defun typescript-ts-mode--set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp typescript-ts-mode-indent-style)
+ (funcall typescript-ts-mode-indent-style)
+ typescript-ts-mode--indent-rules))
+
(defvar typescript-ts-mode--syntax-table
(let ((table (make-syntax-table)))
;; Taken from the cc-langs version
@@ -313,7 +331,8 @@ typescript-ts-mode
(append "{}():;," electric-indent-chars))
;; Indent.
- (setq-local treesit-simple-indent-rules typescript-ts-mode--indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (typescript-ts-mode--set-indent-style))
;; Navigation.
(setq-local treesit-defun-type-regexp
diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index b82886e397..aaf1c91443 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -1343,6 +1343,24 @@ css--treesit-indent-rules
((match nil "declaration" nil 3) (nth-sibling 2) 0)))
"Tree-sitter indentation rules for `css-ts-mode'.")
+(defcustom css-ts-mode-indent-style 'css--treesit-default-style
+ "Style used for indentation.
+
+The selected style could either be the default style, or a
+function could be set instead. This function takes no arguments
+and is expected to return a list that follows the form of
+`treesit-simple-indent-rules'."
+ :version "29.1"
+ :type '(choice (symbol :tag "Default" 'css--treesit-default-style)
+ (function :tag "A function for user customized style" ignore))
+ :group 'css)
+
+(defun css--treesit-set-indent-style ()
+ "Helper function to set indentation style."
+ (if (functionp css-ts-mode-indent-style)
+ (funcall css-ts-mode-indent-style)
+ css--treesit-indent-rules))
+
(defvar css--treesit-settings
(treesit-font-lock-rules
:feature 'comment
@@ -1832,7 +1850,8 @@ css-ts-mode
;; Tree-sitter specific setup.
(treesit-parser-create 'css)
- (setq-local treesit-simple-indent-rules css--treesit-indent-rules)
+ (setq-local treesit-simple-indent-rules
+ (css--treesit-set-indent-style))
(setq-local treesit-defun-type-regexp "rule_set")
(setq-local treesit-font-lock-settings css--treesit-settings)
(setq-local treesit-font-lock-feature-list
--
2.34.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* bug#59617: 29.0.50; Add indent styles to all tree-sitter modes
2022-11-26 18:59 bug#59617: 29.0.50; Add indent styles to all tree-sitter modes Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
[not found] ` <handler.59617.B.166948920014495.ack@debbugs.gnu.org>
@ 2022-11-30 21:44 ` Yuan Fu
2022-11-30 22:24 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-02 5:26 ` Yuan Fu
2 siblings, 1 reply; 19+ messages in thread
From: Yuan Fu @ 2022-11-30 21:44 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: Theodor Thornhill, 59617
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Theodor Thornhill <theo@thornhill.no>
>> Cc: casouri@gmail.com, 59617@debbugs.gnu.org
>> Date: Tue, 29 Nov 2022 16:19:26 +0100
>>
>> Theodor Thornhill <theo@thornhill.no> writes:
>>
>> > Rebased on emacs-29.
>> >
>>
>> Is this good to go or should I change something here?
>
> Good to go from my POV, but I wanted also to hear from Yuan.
>
> Thanks.
Hey sorry, I was busy with some other things. I’ve looked at the patch,
it seems adding a hook that sets treesit-simple-indent-rules would have
the same effect, no? (Ie, user already can set a custom indent style)
Like instead of
(defvar my-personal-csharp-mode-indent-rules (...))
(setq csharp-ts-mode-indent-style
(lambda () my-personal-csharp-mode-indent-rules))
you can just do
(defvar my-personal-csharp-mode-indent-rules (...))
(add-hook 'csharp-mode-hook
(lambda ()
(setq treesit-simple-indent-rules
my-personal-csharp-mode-indent-rules)))
This way there is no need to define a custom option and a function for
each mode. And users can use the same variable
treesit-simple-indent-rules, just in different major mode hooks.
Yuan
^ permalink raw reply [flat|nested] 19+ messages in thread
* bug#59617: 29.0.50; Add indent styles to all tree-sitter modes
2022-11-30 21:44 ` Yuan Fu
@ 2022-11-30 22:24 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 0 replies; 19+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-11-30 22:24 UTC (permalink / raw)
To: Yuan Fu, Eli Zaretskii; +Cc: 59617
On 30 November 2022 22:44:39 CET, Yuan Fu <casouri@gmail.com> wrote:
>
>Eli Zaretskii <eliz@gnu.org> writes:
>
>>> From: Theodor Thornhill <theo@thornhill.no>
>>> Cc: casouri@gmail.com, 59617@debbugs.gnu.org
>>> Date: Tue, 29 Nov 2022 16:19:26 +0100
>>>
>>> Theodor Thornhill <theo@thornhill.no> writes:
>>>
>>> > Rebased on emacs-29.
>>> >
>>>
>>> Is this good to go or should I change something here?
>>
>> Good to go from my POV, but I wanted also to hear from Yuan.
>>
>> Thanks.
>
>Hey sorry, I was busy with some other things. I’ve looked at the patch,
>it seems adding a hook that sets treesit-simple-indent-rules would have
>the same effect, no? (Ie, user already can set a custom indent style)
>Like instead of
>
>(defvar my-personal-csharp-mode-indent-rules (...))
>
>(setq csharp-ts-mode-indent-style
> (lambda () my-personal-csharp-mode-indent-rules))
>
>you can just do
>
>(defvar my-personal-csharp-mode-indent-rules (...))
>
>(add-hook 'csharp-mode-hook
> (lambda ()
> (setq treesit-simple-indent-rules
> my-personal-csharp-mode-indent-rules)))
>
>This way there is no need to define a custom option and a function for
>each mode. And users can use the same variable
>treesit-simple-indent-rules, just in different major mode hooks.
>
>Yuan
Hmm I think you're right, and I think I agree :)
Theo
^ permalink raw reply [flat|nested] 19+ messages in thread
* bug#59617: 29.0.50; Add indent styles to all tree-sitter modes
2022-11-26 18:59 bug#59617: 29.0.50; Add indent styles to all tree-sitter modes Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
[not found] ` <handler.59617.B.166948920014495.ack@debbugs.gnu.org>
2022-11-30 21:44 ` Yuan Fu
@ 2022-12-02 5:26 ` Yuan Fu
2 siblings, 0 replies; 19+ messages in thread
From: Yuan Fu @ 2022-12-02 5:26 UTC (permalink / raw)
To: Theodor Thornhill; +Cc: 59617-done, Eli Zaretskii
Theodor Thornhill <theo@thornhill.no> writes:
> On 30 November 2022 22:44:39 CET, Yuan Fu <casouri@gmail.com> wrote:
>>
>>Eli Zaretskii <eliz@gnu.org> writes:
>>
>>>> From: Theodor Thornhill <theo@thornhill.no>
>>>> Cc: casouri@gmail.com, 59617@debbugs.gnu.org
>>>> Date: Tue, 29 Nov 2022 16:19:26 +0100
>>>>
>>>> Theodor Thornhill <theo@thornhill.no> writes:
>>>>
>>>> > Rebased on emacs-29.
>>>> >
>>>>
>>>> Is this good to go or should I change something here?
>>>
>>> Good to go from my POV, but I wanted also to hear from Yuan.
>>>
>>> Thanks.
>>
>>Hey sorry, I was busy with some other things. I’ve looked at the patch,
>>it seems adding a hook that sets treesit-simple-indent-rules would have
>>the same effect, no? (Ie, user already can set a custom indent style)
>>Like instead of
>>
>>(defvar my-personal-csharp-mode-indent-rules (...))
>>
>>(setq csharp-ts-mode-indent-style
>> (lambda () my-personal-csharp-mode-indent-rules))
>>
>>you can just do
>>
>>(defvar my-personal-csharp-mode-indent-rules (...))
>>
>>(add-hook 'csharp-mode-hook
>> (lambda ()
>> (setq treesit-simple-indent-rules
>> my-personal-csharp-mode-indent-rules)))
>>
>>This way there is no need to define a custom option and a function for
>>each mode. And users can use the same variable
>>treesit-simple-indent-rules, just in different major mode hooks.
>>
>>Yuan
>
> Hmm I think you're right, and I think I agree :)
>
> Theo
Cool :-) I’m closing this then.
Yuan
^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2022-12-02 5:26 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-26 18:59 bug#59617: 29.0.50; Add indent styles to all tree-sitter modes Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
[not found] ` <handler.59617.B.166948920014495.ack@debbugs.gnu.org>
2022-11-27 11:50 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-27 23:38 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-28 6:59 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-28 12:26 ` Eli Zaretskii
2022-11-28 12:38 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-28 13:25 ` Eli Zaretskii
2022-11-28 13:41 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-28 13:44 ` Eli Zaretskii
2022-11-28 15:00 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-28 15:05 ` Eli Zaretskii
2022-11-28 15:08 ` Eli Zaretskii
2022-11-28 16:30 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-29 6:11 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-29 15:19 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-29 15:44 ` Eli Zaretskii
2022-11-30 21:44 ` Yuan Fu
2022-11-30 22:24 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-02 5:26 ` Yuan Fu
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).