iquiw / hyai

Haskell Yet Another Indentation
3 stars 2 forks source link

Improve record indentation #15

Closed luntain closed 6 years ago

luntain commented 6 years ago

When I define a record data type or value of a record data type per the style guide, I would like the cursor to be under the previous comma/opening brace.

Instead, this mode places the cursor under the first character of the type or value assigned to a field. I see that this behavior is tested for:

    Given the buffer is empty
    When I insert:
    """
    person = Person
        { firstName = "John"
    """
    And I call hyai-indent-candidates at the current point
    Then indent candidates are "(18)"

    Given the buffer is empty
    When I insert:
    """
    person = Person
        { firstName = "John"
        , lastName = "Smith"
    """
    And I call hyai-indent-candidates at the current point
    Then indent candidates are "(17)"

How about:

    Given the buffer is empty
    When I insert:
    """
    person = Person
        { firstName = "John"
    """
    And I call hyai-indent-candidates at the current point
    Then indent candidates are "(4 18)"

    Given the buffer is empty
    When I insert:
    """
    person = Person
        { firstName = "John"
        , lastName = "Smith"
    """
    And I call hyai-indent-candidates at the current point
    Then indent candidates are "(4 17)"
iquiw commented 6 years ago

In this case, if , or } is entered in the next line, the indent will be 4. Isn't is sufficient?

luntain commented 6 years ago

That would be sufficient. Is it what happens now? I don't see that behavior in my setup.

iquiw commented 6 years ago

It isn't automatically done, TAB is required.

It may be possible to achieve automatic indent by electric-indent-mode. But haskell-mode disables it now for some reason, so it may cause unexpected behavior.

Below is untested code.

(add-hook 'haskell-mode-hook
  (lambda ()
    (setq electric-indent-inhibit nil)
    (setq electric-indent-chars '(?, ?\})))
luntain commented 6 years ago

I didn't press TAB. That helps.