Skip to content

haskell-cabal-subsection-arrange-lines should take in account comments #1097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
geraldus opened this issue Jan 21, 2016 · 4 comments
Open

Comments

@geraldus
Copy link
Contributor

This is a tricky case I want to discuss. Consider following dependencies list of scaffolded Yesod application with three extra dependencies I've added manually at the end:

    build-depends: base                          >= 4          && < 5
                 , yesod                         >= 1.4.1      && < 1.5
                 …
                 , classy-prelude                >= 0.10.2
                 …
                 , template-haskell
                 …
                 , unordered-containers
                 , containers
                 , vector
                 , time
                 -- extra
                 , lambdacms-core
                 , blaze-html
                 , wai

Now if I run haskell-cabal-subsection-arrange-lines it becomes:

    build-depends: aeson                         >= 0.6        && < 0.10
                 , base                          >= 4          && < 5
                 …
                 , yesod-static                  >= 1.4.0.3    && < 1.6
                 -- extra
                 , lambdacms-core
                 , blaze-html
                 , wai

So, as you can see, everything till comment is rearranged as expected, but lines after comment leaved untouched. It is not matter where the point stands when re-arrange command is executed, the result is the same. In my current case I used comment to split dependency list into sections, but others can place comments for other needs. So, in my current case I expect the second section would be sorted independently of first one leaving comment as section separator (there is an easy way — wrap second section by region and call sort-lines).

Definitely it would be better if haskell-cabal-subsection-arrange-lines to sort whole list, but it's not clear how to deal with comments. I can think of few scenarios:

  • leave current behaviour: sort list until first comment
  • sort everything, move comments at the end of the list
  • sort comment lines with dependencies, there are at least two options:
    • assume comments are related to previous lines
    • assume comments are related to following lines
  • sort whole list by subsecions, where comment are assumed as subsection delimiters

I think all this scenarios could be covered by some optional parameter, defaulting to current behaviour.

What do you think?

@gracjan
Copy link
Contributor

gracjan commented Jan 21, 2016

This is relevant:

haskell/cabal#2681

@gracjan
Copy link
Contributor

gracjan commented Jan 21, 2016

@geraldus: Your example is better formatted like this:

    -- standard dependencies
    build-depends: base                          >= 4          && < 5
                 , yesod                         >= 1.4.1      && < 1.5
                 …
                 , classy-prelude                >= 0.10.2
                 …
                 , template-haskell
                 …
                 , unordered-containers
                 , containers
                 , vector
                 , time

    -- extra dependencies
    build-depends: lambdacms-core
                 , blaze-html
                 , wai

Then C-c C-s can format whole value as is.

@geraldus
Copy link
Contributor Author

@gracjan indeed! I didn't know it is allowed to have several build-depends sections, thanks! Ok, let's discuss "comments as comments" cases in this case.

@bergey
Copy link
Contributor

bergey commented Jan 21, 2016

My preference would be:

  • comments starting a line are section separators
  • comments after other text are kept with that line

I think that captures the styles I see most often. But obviously we can't support all possible styles, so I'm fine with whatever you decide to implement. If you decide not to treat comments as section separators, I have a slight preference for comments describing the following line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants