GNU bug report logs - #66152
Support indenting box comments in c-ts-mode

Previous Next

Package: emacs;

Reported by: Augustin Chéneau (BTuin) <btuin <at> mailo.com>

Date: Fri, 22 Sep 2023 11:25:01 UTC

Severity: wishlist

Found in version 30.0.50

Full log


Message #22 received at 66152 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Augustin Chéneau (BTuin) <btuin <at> mailo.com>,
 66152 <at> debbugs.gnu.org
Subject: Re: bug#66152: 30.0.50; Missing indent rules in c-ts-mode
Date: Sun, 10 Dec 2023 18:41:35 -0800

On 9/26/23 5:29 AM, Augustin Chéneau (BTuin) wrote:
> I found some more issues.
>
> First, there is no rule for an element in an else clause:
>
>
> if (true)
>   do_something();
> else
> do_something_else();
>
>
> "do_something_else" is not indented.

Right. tree-sitter-c recently changed their grammar and added 
else_clause. The fix for this is pushed to emacs-29 a few days ago.

>
> There is also something weird with the bsd indent style.  It indents 
> do_something and do_something_else to parent-bol with 0 offset, so the 
> result is:
>
> if (true)
> do_something();
> else
> do_something_else();
>
>
> It is very different from the bsd style from c-mode, which produces this:
>
> if (true)
>     do_something();
> else
>     do_something_else();
>
> By looking at random files from OpenBSD, they do indent their 
> expressions inside if and else:
>
> <https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/net/bsd-comp.c?rev=1.17&content-type=text/plain> 
>
> (lines 277, 484, and 527)
>
Thanks for reporting this, probably not a lot of people use c-ts-mode 
with bsd style, and things like this goes under the radar. I pushed a 
fix for it.

>
> Also there is a second patch which tries to handle specific types of 
> comments.  I don't know how popular it is, but some people use these 
> kind of comments:
>
> /*---------.
> | %param.  |
> `---------*/
>
> Here we want the vertical bar ("|") to be indented at the same column 
> as the first "/".
>
> Currently the result is this:
>
> /*---------.
>   | %param.  |
>   `---------*/
>
> This patch is a just proof of concept.  If this new behavior is indeed 
> wanted, I would clean it up and adapt other modes.

The gallery of artisan C comments is just endless :-) If we can support 
this style, it's definitely good, the only thing to watch out for is 
that the rules could unintentionally match some other comments that 
aren't really this style. Like, does people do this:

/*
 |
 |
 |
 */

in the wild? I don't know, maybe we need a embedded gpt-4 for formatting 
comments.

Yuan





This bug report was last modified 166 days ago.

Previous Next


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