[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: treesit indentation "blinking"

From: Lynn Winebarger
Subject: Re: treesit indentation "blinking"
Date: Wed, 29 Mar 2023 18:56:01 -0400

On Wed, Mar 29, 2023, 6:29 PM João Távora <joaotavora@gmail.com> wrote:
On Wed, Mar 29, 2023 at 3:26 AM Eli Zaretskii <eliz@gnu.org> wrote:
> > From: João Távora <joaotavora@gmail.com>
> > Cc: Dmitry Gutov <dgutov@yandex.ru>,  dancol@dancol.orgcasouri@gmail.com,
> >   emacs-devel@gnu.org, theo@thornhill.no
> > Date: Tue, 28 Mar 2023 23:11:05 +0100
> >
> > Though a number of indenting problems would remain after that, at least
> > this one clear annoyance would be solved.  So if there are no
> > objections, I propose to apply this patch.
> >
> > diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
> > index 59eb9fc23e6..88360716381 100644
> > --- a/lisp/progmodes/c-ts-mode.el
> > +++ b/lisp/progmodes/c-ts-mode.el
> > @@ -956,10 +956,6 @@ c-ts-base-mode
> >    ;; Comment
> >    (c-ts-common-comment-setup)
> >
> > -  ;; Electric
> > -  (setq-local electric-indent-chars
> > -              (append "{}():;,#" electric-indent-chars))
> > -
> >    ;; Imenu.
> >    (setq-local treesit-simple-imenu-settings
> >                (let ((pred #'c-ts-mode--defun-valid-p))
> >
> > In master?  In emacs-29?
> I suggest to do this in emacs-29, but conditionally, with a
> defcustom.  This will allow users to try both ways and maybe we will
> have some feedback regarding what is the best way.

I'm not fond of creating a defcustom to work around what I consider
as a simple bug and to configure something which the user can already
configure with a two-line mode hook addition. So I won't do that
change myself.

> I'm also interested to know what other editors do, as Daniel points
> out.

I don't use many other editors but I can tell you that online editors
like the ones found at hackerrank.com, which I strongly suspect are
based on LSP + treesitter behave as if electric-pair-mode was on
and electric-indent-chars is just '(?\n).  I.e. they auto-indent
on newline and don't bounce around when symbols such as ':',')' or
';' are typed.  As far as I can tell, auto-indenting on characters
other than newline is an Emacs invention that only works well if a
mode has near-perfect predictive powers of indentation, which
c++-ts-mode clearly doesn't have (yet).

And then my personal opinion is that it is an annoying
feature to have on by default as it whole lines about.
Having electric-indent-chars set to '(?\n), like c++-mode
has, is fine.

I would think the advantage of using tree-sitter is triggering formatting based on lexemes and grammar symbols rather than raw characters.  So instead of ';' a formatting action might be triggered by the parser deducing a lexeme/symbol STATEMENT-SEPARATOR, as opposed to a ';' separating clauses in a for statement.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]