Skip to content

Update haskell-indentation-indent-line #1175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions haskell-indentation.el
Original file line number Diff line number Diff line change
Expand Up @@ -243,24 +243,40 @@ indentation points to the right, we switch going to the left."
;; try to repeat
(when (not (haskell-indentation-indent-line-repeat))
(setq haskell-indentation-dyn-last-direction nil)
;; parse error is intentionally not cought here, it may come from
;; parse error is intentionally not caught here, it may come from
;; `haskell-indentation-find-indentations', but escapes the scope
;; and aborts the opertaion before any moving happens
;; and aborts the operation before any moving happens
(let* ((cc (current-column))
(ci (haskell-indentation-current-indentation))
(inds (save-excursion
(move-to-column ci)
(or (haskell-indentation-find-indentations)
'(0))))
(valid (memq ci inds))
(cursor-in-whitespace (< cc ci)))

(cursor-in-whitespace (< cc ci))
;; certain evil commands need the behaviour seen in
;; `haskell-indentation-newline-and-indent'
(evil-special-command (and (bound-and-true-p evil-mode)
(memq this-command '(evil-open-above
evil-open-below
evil-replace))))
(on-last-indent (eq ci (car (last inds)))))
(if (and valid cursor-in-whitespace)
(move-to-column ci)
(haskell-indentation-reindent-to
(haskell-indentation-next-indentation ci inds 'nofail)
(funcall
(if on-last-indent
#'haskell-indentation-previous-indentation
#'haskell-indentation-next-indentation)
(if evil-special-command
(save-excursion
(end-of-line 0)
(1- (haskell-indentation-current-indentation)))
ci)
inds
'nofail)
cursor-in-whitespace))
(setq haskell-indentation-dyn-last-direction 'right
(setq haskell-indentation-dyn-last-direction (if on-last-indent 'left 'right)
haskell-indentation-dyn-last-indentations inds))))

(defun haskell-indentation-indent-line-repeat ()
Expand Down
43 changes: 43 additions & 0 deletions tests/haskell-indentation-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -946,4 +946,47 @@ data Foo = Bar
(execute-kbd-macro (kbd "M-j"))
(should (equal 3 (- (point) (line-beginning-position))))))

(ert-deftest haskell-indentation-cycle ()
"Test if the indentation cycles properly."
(with-temp-buffer
(haskell-mode)
(insert "
test = test' []
where
test' = test''
where
test'' :: [a] -> [a]
test'' = something")
(let* ((inds (save-excursion
(move-to-column (haskell-indentation-current-indentation))
(haskell-indentation-find-indentations)))
(count (1- (length inds)))
(current count))
(should (eq count 3))
(setq current 2) ; will be at third position
;; do first indent as normal
(haskell-indentation-indent-line)
(should (eq (haskell-indentation-current-indentation)
(nth current inds)))
;; indent until the max indent position
;; behave as if re-indenting
(while (< current count)
(cl-incf current)
(let ((last-command 'indent-for-tab-command))
(haskell-indentation-indent-line))
(should (eq (haskell-indentation-current-indentation)
(nth current inds))))
;; start to indent backwards
(cl-decf current)
(haskell-indentation-indent-line)
(should (eq (haskell-indentation-current-indentation)
(nth current inds)))
;; indent back the rest of the way
(while (> current 0)
(cl-decf current)
(let ((last-command 'indent-for-tab-command))
(haskell-indentation-indent-line))
(should (eq (haskell-indentation-current-indentation)
(nth current inds)))))))

;;; haskell-indentation-tests.el ends here