haskell-mode icon indicating copy to clipboard operation
haskell-mode copied to clipboard

haskell-cabal: bad indentation with redundant leading comma

Open Commelina opened this issue 2 years ago • 5 comments

As the Cabal document says, Cabal allows redundant leading (and trailing) commas since 2.2. And some tools such as cabal-fmt use leading commas by default. However, the indentation of such leading commas does not work very well. For example,

build-depends:
        , bar
, foo

When indenting the last line, we may expect

build-depends:
        , bar
        , foo

However, haskell-cabal-indent-line gives

build-depends:
        , bar
      , foo

This is a little annoying. I am not sure if this is caused by my incorrect usage. However, I tried checking if there was a leading comma before indenting and taking different indent strategies, which worked as expected. (Of course, there are still corner cases such as multiple blank lines. But the origin code does not handle them very well either...) I will make a PR if it is OK.

Commelina avatar Oct 01 '23 20:10 Commelina

Me too.

andreasabel avatar Feb 26 '25 07:02 andreasabel

I attempted to fix the indentation for subsections with leading commas or multiple newlines. It should work as expected on the cases:

  build-depends:
         , base
         , text
  build-depends:


       base
     , text 

Do you have any idea? @andreasabel

Commelina avatar Feb 26 '25 14:02 Commelina

This looks good.

Do you have any idea? @andreasabel

What kind of input do you want from me? (Sorry, I fail to comprehend your question.)

andreasabel avatar Mar 01 '25 08:03 andreasabel

Uh, I was just saying if the patch works for you. Sorry for my ambiguity!

Commelina avatar Mar 01 '25 08:03 Commelina

I am currently using the haskell-mode from MELPA so I cannot easily test a PR.

andreasabel avatar Mar 01 '25 12:03 andreasabel