all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Allow indentation styles by use of function in tree-sitter
@ 2022-11-06 12:52 Theodor Thornhill
  2022-11-07  0:06 ` Yuan Fu
  0 siblings, 1 reply; 4+ messages in thread
From: Theodor Thornhill @ 2022-11-06 12:52 UTC (permalink / raw)
  To: emacs-devel; +Cc: casouri

[-- 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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-07  9:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-06 12:52 Allow indentation styles by use of function in tree-sitter Theodor Thornhill
2022-11-07  0:06 ` Yuan Fu
2022-11-07  8:00   ` Theodor Thornhill
2022-11-07  9:13     ` Yuan Fu

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.