Skip to content
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

Handle block of blank lines for code folding properly (fixes #1707). #1756

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 12 additions & 1 deletion haskell-collapse.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tests/haskell-collapse-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)))))