haskell / haskell-mode

Emacs mode for Haskell
http://haskell.github.io/haskell-mode/
GNU General Public License v3.0
1.33k stars 343 forks source link

Make region indentation move work by offsets #949

Open gracjan opened 8 years ago

gracjan commented 8 years ago

Currently when region is active and TAB or S-TAB is pressed in haskell-indentation-mode the region is move one space left or right. To do:

codygman commented 4 years ago

Step 1 seems to be from my tests:

(defun haskell-indentation-indent-region (_start _end)
  "This function does nothing.

It is better to do nothing to indent region in Haskell than to
break the semantics of indentation.  This function is used for
`indent-region-function' because the default is to call
`indent-line-function' on every line from START to END and that
also produces catastrophic results.

Someday we will have indent region that preserves semantics and
fixes up only indentation."
  (haskell-indentation-indent-rigidly (region-beginning) (region-end) (* -1 haskell-indentation-layout-offset)))
codygman commented 4 years ago

Oh, silly me that always indents negatively.

Do we have any way of knowing whether to indent forwards or backwards in haskell-indentation-indent-region?

codygman commented 4 years ago

I just realized it might not be clear that I'm triggering haskell-indentation-indent-region from evil mode by higlighting this block:

main = do
  print 1
  -- example of where we want to indent backward to align with print
            case 1 == 1 of
              True -> do
                putStrLn "1 == 1"
                putStrLn "good"

Then I'm calling = which calls evil-indent, which eventually calls haskell-indentation-indent-region. In order for this method to work I would have to know whether to go backwards or forwards in haskell-indentation-indent-region.

I suppose I can just set it to positive like i think this issue aims to do:

(defun haskell-indentation-indent-region (_start _end)
      (haskell-indentation-indent-rigidly (region-beginning) (region-end) haskell-indentation-layout-offset))

Then do a vertical highlight at the beginning of the lines I want to indent, call evil-insert-line with I to go into insert mode at beginning, and then tab cycle normally.

That's not the ideal way, but it works with this implementation I suppose. I think this might be where Haskell-mode in vanilla emacs and Haskell-mode in vim diverge and supporting both complicates the api accordingly.