GNU bug report logs - #61502
29.0.60; c-ts-mode auto-indent not working

Previous Next

Package: emacs;

Reported by: Pankaj Jangid <pankaj <at> codeisgreat.org>

Date: Tue, 14 Feb 2023 04:37:01 UTC

Severity: normal

Found in version 29.0.60

Full log


View this message in rfc822 format

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Theodor Thornhill <theo <at> thornhill.no>, Eli Zaretskii <eliz <at> gnu.org>, Pankaj Jangid <pankaj <at> codeisgreat.org>, Yuan Fu <casouri <at> gmail.com>
Cc: 61502 <at> debbugs.gnu.org
Subject: bug#61502: 29.0.60; c-ts-mode auto-indent not working
Date: Wed, 15 Feb 2023 02:12:23 +0200
On 14/02/2023 23:00, Theodor Thornhill via Bug reports for GNU Emacs, 
the Swiss army knife of text editors wrote:
> 
> On 14 February 2023 21:59:03 CET, Dmitry Gutov<dgutov <at> yandex.ru>  wrote:
>> On 14/02/2023 21:41, Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors wrote:
>>> diff --git a/lisp/treesit.el b/lisp/treesit.el
>>> index 749781894b..300a703515 100644
>>> --- a/lisp/treesit.el
>>> +++ b/lisp/treesit.el
>>> @@ -1418,6 +1418,8 @@ treesit--indent-1
>>>             ;; encompass the whitespace.
>>>             (parent (cond ((and node parser)
>>>                            (treesit-node-parent node))
>>> +                       ((equal (treesit-node-type smallest-node) "}")
>>> +                        (treesit-node-parent smallest-node))
>>>                           (t (treesit-node-on bol bol)))))
>>>          (funcall treesit-indent-function node parent bol))))
>> Is it a good idea to add C-specific constants to generic code?
>>
>> Other modes might not have a node called "}" at all.
> Yeah this was merely an example. There may be some "block-ender" concept one could envision. I need to experiment with it, and it may not be feasible at all

I was thinking we could use a more/grammar-specific override to choose 
which node to use to base the indentation on.

I.e. being able to override this piece of logic:

               (treesit-parent-while
                smallest-node
                (lambda (node)
                  (and (eq bol (treesit-node-start node))
                       (not (treesit-node-eq node root)))))

It could also help with issues like 
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=60602#8, to avoid 
duplication in indentation rules.

AFAICT this is largely possible to do already by changing 
treesit-indent-function to some mode-specific wrapper, but an override 
like the above could be written more succinctly.




This bug report was last modified 2 years and 123 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.