all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Björn Lindqvist" <bjourne@gmail.com>
To: Emacs developers <emacs-devel@gnu.org>
Subject: How does c-ts-mode, tree-sitter indentation, and preprocessor directives work?
Date: Thu, 28 Nov 2024 00:27:17 +0100	[thread overview]
Message-ID: <CALG+76cWBm7Mhs49=w5SDQZ5dgvtjX8syxYzZRucfWmnhoCwRA@mail.gmail.com> (raw)

Hello Emacs developers!

I've been trying to get c-ts-mode to indent like I want, but I'm
running into problems related to preprocessor directives. For
example, consider a type definition nested in two #ifdefs:

    #ifdef X
    #ifdef Y
    typedef int foo;
    #endif
    #endif

Since both the parent and grand parent of the type_definition is a
preproc_ifdef no rule matches. Another issue is that I want my
preprocessor directives kept at column 0, which unfortunately screws
up all rules that refer to the parent. E.g.:

    ((parent-is "if_statement") standalone-parent 4)

Doesn't work for

    int main() {
        if (true)
    #ifdef A
            prutt();
    #else
            fis();
    #endif
    }

The rule I'd like to express is "take the indent of the closest
*indenting* parent and add one indent". That rule would match whether
that parent is a "while_statement", "if_statement", "for_statement",
etc. You can't express such rules with tree-sitter, can you?

Btw, I get that tree-sitter can't handle *all* weird preprocessor
constructs you can create, but my examples are really common and
appear in most C code bases.


-- 
mvh/best regards Björn Lindqvist



             reply	other threads:[~2024-11-27 23:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-27 23:27 Björn Lindqvist [this message]
2024-11-28  7:30 ` How does c-ts-mode, tree-sitter indentation, and preprocessor directives work? Eli Zaretskii
2024-11-28 10:03   ` Yuan Fu
2024-11-28 18:30   ` Filippo Argiolas
2024-12-01  6:18     ` Yuan Fu
2024-12-01  8:36       ` Filippo Argiolas
2024-12-01  9:32         ` Yuan Fu

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='CALG+76cWBm7Mhs49=w5SDQZ5dgvtjX8syxYzZRucfWmnhoCwRA@mail.gmail.com' \
    --to=bjourne@gmail.com \
    --cc=emacs-devel@gnu.org \
    /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.