all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Arteen Abrishami <arteen@linux.ucla.edu>, Yuan Fu <casouri@gmail.com>
Cc: 67417@debbugs.gnu.org
Subject: bug#67417: 29.1.50; c-ts-mode syntax issues with no brackets
Date: Fri, 24 Nov 2023 09:23:29 +0200	[thread overview]
Message-ID: <83h6lbfwcu.fsf@gnu.org> (raw)
In-Reply-To: <B398EA0C-890A-4363-94F3-828970B0ED6F@linux.ucla.edu> (bug-gnu-emacs@gnu.org)

> Date: Thu, 23 Nov 2023 12:55:31 -0800
> From:  Arteen Abrishami via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
> 
> This is specifically for the usage of `c-ts-mode` and is not a problem
> in `c-mode`. Sometimes, when you type something like:
> 
> else
> break
> 
> it won't indent the "break" until you type a semicolon. In this below
> scenario, it does not indent the break at all, but `c-mode` does, and
> switching from `c-mode` to `c-ts-mode` with correct indentation leaves
> it fixed, but `c-ts-mode` cannot detect or fix it itself.
> 
> You can put it into a `.c` buffer all by itself and see:
> 
> ```
> unsigned
> heap_pop(struct heapq * heap)
> {
>   if (heap->sz == 0)
>     return -1;
> 
>   unsigned ret_val = heap->vals[0];
>   heap->vals[0] = heap->vals[heap->len];
>   heap->len -= 1;
>   unsigned i = 0;
>   unsigned lc;
> 
>   while ((lc = HEAPQ_L_CHILD(i)) < heap->len)
>     {
>       unsigned rc = HEAPQ_R_CHILD(i);
>       /* no right child for our guy, special case */      
>       if (rc == heap->len)
>         {
>           if (heap->vals[lc] < heap->vals[i])
>             SWAP(heap->vals[lc], heap->vals[i]);
>           break;
>         }
> 
>       if (heap->vals[lc] < heap->vals[i])
>         {
>           SWAP(heap->vals[lc], heap->vals[i]);
>           i = lc;
>         }
>       else if (heap->vals[rc] < heap->vals[i])
>         {
>           SWAP(heap->vals[rc], heap->vals[i]);
>           i = rc;
>         }
>       else
>       break;
>       
>     }
> }
> ```
> 
> The very last break on the else without brackets around it will not indent.c

Yuan, any comments?

My personal take on this is that as long as typing the required
semi-colons fixes the indentation, we are okay in these cases, but if
we can do better (i.e. if the problem is not that tree-sitter returns
a tree with an error node), we should fix this even without relying on
the electric semi-colon.

In the specific example above, it looks like tree-sitter does succeed
in parsing and shows a valid tree:

	   alternative: 
	    (else_clause else
	     (break_statement break ;)))))

So I wonder why we don't indent the "break;" part here.

Comparison with c-mode is not relevant here, btw, since c-mode uses a
very different strategy for computing indentation.





  reply	other threads:[~2023-11-24  7:23 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-23 20:55 bug#67417: 29.1.50; c-ts-mode syntax issues with no brackets Arteen Abrishami via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-24  7:23 ` Eli Zaretskii [this message]
2023-11-24 18:26   ` Dmitry Gutov
2023-11-27  1:47     ` Yuan Fu
2023-11-27  2:22       ` Dmitry Gutov
2023-11-28  6:55         ` Yuan Fu
2023-11-28 14:27           ` Eli Zaretskii
2023-11-28 15:31           ` Dmitry Gutov
2023-12-01  7:58             ` Yuan Fu
2023-12-09  8:27               ` Eli Zaretskii
2023-12-10  9:29                 ` Yuan Fu
2023-12-11  0:29                   ` Dmitry Gutov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83h6lbfwcu.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=67417@debbugs.gnu.org \
    --cc=arteen@linux.ucla.edu \
    --cc=casouri@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.