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

Comments aren't taken into account when determining indent level

Open ntc2 opened this issue 8 years ago • 13 comments

(Originally reported against Intero here. All occurrences of "Intero" below mean "haskell-mode").

For example:

foo x = y
  where
  -- Let me tell you about @y@!
    <-- Only TAB stop on this line is two spaces in from "where".

I would like to be able to indent the next line to the same level as the beginning of the comment.

On the other hand, Intero does take non-comment lines into account when determining indent level, so the following is handled correctly:

foo x = z
  where
  y = x
  <-- Here I can TAB to the same indent level as "y".

Probably related: immediately after a where, Intero only supports indenting one level past the where, not indenting to the same level as the where. I thought of this as "Intero has an opinion about how to best indent my code", which is usually fine, since I can usually override Intero by manually indenting the first line (More important, common case: I'm editing an existing code base that aligns the where-clauses to the same level as the where keyword, and of course I don't want to indent all of them just to make Intero happy).

So, a simple fix might be to soften Intero's opinion of best indentation style: make the first TAB stop one more level in (or whatever Intero's opinion is), but make the "aligned with where" choice always be available as the second TAB stop.

ntc2 avatar Jan 17 '17 23:01 ntc2

Shouldn't code on newline following where be indented? The request doesn't look justified - maybe close this?

andreas-roehler avatar May 04 '18 20:05 andreas-roehler

Code following where is not required to be indented. My impression was that haskell-mode intended to support editing code in a variety of syntactically valid formats, not enforce a specific coding standard. Is my impression wrong?

On Fri, May 4, 2018 at 1:05 PM, Andreas Röhler [email protected] wrote:

Shouldn't code on newline following where be indented? The request doesn't look justified - maybe close this?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/haskell/haskell-mode/issues/1473#issuecomment-386718669, or mute the thread https://github.com/notifications/unsubscribe-auth/AABAJQ4QV9g-Zlkdv0ewT33NSAJeh9wWks5tvLSjgaJpZM4LmUJ0 .

ntc2 avatar May 04 '18 20:05 ntc2

@andreas-roehler For example, in GHC source: https://github.com/ghc/ghc/blob/master/ghc/GHCi/UI.hs#L663.

ntc2 avatar May 04 '18 20:05 ntc2

Didn't write on behalf of haskell-mode, just expressed my personal view. There are several indent-enginges around, which indicates the complexity of the task. Increasing that complexity seems not reasonable - just how I see it. Unless there are reasons why that kind of indent seems necessary...

andreas-roehler avatar May 05 '18 15:05 andreas-roehler

@andreas-roehler Thanks for clarifying. The reason for supporting different indenting styles is that different code bases already use different styles: it's unreasonable for me to start working on an existing project and expect the entire code base to be reformatted to be an a style that my editor prefers. In particular, imagine if two people use two different editors that enforce different, incompatible styles: should they not be able to work on the same project?

ntc2 avatar May 07 '18 20:05 ntc2

Is there a known coding style lining up the body of where below the keyword? AFAIK haskell-mode doesn't prevent doing so, just doesn't suggest it. Once lined up that way, the following indent should obey.

andreas-roehler avatar May 08 '18 06:05 andreas-roehler

@andreas-roehler Please re-read the issue description: yes, haskell-mode does already support indenting subsequent definitions at the same position as the previous definition. What it doesn't do is take into account the position of comments. I'm just suggesting that comments determine the indent level the same way that defs do.

ntc2 avatar May 08 '18 17:05 ntc2

Okay, got astray by the lining up, which is much harder to read IMHO. But you are right, if lined up deliberately, Emacs should follow. So it's a bug.

andreas-roehler avatar May 08 '18 18:05 andreas-roehler

Checked in a fix.

andreas-roehler avatar May 08 '18 19:05 andreas-roehler

@andreas-roehler Thanks!

ntc2 avatar May 08 '18 20:05 ntc2

@andreas-roehler Looks like you never submitted a PR for your fix.

ntc2 avatar Jul 03 '18 23:07 ntc2

Thanks for the heads up. Will look for this.

On 04.07.2018 01:22, Nathan Collins wrote:

@andreas-roehler https://github.com/andreas-roehler Looks like you never submitted a PR for your fix.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/haskell/haskell-mode/issues/1473#issuecomment-402319007, or mute the thread https://github.com/notifications/unsubscribe-auth/ABHmk8neFR-dzdcAvkXg-ry0yj17RtrGks5uC_y6gaJpZM4LmUJ0.

andreas-roehler avatar Jul 10 '18 14:07 andreas-roehler

When ckecking the issue, see it's done inside of https://github.com/haskell/haskell-mode/pull/1596/commits

On 04.07.2018 01:22, Nathan Collins wrote:

@andreas-roehler https://github.com/andreas-roehler Looks like you never submitted a PR for your fix.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/haskell/haskell-mode/issues/1473#issuecomment-402319007, or mute the thread https://github.com/notifications/unsubscribe-auth/ABHmk8neFR-dzdcAvkXg-ry0yj17RtrGks5uC_y6gaJpZM4LmUJ0.

andreas-roehler avatar Jul 10 '18 14:07 andreas-roehler