jcollard / elm-mode

Elm mode for emacs
GNU General Public License v3.0
373 stars 67 forks source link

Use haskell-mode paragraph detection rules. #164

Closed jsoo1 closed 4 years ago

jsoo1 commented 4 years ago

Closes #163

I'm wondering if it's worth using anything other than default for paragraph-separate It's a little counter-intuitive to navigate through a doc-comment and then the defun as two separate paragraphs.

This also leaves the following problem. If the point is in the indicated position, (forward-paragraph) doesn't continue past the comment closing:

module Example exposing (f, g, h)

f : String -> String -> String
f x y =
    x ++ y

<-- point here
{-| A doc comment
-} <-- (forward-paragraph) goes before the -} 
g : String -> String -> List String
g x y =
    [ y, x ]

h : Int -> Int -> Int
h x y =
    x + y

That means that dap will delete the comment close in addition to g.

I'm not sure being able to fill-paragraph a doc comment is really worth it. But the current PR does preserve the fill-paragraph behavior as before.

The PR also fixes the paragraph detection in a buffer with trailing whitespace.

purcell commented 4 years ago

I see that haskell-mode actually uses these settings:

  (setq-local paragraph-start (concat " *{-\\| *-- |\\|" page-delimiter))
  (setq-local paragraph-separate (concat " *$\\| *\\({-\\|-}\\) *$\\|" page-delimiter))

Perhaps you'd like to try those out locally, because I feel like they should work well for Elm too. Note that haskell-mode also has a custom fill-paragraph-function to smartly fill inside comments, which we could also borrow if helpful.

jsoo1 commented 4 years ago

Ok I will try it out.

I find it a bit awkward when editing Haskell since skipping language pragmas often means moving forward many "paragraphs". That said I think the paragraph settings can be a local configuration for me and other evil users. Treating multiline comments as paragraphs seems like the right choice in general. Also it seems like a nicer experience in elm since there will be no language pragmas.

I don’t have any strong feelings on using haskell’s specialized fill-paragraph rules. I can add them if you want but seems better to leave them out until really necessary.

jsoo1 commented 4 years ago

I also noticed they inhibit electric indent. Maybe that would be something worth thinking about for elm too?

purcell commented 4 years ago

I don’t have any strong feelings on using haskell’s specialized fill-paragraph rules. I can add them if you want but seems better to leave them out until really necessary.

Agree, leave it out for now.

I also noticed they inhibit electric indent.

Yes, I think I added that myself: I'm pretty much the only active haskell-mode maintainer at the moment too. :-)

Maybe that would be something worth thinking about for elm too?

Not sure, but possibly. I think I'd probably want an example of why it was necessary, though. Elm doesn't have the same type of indentation-driven layout rules as Haskell.

jsoo1 commented 4 years ago
  (setq-local paragraph-start (concat " *{-\\| *-- |\\|" page-delimiter))
  (setq-local paragraph-separate (concat " *$\\| *\\({-\\|-}\\) *$\\|" page-delimiter))

Works nicely. dap deletes the whole comment.

I also noticed they inhibit electric indent.

Yes, I think I added that myself: I'm pretty much the only active haskell-mode maintainer at the moment too. :-)

Maybe that would be something worth thinking about for elm too?

Not sure, but possibly. I think I'd probably want an example of why it was necessary, though. Elm doesn't have the same type of indentation-driven layout rules as Haskell.

Ok I will not do anything with electric indent.

jsoo1 commented 4 years ago

Also

Yes, I think I added that myself: I'm pretty much the only active haskell-mode maintainer at the moment too. :-)

Thank you so much. I really appreciate all your work.

purcell commented 4 years ago

Awesome, thanks for fixing this up. :-)