From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill Newsgroups: gmane.emacs.devel Subject: Allow indentation styles by use of function in tree-sitter Date: Sun, 06 Nov 2022 13:52:08 +0100 Message-ID: <871qqgjldz.fsf@thornhill.no> 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="14311"; mail-complaints-to="usenet@ciao.gmane.io" Cc: casouri@gmail.com To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Nov 06 13:53:05 2022 Return-path: Envelope-to: ged-emacs-devel@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 1orf97-0003Sb-HA for ged-emacs-devel@m.gmane-mx.org; Sun, 06 Nov 2022 13:53:05 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1orf8N-0005St-9M; Sun, 06 Nov 2022 07:52:19 -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 1orf8K-0005R7-Iu for emacs-devel@gnu.org; Sun, 06 Nov 2022 07:52:16 -0500 Original-Received: from out2.migadu.com ([188.165.223.204]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1orf8I-0000rx-5n for emacs-devel@gnu.org; Sun, 06 Nov 2022 07:52:16 -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=1667739130; 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; bh=ZKukKhp+HEB4M4zCRayhpYTKGNC7dPcw7wIZ57UR6HQ=; b=e07e9pq7q0zWsQAx8czmU/KaVQHfaOTF0RkYz/1jQYur49MVv5jfjSDMBaW5uktCe8a/dy W8+CLXZmc1a2lQ1CBMC9ncQuzvcNyr8wAh+rL6sIZljGaXmG0GpvZJJ82z11QLPgqNGOJt E8sh1vg+Li1+Q6wz6wgleyTN5d+kV1zgx4JXk+ZNvRvVTdiiGWMYuVzS2T74HLNHeOl5h0 LuwTIny57WHuG2w/DUrnx0ovnYCc00Qf3qVaTOIfZsqxsE96EtWHBdb6NHWNHsJCBm8ME0 GmAtwVBk6Ki8HDwOO4hCHXyMMqrtxPMtNft2zGmjbRPdhXAb229KbGOUF0yg7A== X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=188.165.223.204; envelope-from=theo@thornhill.no; helo=out2.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: "Emacs-devel" Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:299252 Archived-At: --=-=-= Content-Type: text/plain 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 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Make-treesit-simple-indent-rules-accept-function.patch >From 9dc7d1151eb15880285d4015efa1579f9e8817ed Mon Sep 17 00:00:00 2001 From: Theodor Thornhill 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 --=-=-=--