haskell-mode
haskell-mode copied to clipboard
haskell-indentation-indent-region and smartparens interact poorly
Calling a smartparens command like sp-raise-sexp or sp-forward-slurp calls indent-region which calls haskell-indentation-indent-region, which indents the region exactly 1 space, which is almost never what is wanted.
I think this is a misfeature in haskell-indentation-indent-region.
Region indentation can be considered unimplemented feature. We do not have that working yet.
Then it would be more useful if region indentation did absolutely nothing.
@rpglover64: Are you able to submit a unit test in tests/haskell-indentation-tests.el that shows the broken behavior?
Not in the style of the file (i.e. not using haskell-indentation-check); AFAICT, haskell-indentation-find-indentations is behaving correctly, and that's what the file is testing.
I personally worked around this by redefining haskell-indentation-indent-region to do nothing.
It is expected that there will be more check styles.
Noted the need of indent-region in #1032. And closing this particular issue because it seems that smartparens has a flag to work around haskell-mode missing feature.
What is the flag that works around this @gracjan?
The flag is in smart parens.
@khanage From my answer to https://github.com/haskell/haskell-mode/issues/1031:
(add-to-list 'sp-no-reindent-after-kill-modes 'haskell-mode)
That works for sp-kill-sexp. It doesn't work (in my quick test) for sp-raise-sexp or sp-forward-slurp. Maybe smartparens should apply sp-no-reindent-after-kill-modes to these functions also; I'm not certain. I think #1032 covers the issue from haskell-mode perspective.
Reopening as this does not seem to be solved good enough with #1032 (i.e. I have bad feelings but no proof yet).
Yes, sp-forward-slurp-sexp usually bound to C-right calls indent-region-function without looking at sp-no-reindent-after-kill-modes and messes up the layout.
smartparens will also interact poorly even if haskell-indent-region is implemented properly. Consider:
foo = (h $ do abc
def
ghi)
And now use sp-splice-sexp M-s-d inside the parentheses:
foo = h $ do abc
def
ghi
Layout is already messed up and even properly implemented haskell-indent-region cannot salvage the meaning of this program.
This may be a fix; works for me: https://gist.github.com/unhammer/edd926fff70af71d1c77ed73461d55a9#file-init-haskell-el-L112-L133