Skip to content

Indent multiline strings #1035

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 2 commits into from
Dec 25, 2015
Merged
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
57 changes: 33 additions & 24 deletions haskell-indentation.el
Original file line number Diff line number Diff line change
Expand Up @@ -249,29 +249,25 @@ indentation points to the right, we switch going to the left."
;; try to repeat
(when (not (haskell-indentation-indent-line-repeat))
(setq haskell-indentation-dyn-last-direction nil)
;; do nothing if we're inside a string or comment
(unless (save-excursion
(beginning-of-line)
(nth 8 (syntax-ppss)))
;; parse error is intentionally not cought here, it may come from
;; `haskell-indentation-find-indentations', but escapes the scope
;; and aborts the opertaion before any moving happens
(let* ((cc (current-column))
(ci (haskell-indentation-current-indentation))
(inds (save-excursion
(move-to-column ci)
(or (haskell-indentation-find-indentations)
'(0))))
(valid (memq ci inds))
(cursor-in-whitespace (< cc ci)))

(if (and valid cursor-in-whitespace)
(move-to-column ci)
(haskell-indentation-reindent-to
(haskell-indentation-next-indentation ci inds 'nofail)
cursor-in-whitespace))
(setq haskell-indentation-dyn-last-direction 'right
haskell-indentation-dyn-last-indentations inds)))))
;; parse error is intentionally not cought here, it may come from
;; `haskell-indentation-find-indentations', but escapes the scope
;; and aborts the opertaion before any moving happens
(let* ((cc (current-column))
(ci (haskell-indentation-current-indentation))
(inds (save-excursion
(move-to-column ci)
(or (haskell-indentation-find-indentations)
'(0))))
(valid (memq ci inds))
(cursor-in-whitespace (< cc ci)))

(if (and valid cursor-in-whitespace)
(move-to-column ci)
(haskell-indentation-reindent-to
(haskell-indentation-next-indentation ci inds 'nofail)
cursor-in-whitespace))
(setq haskell-indentation-dyn-last-direction 'right
haskell-indentation-dyn-last-indentations inds))))

(defun haskell-indentation-indent-line-repeat ()
"Cycle though indentation positions."
Expand Down Expand Up @@ -453,7 +449,20 @@ indentation points to the right, we switch going to the left."
(let ((ppss (syntax-ppss)))
(cond
((nth 3 ppss)
(haskell-indentation-first-indentation))
(if (save-excursion
(and (forward-line -1)
(< (nth 8 ppss) (point))))
;; if this string goes over more than one line we want to
;; sync with the last line, not the first one
(list (save-excursion
(forward-line -1)
(current-indentation)))

(append
(haskell-indentation-first-indentation)
(list (save-excursion
(goto-char (nth 8 ppss))
(current-column))))))
((nth 4 ppss)
(if (save-excursion
(and (skip-syntax-forward "-")
Expand Down
20 changes: 20 additions & 0 deletions tests/haskell-indentation-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,26 @@ fact n =
(4 0 2 4 6)
(5 0 2 4 6))

(hindent-test "47a multiline strings" "
fact n = \"\\
\\a\""
(1 0)
;; we want to offer both a continuation style and the
;; align to left column style (like in lisp)
(2 0 9)
(3 0 2))

(hindent-test "47b multiline strings" "
fact n = \"\\
\\a\\
\\x\""
;; here we want to keep third line like the second one,
;; although the second one wasn't best indented
(1 0)
(2 0 9)
(3 6))


(defmacro with-temp-switch-to-buffer (&rest body)
"Create a temporary buffer, use `switch-to-buffer' and evaluate BODY there like `progn'.

Expand Down