Skip to content

Refactor haskell-simple-indent. #426

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

Merged
merged 1 commit into from
Jan 17, 2015
Merged
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
62 changes: 35 additions & 27 deletions haskell-simple-indent.el
Original file line number Diff line number Diff line change
Expand Up @@ -90,33 +90,41 @@ column, `tab-to-tab-stop' is done instead."
(interactive)
(let* ((start-column (current-column))
(invisible-from nil) ; `nil' means infinity here
(indent
(catch 'haskell-simple-indent-break
(save-excursion
(while (progn (beginning-of-line)
(not (bobp)))
(forward-line -1)
(if (not (looking-at "[ \t]*\n"))
(let ((this-indentation (current-indentation)))
(if (or (not invisible-from)
(< this-indentation invisible-from))
(if (> this-indentation start-column)
(setq invisible-from this-indentation)
(let ((end (line-beginning-position 2)))
(move-to-column start-column)
;; Is start-column inside a tab on this line?
(if (> (current-column) start-column)
(backward-char 1))
(or (looking-at "[ \t]")
(skip-chars-forward "^ \t" end))
(skip-chars-forward " \t" end)
(let ((col (current-column)))
(throw 'haskell-simple-indent-break
(if (or (= (point) end)
(and invisible-from
(> col invisible-from)))
invisible-from
col)))))))))))))
(indent))
(save-excursion
;; Loop stops if there no more lines above this one or when has
;; found a line starting at first column.
(while (and (or (not invisible-from)
(not (zerop invisible-from)))
(zerop (forward-line -1)))
;; Ignore empty lines.
(if (not (looking-at "[ \t]*\n"))
(let ((this-indentation (current-indentation)))
;; Is this line so indented that it cannot have
;; influence on indentation points?
(if (or (not invisible-from)
(< this-indentation invisible-from))
(if (> this-indentation start-column)
(setq invisible-from this-indentation)
(let ((end (line-end-position)))
(move-to-column start-column)
;; Is start-column inside a tab on this line?
(if (> (current-column) start-column)
(backward-char 1))
;; Skip to the end of non-whitespace.
(skip-chars-forward "^ \t" end)
;; Skip over whitespace.
(skip-chars-forward " \t" end)
;; Indentation point found if not at the end of
;; line and if not covered by any line below
;; this one. In that case use invisible-from.
(setq indent (if (or (= (point) end)
(and invisible-from
(> (current-column) invisible-from)))
invisible-from
(current-column)))
;; Signal that solution is found.
(setq invisible-from 0))))))))
(if indent
(let ((opoint (point-marker)))
(indent-line-to indent)
Expand Down