emacs-devel
[Top][All Lists]
Advanced

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

Re: c-ts-mode


From: João Távora
Subject: Re: c-ts-mode
Date: Fri, 8 Sep 2023 13:38:58 +0100

On Fri, Sep 8, 2023 at 12:26 PM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > From: João Távora <joaotavora@gmail.com>
> > Cc: Theodor Thornhill <theo@thornhill.no>,  casouri@gmail.com,
> >   spacibba@aol.com,  emacs-devel@gnu.org
> > Date: Fri, 08 Sep 2023 08:25:50 +0100
> >
> > > What I had in mind was a simple alist, like CC Mode uses, with an
> > > infrastructure function to install it.  Patches are welcome.
> >
> > It would certainly work for me, at least for my very simple case, and I
> > would be happy for this.  Not sure it is half as powerful, for example
> > how would you make that simple alist express cases where you want to add
> > the rules _after_ the base set?
>
> How does CC Mode support this (if it does)?

No idea, I don't know CC Mode's styling interface well beyond
the trivial example I showed.

It does seems like CC Mode have different mechanics?
Maybe order doesn't matter there?

> Anything beyond that is, of course, welcome, but it is
> less important from my POV.

Sure makes sense.  As I said I'm just conjecturing someone
will need that flexibility because rule ordering is a fundamental
part of the mechanics in TS and I don't think we abstract it
away.  But personally, for those ridiculous two rules, I didn't
need it at all, adding at the front was just fine

Anyway, it's worth pointing out that unless you're extremely adept
at crafting indentation styles for Emacs, you're always in a losing
battle when working on multiple projects, since many projects
nowadays (not just C/C++) use an external format definition.
A .clang-format  (even we have one since 2017) or other similar
files.  These are understood by other editors and tools.

Maybe in the past CC Mode's styles were very useful, but I don't
think they attract the same interest today because there are these
external tools.  For the same reason, I don't predict ts
indentation styles to become widely used.

Of course, this is a big annoyance, because there always multiple
competing sources of indentation rules.  Emacs TAB use one thing,
everyone else uses something else.

Personally I've not been fighting this, i.e. I gave up.  I use
Emacs indentation rules to more or less align the file with the rules
and then make sure to run the tool (maybe via eglot-format)
before committing.  It'd be great if I could rely on indent-region
or C-M-q to produce the canonical indentation like I do in
Lisp modes, but I can't.

A more promising solution to this whole problem would be
to somehow bring these external formatter's rules to meet Emacs's
idea of "just indent these lines".

I tried to do that with Eglot (and Theo helped out) via
indent-region-function but we alas it didn't work very well,
because -- at least for clangd -- the LSP formatter (which
delegates to clang-format under the hood) has a tendency to add
and remove newlines even if you ask it to stay within the
same line.  So basic things like indenting an empty line is
essentially impossible.

João



reply via email to

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