haskell-mode icon indicating copy to clipboard operation
haskell-mode copied to clipboard

Make region indentation move work by offsets

Open gracjan opened this issue 10 years ago • 3 comments

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:

  • [ ] make it move by haskell-indentation-layout-offset
  • [ ] write some unit test cases
  • [ ] write documentation about this in haskell-mode.texi
  • [ ] make a pull request against ghc-mod that removes this file https://github.com/kazu-yamamoto/ghc-mod/blob/master/elisp/ghc-indent.el

gracjan avatar Oct 18 '15 09:10 gracjan

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 avatar Sep 29 '19 19:09 codygman

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 avatar Sep 29 '19 19:09 codygman

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.

codygman avatar Sep 29 '19 19:09 codygman