GNU bug report logs - #77901
tsx-ts-mode: ternary chains are indented as a tree

Previous Next

Package: emacs;

Reported by: Konstantin Kharlamov <Hi-Angel <at> yandex.ru>

Date: Fri, 18 Apr 2025 14:26:06 UTC

Severity: normal

Done: Yuan Fu <casouri <at> gmail.com>

Full log


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

From: Konstantin Kharlamov <Hi-Angel <at> yandex.ru>
To: Yuan Fu <casouri <at> gmail.com>
Cc: 77901 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>
Subject: Re: bug#77901: tsx-ts-mode: ternary chains are indented as a tree
Date: Fri, 16 May 2025 13:22:19 +0700
On Thu, 2025-05-15 at 20:12 -0700, Yuan Fu wrote:
> 
> 
> > On May 14, 2025, at 7:50 AM, Konstantin Kharlamov
> > <Hi-Angel <at> yandex.ru> wrote:
> > 
> > On Tue, 2025-05-13 at 12:45 -0700, Yuan Fu wrote:
> > > Hey, sorry for the delay.
> > > 
> > > > On May 10, 2025, at 3:16 AM, Eli Zaretskii <eliz <at> gnu.org>
> > > > wrote:
> > > > 
> > > > > From: Konstantin Kharlamov <Hi-Angel <at> yandex.ru>
> > > > > Date: Thu, 01 May 2025 20:39:02 +0700
> > > > > 
> > > > > After poking around I wrote a patch (attached).
> > > 
> > > Thanks! LGTM. For some reason I can’t apply the patch on either
> > > emacs-30 or master. [1]
> > 
> > Oh, interesting.  I kind of know where the error is coming from,
> > but
> > only partially.  The reason for the error is that the patch I sent
> > was
> > applied over the patch for #78121 (which is pending btw 😊) as I'm
> > using them both for coding.   At the same time, I don't really
> > understand the source of the error as the same parameters work for
> > me:
> > 
> >    ╰─λ git am --3way -- /tmp/1.patch
> >    Applying: typescript-ts: align ternary-chain branches
> > (bug#78187)
> >    Using index info to reconstruct a base tree...
> >    M       lisp/progmodes/typescript-ts-mode.el
> >    M       test/lisp/progmodes/typescript-ts-mode-
> > resources/indent.erts
> >    Falling back to patching base and 3-way merge...
> >    Auto-merging test/lisp/progmodes/typescript-ts-mode-
> > resources/indent.erts
> >    Auto-merging lisp/progmodes/typescript-ts-mode.el
> > 
> > Either way, I redone the patch on top of the tree, please try this
> > one
> 
> Thanks, this works. I applied it on emacs-30. BTW, each entry in the
> commit message needs to be prefixed with “*”. 

Oh, sorry, apparently I forgot it while writing this message.

> Are you using magit? You can just type “C” in the magit diff buffer
> and it’ll insert changelog entries for you into the commit message
> buffer.

I use magit, though just for the highlight. I just tried your
suggestion: invoked emacs with `git commit --amend` for the discussed
commit, switched to the diff buffer and tried pressing "c" and "C".

Lower-case "c" just switches me to "COMMIT_EDITMSG" buffer. Upper-case
"C" pops up an interactive question about cloning from a URL.

I don't know if I'm missing something, but neither seems to insert the
changelog entries.

> > > > > Worth noting though, for
> > > > > some reason it doesn't work for ternary without starting
> > > > > colon,
> > > > > e.g.:
> > > > > 
> > > > >    const a = cond1 ? 1 :
> > > > >      cond2 ? 2 :
> > > > >      cond3 ? 3 : 4;
> > > > > 
> > > > > I'm unclear why, per my understanding the "standalone-parent"
> > > > > of
> > > > > the
> > > > > whole ternary chain (disregarding where the point is) is the
> > > > > `const a
> > > > > =` declaration.
> > > 
> > > The standalone rule just keeps going up the parse tree until it
> > > finds
> > > a node that starts on a new line. In this case, if you start form
> > > cond3, it’ll go up until reaching the teneray_expression node
> > > containing cond2. This node starts on a new line so standalone-
> > > parent
> > > stops here. So the cond3 line uses the cond2 line as the anchor,
> > > instead of the “const a” line. If you add a cond4 line, it’ll use
> > > the
> > > cond3 line as anchor.
> > > 
> > > There’re several ways to fix it. The best way is to add a new
> > > anchor
> > > to the presets that does what standalone-parent does, but
> > > additionally excludes some nodes. Something like (standalone-
> > > parent-
> > > excluding “regexp”). Then this can be used for both typescript
> > > and
> > > c/c++ (and java, etc).
> > 
> > Oh, I see, thank you!
> 
> Unless you intend to work on this (which will be great ;-), I’ll add
> it when I find time.

Hahah, well, it's really the same for me 😊 I might dig into it, but
this depends on my time 😊




This bug report was last modified 12 days ago.

Previous Next


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