From: Theodor Thornhill <theo@thornhill.no>
To: emacs-devel@gnu.org
Cc: casouri@gmail.com
Subject: Allow indentation styles by use of function in tree-sitter
Date: Sun, 06 Nov 2022 13:52:08 +0100 [thread overview]
Message-ID: <871qqgjldz.fsf@thornhill.no> (raw)
[-- Attachment #1: Type: text/plain, Size: 499 bytes --]
Hi Yuan!
I was thinking that a quick way to enable indentation styles and
customizable indentation styles is to also accept a function in
tree-sitter-simple-indent.
What do you think of the suggested patch?
That would allow a defcustom such as
```
(defcustom c-ts-mode-indent-rule-function #'c-ts-mode--some-specific-style
"Indentation style of choice"
:group 'c)
```
and in the major-mode init:
```
(setq-local treesit-simple-indent-rules c-ts-mode-indent-rule-function)
```
--
Theo
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Make-treesit-simple-indent-rules-accept-function.patch --]
[-- Type: text/x-diff, Size: 1553 bytes --]
From 9dc7d1151eb15880285d4015efa1579f9e8817ed Mon Sep 17 00:00:00 2001
From: Theodor Thornhill <theo@thornhill.no>
Date: Sun, 6 Nov 2022 13:48:39 +0100
Subject: [PATCH] Make treesit-simple-indent-rules accept function
* lisp/treesit.el (treesit-simple-indent): Make treesit-simple-indent
accept a function that returns a list of the same type as before.
(treesit-simple-indent-rules): Document said change.
---
lisp/treesit.el | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 84be69d8b7..18c9abd658 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -882,7 +882,8 @@ treesit--indent-verbose
"If non-nil, log progress when indenting.")
(defvar-local treesit-simple-indent-rules nil
- "A list of indent rule settings.
+ "A list, or a function that returns a list of indent rule settings.
+
Each indent rule setting should be (LANGUAGE . RULES),
where LANGUAGE is a language symbol, and RULES is a list of
@@ -1292,7 +1293,9 @@ treesit-simple-indent
(cons nil nil))
(let* ((language (treesit-node-language parent))
(rules (alist-get language
- treesit-simple-indent-rules)))
+ (if (functionp treesit-simple-indent-rules)
+ (funcall treesit-simple-indent-rules)
+ treesit-simple-indent-rules))))
(cl-loop for rule in rules
for pred = (nth 0 rule)
for anchor = (nth 1 rule)
--
2.34.1
next reply other threads:[~2022-11-06 12:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-06 12:52 Theodor Thornhill [this message]
2022-11-07 0:06 ` Allow indentation styles by use of function in tree-sitter Yuan Fu
2022-11-07 8:00 ` Theodor Thornhill
2022-11-07 9:13 ` Yuan Fu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871qqgjldz.fsf@thornhill.no \
--to=theo@thornhill.no \
--cc=casouri@gmail.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.