From 20aa23bd62c8209de1b64ddf5dc55f46a32298f7 Mon Sep 17 00:00:00 2001 From: Torimus Date: Wed, 11 Aug 2021 16:58:17 +0200 Subject: [PATCH 1/3] Handle block of blank lines for code folding properly (fixes #1707). --- haskell-collapse.el | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/haskell-collapse.el b/haskell-collapse.el index 8a73fa388..45930c3d9 100644 --- a/haskell-collapse.el +++ b/haskell-collapse.el @@ -46,6 +46,19 @@ (= (point-at-eol) (progn (skip-chars-forward "[:blank:]") (point))))) +(defun haskell-blank-lines-block (cmp dir indent) + "returns `t' if following sequence of blank lines fits specific indentation level" + (let ((initial-pos (point))) + (while (and (zerop (forward-line dir)) + (haskell-blank-line-p))) + (if (funcall cmp (current-indentation) indent) + (progn + (when (= dir 1) (forward-line -1)) + t) + (progn + (goto-char initial-pos) + nil)))) + (defun haskell-indented-block () "return (start-of-indentation . end-of-indentation)" (let ((cur-indent (current-indentation)) @@ -80,7 +93,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) From 046e429c771d2d36b58c8ba47b24a5d8a4d8d90a Mon Sep 17 00:00:00 2001 From: Torimus Date: Thu, 12 Aug 2021 20:14:28 +0200 Subject: [PATCH 2/3] PR #1756 update --- haskell-collapse.el | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/haskell-collapse.el b/haskell-collapse.el index 45930c3d9..2b408d58e 100644 --- a/haskell-collapse.el +++ b/haskell-collapse.el @@ -47,17 +47,15 @@ (progn (skip-chars-forward "[:blank:]") (point))))) (defun haskell-blank-lines-block (cmp dir indent) - "returns `t' if following sequence of blank lines fits specific indentation level" + "Return non-nil if sequence of blank lines in direction DIR fits given INDENT level." (let ((initial-pos (point))) - (while (and (zerop (forward-line dir)) - (haskell-blank-line-p))) - (if (funcall cmp (current-indentation) indent) - (progn - (when (= dir 1) (forward-line -1)) - t) - (progn - (goto-char initial-pos) - nil)))) + (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)" From 0d3e345dae644de2e0d12ccaa98fdad0d6e3a8eb Mon Sep 17 00:00:00 2001 From: Torimus Date: Fri, 13 Aug 2021 14:49:20 +0200 Subject: [PATCH 3/3] PR #1756 updated tests to reflect changed code folding logic, ie. retain block of blank lines followed by same (or lesser) indentation level as the initial one. --- tests/haskell-collapse-tests.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/haskell-collapse-tests.el b/tests/haskell-collapse-tests.el index e9e369de9..8b2d64c33 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)))))