Subject: bug#76908: 31.0.50; Extending c-ts-common-baseline-indent-rule

From: Yuan Fu <[email-masked]>
Date: Tue, 11 Mar 2025 02:52:54 -0700

> On Mar 9, 2025, at 7:55 PM, [email-masked] wrote:
> 
> Hi Yuan.
> 
> I’ve been working on replacing some of the bespoke indentation
> rules in lua-ts-mode with c-ts-common-baseline-indent-rule and ran
> into one spot it didn’t handle.

Glad to hear it’s getting used!

> 
> If the parent (table, args, params) starts with a comment all the
> siblings follow that indentation instead of ignoring the comment
> and falling back to the default indent-offset; e.g.
> 
>  -- currently lua-ts-mode indents like:
>  local my_table = { -- there is a comment here
>      x_offset = 12,
>      y_offset = 30,
>  }
> 
>  -- using c-ts-common-baseline-indent-rule we get:
>  local my_table = { -- there is a comment here
>                     x_offset = 12,
>                     y_offset = 30,
>  }
> 
> And similarly for arguments & parameters:
> 
>  -- current:
>  very_fun(-- do the very fun stuff
>      "This is a string",
>      3.1415926535897932,
>      { x = 1, y = 2 },
>  )
> 
>  -- c-t-c-b-i-r:
>  very_fun(-- do the very fun stuff
>           "This is a string",
>           3.1415926535897932,
>           { x = 123, y = 99 },
>  )
> 
> Is this something it could be extended to do or should I just
> stick with custom rules for this kind of thing?

The first example seems to work fine for me. The second example is indeed a bug, I fixed it.

I tried 

(defvar lua-ts--simple-indent-rules
  `((lua
     c-ts-common-baseline-indent-rule)))

with

(setq-local c-ts-common-indent-offset 'lua-ts-indent-offset)
(setq-local c-ts-common-list-indent-style 'simple)

(BTW you don’t need to set c-ts-common-indent-type-regexp-alist to use the baseline-indent-rule. I forgot to update the comment in Commentary.)

Yuan