diff --git a/haskell-collapse.el b/haskell-collapse.el index 8a73fa38..2b408d58 100644 --- a/haskell-collapse.el +++ b/haskell-collapse.el @@ -46,6 +46,17 @@ (= (point-at-eol) (progn (skip-chars-forward "[:blank:]") (point))))) +(defun haskell-blank-lines-block (cmp dir indent) + "Return non-nil if sequence of blank lines in direction DIR fits given INDENT level." + (let ((initial-pos (point))) + (when (haskell-blank-line-p) + (while (and (zerop (forward-line dir)) + (haskell-blank-line-p))) + (unless (funcall cmp (current-indentation) indent) + (progn + (goto-char initial-pos) + nil))))) + (defun haskell-indented-block () "return (start-of-indentation . end-of-indentation)" (let ((cur-indent (current-indentation)) @@ -80,7 +91,7 @@ indentation if dir=-1" (let ((start-indent (current-indentation))) (progn (while (and (zerop (forward-line direction)) - (or (haskell-blank-line-p) + (or (haskell-blank-lines-block comparison direction start-indent) (funcall comparison (current-indentation) start-indent)))) (when (= direction 1) (forward-line -1)) (end-of-line) diff --git a/tests/haskell-collapse-tests.el b/tests/haskell-collapse-tests.el index e9e369de..8b2d64c3 100644 --- a/tests/haskell-collapse-tests.el +++ b/tests/haskell-collapse-tests.el @@ -84,7 +84,7 @@ indexCtx posts blogconfig = listField \"posts\" (postCtx blogconfig) (return (t (should (test-haskell-indented-block haskell-code-block-1 1 - (lambda () (test-haskell-collapse-start-end 1 9))))) + (lambda () (test-haskell-collapse-start-end 1 8))))) (ert-deftest test-haskell-indented-block-2 () (should (test-haskell-indented-block @@ -97,7 +97,7 @@ indexCtx posts blogconfig = listField \"posts\" (postCtx blogconfig) (return (t (should (test-haskell-indented-block haskell-code-block-1 2 - (lambda () (test-haskell-collapse-start-end 1 9))))) + (lambda () (test-haskell-collapse-start-end 1 8))))) (ert-deftest test-haskell-indented-block-4 () (should (test-haskell-indented-block @@ -121,4 +121,4 @@ indexCtx posts blogconfig = listField \"posts\" (postCtx blogconfig) (return (t (should (test-haskell-indented-block haskell-code-block-3 0 - (lambda () (test-haskell-collapse-start-end 0 5))))) + (lambda () (test-haskell-collapse-start-end 0 2)))))