Skip to content

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

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
15 changes: 14 additions & 1 deletion haskell-collapse.el
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A quick fix to follow docstring conventions:

Suggested change
"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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use spaces for indents.

t)
(progn
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This progn wrapper is redundant in the else clause of if statements, and it would be more idiomatic to omit it.

(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 +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)
Expand Down