Skip to content

Commit 98164b1

Browse files
committed
Merge pull request #426 from gracjan/pr-haskell-simple-indent-refactor
Refactor haskell-simple-indent.
2 parents 5ada77e + 5904679 commit 98164b1

File tree

1 file changed

+35
-27
lines changed

1 file changed

+35
-27
lines changed

haskell-simple-indent.el

+35-27
Original file line numberDiff line numberDiff line change
@@ -90,33 +90,41 @@ column, `tab-to-tab-stop' is done instead."
9090
(interactive)
9191
(let* ((start-column (current-column))
9292
(invisible-from nil) ; `nil' means infinity here
93-
(indent
94-
(catch 'haskell-simple-indent-break
95-
(save-excursion
96-
(while (progn (beginning-of-line)
97-
(not (bobp)))
98-
(forward-line -1)
99-
(if (not (looking-at "[ \t]*\n"))
100-
(let ((this-indentation (current-indentation)))
101-
(if (or (not invisible-from)
102-
(< this-indentation invisible-from))
103-
(if (> this-indentation start-column)
104-
(setq invisible-from this-indentation)
105-
(let ((end (line-beginning-position 2)))
106-
(move-to-column start-column)
107-
;; Is start-column inside a tab on this line?
108-
(if (> (current-column) start-column)
109-
(backward-char 1))
110-
(or (looking-at "[ \t]")
111-
(skip-chars-forward "^ \t" end))
112-
(skip-chars-forward " \t" end)
113-
(let ((col (current-column)))
114-
(throw 'haskell-simple-indent-break
115-
(if (or (= (point) end)
116-
(and invisible-from
117-
(> col invisible-from)))
118-
invisible-from
119-
col)))))))))))))
93+
(indent))
94+
(save-excursion
95+
;; Loop stops if there no more lines above this one or when has
96+
;; found a line starting at first column.
97+
(while (and (or (not invisible-from)
98+
(not (zerop invisible-from)))
99+
(zerop (forward-line -1)))
100+
;; Ignore empty lines.
101+
(if (not (looking-at "[ \t]*\n"))
102+
(let ((this-indentation (current-indentation)))
103+
;; Is this line so indented that it cannot have
104+
;; influence on indentation points?
105+
(if (or (not invisible-from)
106+
(< this-indentation invisible-from))
107+
(if (> this-indentation start-column)
108+
(setq invisible-from this-indentation)
109+
(let ((end (line-end-position)))
110+
(move-to-column start-column)
111+
;; Is start-column inside a tab on this line?
112+
(if (> (current-column) start-column)
113+
(backward-char 1))
114+
;; Skip to the end of non-whitespace.
115+
(skip-chars-forward "^ \t" end)
116+
;; Skip over whitespace.
117+
(skip-chars-forward " \t" end)
118+
;; Indentation point found if not at the end of
119+
;; line and if not covered by any line below
120+
;; this one. In that case use invisible-from.
121+
(setq indent (if (or (= (point) end)
122+
(and invisible-from
123+
(> (current-column) invisible-from)))
124+
invisible-from
125+
(current-column)))
126+
;; Signal that solution is found.
127+
(setq invisible-from 0))))))))
120128
(if indent
121129
(let ((opoint (point-marker)))
122130
(indent-line-to indent)

0 commit comments

Comments
 (0)