Skip to content

haskell-indendation and guards #481

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

Closed
EDmitry opened this issue Feb 25, 2015 · 9 comments
Closed

haskell-indendation and guards #481

EDmitry opened this issue Feb 25, 2015 · 9 comments

Comments

@EDmitry
Copy link

EDmitry commented Feb 25, 2015

Consider the following code:

resolve (amount, max) number 
  | number > max = (1, number)
  | number == max = (amount + 1, number)

If I put the cursor in the end of the last line and hit and then try to use to cycle through all indentation possibilities it would never align with the previous guard. Is this expected or a bug? How does haskell-indentation mode format guards?

@ivan-m
Copy link
Contributor

ivan-m commented Feb 26, 2015

Does C-c C-| (or it might be C-c |; I forget; I haven't used haskell-indentation for quite a while) work for auto-insertion of guards? What is haskell-indent-spaces set to? (It appears that you have the guards indented by two spaces here.)

@EDmitry
Copy link
Author

EDmitry commented Feb 27, 2015

I have this set:

(setq c-default-style "bsd"
      c-basic-offset 4)
(setq-default indent-tabs-mode nil)

but nothing specific to haskell-mode. But shouldn't it indent based on previous guard automatically?

@ivan-m
Copy link
Contributor

ivan-m commented Feb 27, 2015

C-h v haskell-indent-spaces

@EDmitry
Copy link
Author

EDmitry commented Mar 9, 2015

New indentation from wip/hi2 doesn't fix this issue unfortunately:

screen shot 2015-03-09 at 1 40 46 pm

I am still not sure how this is supposed to be working — I am not convinced guards have to be inserted by a hotkey. In theory it should be pretty easy to detect a guard on the previous line and add an indentation stop right under it.

@gracjan
Copy link
Contributor

gracjan commented Mar 10, 2015

Do I understand that the pink rectangle position is offered as indentation point when it should not be?

Or do you want haskell-indentation to insert guards for you? (Auto-inserting was done by haskell-indent).

@EDmitry
Copy link
Author

EDmitry commented Mar 10, 2015

Sorry, the pink rectangle is just my cursor, I should have moved it before taking the screenshot. I was expecting the indentation position (one of) to be right under |.

@gracjan
Copy link
Contributor

gracjan commented Mar 29, 2015

I think I now understand. So if you place the cursor at a line with a guard then it offers proper indentation position. But if you place the cursor on empty line below a line with a guard then it does not offer guard position as an option.

There are a couple of ways to intepret this situation. As far as I understand most of emacs modes for other languages use 'electric' behvior, that is as soon as you insert '|' (guard) it gets indented properly. This could work in this case as there is exactly one available indentation position.

@gracjan
Copy link
Contributor

gracjan commented Oct 18, 2015

If you consider code:

resolve (amount, max) number 
  | number > max = (1, number)
  | number == max = (amount + 1, number)
  |

and now press TAB on line with the singe | in it, then haskell-indentation is properly able to recognize that you have started new guard.

I'll close this specific issue about guards as similar problem appears when continuing lists or records or curly braced constructs. Someday we will be able to tackle this together.

@gracjan gracjan closed this as completed Oct 18, 2015
@PierreR
Copy link
Contributor

PierreR commented Oct 18, 2015

👍 to tackle this as soon as it can be ;-)

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

No branches or pull requests

4 participants