I frequently comment out code while testing, and elm-format is stripping the line indents. This makes it so I can't uncomment the code later. For example:
-- fieldListItem : AvailableField -> Html
-- fieldListItem af =
-- a
-- [ class "list-group-item narrow" ]
-- [ text af.name ]
Elm format turns it into this:
-- fieldListItem : AvailableField -> Html
-- fieldListItem af =
-- a
-- [ class "list-group-item narrow" ]
-- [ text af.name ]
Which if I then uncomment, turns into this, and throws an error (Elm-format never re-indents it).
fieldListItem : AvailableField -> Html
fieldListItem af =
a
[ class "list-group-item narrow" ]
[ text af.name ]
I see your point, but in this instance wouldn't it make more sense to use multiline comments
{- fieldListItem : AvailableField -> Html
fieldListItem af =
a
[ class "list-group-item narrow" ]
[ text af.name ]
-}
That will keep your indents in order.
I would normally agree with you, but for turning chunks of code on/off during development, line comments are much more convenient. Imagine the example where you have the following three functions:
one : String
one = "one"
two : String
two = "two"
three: String
three = "three"
Now imagine I need to turn off two:
one : String
one = "one"
{-
two : String
two = "two"
-}
three: String
three = "three"
Then I later decide I want to comment out all three:
{-
one : String
one = "one"
{-
two : String
two = "two"
-}
three: String
three = "three"
-}
I haven't tried this in elm, but most languages get really grumpy if you nest multi-line comments. Even if it compiles, I don't really want to double-comment out two. I just want all of them commented out in the same way. I'm using my editor (vim's NERDCommenter) and I'm pretty sure this is a fairly common workflow.
Well, Elm doesn't complain about and supports nested comments, AFAIK... Try
it :)
On Mar 8, 2016 8:39 PM, "Sean Hess" [email protected] wrote:
I would normally agree with you, but for turning chunks of code on/off
during development, line comments are much more convenient. Imagine the
example where you have the following three functions:one : String
one = "one"two : String
two = "two"three: String
three = "three"Now imagine I need to turn off two:
one : String
one = "one"{-
two : String
two = "two"
-}three: String
three = "three"Then I later decide I want to comment out all three:
{-
one : String
one = "one"{-
two : String
two = "two"
-}three: String
three = "three"
-}I haven't tried this in elm, but most languages get really grumpy if you
nest multi-line comments. I'm using my editor (vim's NERDCommenter) and I'm
pretty sure this is a fairly common workflow.—
Reply to this email directly or view it on GitHub
https://github.com/avh4/elm-format/issues/141#issuecomment-193936818.
Objectively, Elm supports nested comments, and the compiler doesn't treat "doubly-commented" code any different from "singly-commented". Subjectively, I think having doubled comments when you're developing is fine (obviously clean it up before committing).
btw my editor (Light Table) would format your block like this when using line comments
-- fieldListItem : AvailableField -> Html
-- fieldListItem af =
-- a
-- [ class "list-group-item narrow" ]
-- [ text af.name ]
which works fine with elm format :-)
My point being I guess, is that I would totally understand why your case wouldn't be a high priority to support.
I think we need to make commenting/uncommented behave nicely for almost everyone.
@seanhess can you give more details about your workflow: Do you typically type/delete the -- yourself? Do you use and editor shortcut or macro to do it faster (if so, which editor, and which shortcut/commands)?
For others, in general, what editors have support for adding/removing -- and {- -} comments? Do you typically use those features? Do you tend to use one type of comment vs the other, or do you use use both depending on the situation?
Thanks @avh4 for the consideration!
I use NERDCommenter on vim. I use the :NERDCommenterToggle command bound to cmd+/. I'm pretty sure it's the most common commenting plugin for vim.
I've used it enough to know that using it with multi-line comments is a huge pain for quickly adding / removing lines. I can give more examples of how I use it to hide things while debugging if needed.
I tried to figure out how to configure it to comment from the beginning of the line, like how @rundis says atom does (which makes more sense to me), but I don't see it. I'm not sure why they do it this way.
I'm switching commenting plugins! Commentary puts comments at the beginning of the line.
I still think stripping comment indentation is overkill / not useful, but I'll leave it to you guys :)
Thanks for your hard work! Elm-format is treating me pretty well.
Another thing I just noticed. If I have two blocks commented out it squishes them together.
-- one = "one"
-- two = "two"
becomes
-- one = "one"
-- two = "two"
Which isn't what I intended. You're trying to get people to keep comments grouped together? Why not add blank comment lines instead? Like this:
-- one = "one"
--
-- two = "two"
The last suggestion is an interesting one-- I'm going to make a separate issue to track it.
The original problem could be solved by having elm-format transform
-- fieldListItem : AvailableField -> Html
-- fieldListItem af =
-- a
-- [ class "list-group-item narrow" ]
-- [ text af.name ]
into
-- fieldListItem : AvailableField -> Html
-- fieldListItem af =
-- a
-- [ class "list-group-item narrow" ]
-- [ text af.name ]
That way comments can be formatted nicely while still preserving the indentation of any commented out code. Thoughts?
Most helpful comment
The original problem could be solved by having elm-format transform
into
That way comments can be formatted nicely while still preserving the indentation of any commented out code. Thoughts?