Skip to content

Commit 38c4231

Browse files
committed
Merge pull request #1035 from gracjan/pr-indent-multiline-strings
Indent multiline strings
2 parents 212eb89 + fd72772 commit 38c4231

File tree

2 files changed

+53
-24
lines changed

2 files changed

+53
-24
lines changed

haskell-indentation.el

+33-24
Original file line numberDiff line numberDiff line change
@@ -249,29 +249,25 @@ indentation points to the right, we switch going to the left."
249249
;; try to repeat
250250
(when (not (haskell-indentation-indent-line-repeat))
251251
(setq haskell-indentation-dyn-last-direction nil)
252-
;; do nothing if we're inside a string or comment
253-
(unless (save-excursion
254-
(beginning-of-line)
255-
(nth 8 (syntax-ppss)))
256-
;; parse error is intentionally not cought here, it may come from
257-
;; `haskell-indentation-find-indentations', but escapes the scope
258-
;; and aborts the opertaion before any moving happens
259-
(let* ((cc (current-column))
260-
(ci (haskell-indentation-current-indentation))
261-
(inds (save-excursion
262-
(move-to-column ci)
263-
(or (haskell-indentation-find-indentations)
264-
'(0))))
265-
(valid (memq ci inds))
266-
(cursor-in-whitespace (< cc ci)))
267-
268-
(if (and valid cursor-in-whitespace)
269-
(move-to-column ci)
270-
(haskell-indentation-reindent-to
271-
(haskell-indentation-next-indentation ci inds 'nofail)
272-
cursor-in-whitespace))
273-
(setq haskell-indentation-dyn-last-direction 'right
274-
haskell-indentation-dyn-last-indentations inds)))))
252+
;; parse error is intentionally not cought here, it may come from
253+
;; `haskell-indentation-find-indentations', but escapes the scope
254+
;; and aborts the opertaion before any moving happens
255+
(let* ((cc (current-column))
256+
(ci (haskell-indentation-current-indentation))
257+
(inds (save-excursion
258+
(move-to-column ci)
259+
(or (haskell-indentation-find-indentations)
260+
'(0))))
261+
(valid (memq ci inds))
262+
(cursor-in-whitespace (< cc ci)))
263+
264+
(if (and valid cursor-in-whitespace)
265+
(move-to-column ci)
266+
(haskell-indentation-reindent-to
267+
(haskell-indentation-next-indentation ci inds 'nofail)
268+
cursor-in-whitespace))
269+
(setq haskell-indentation-dyn-last-direction 'right
270+
haskell-indentation-dyn-last-indentations inds))))
275271

276272
(defun haskell-indentation-indent-line-repeat ()
277273
"Cycle though indentation positions."
@@ -453,7 +449,20 @@ indentation points to the right, we switch going to the left."
453449
(let ((ppss (syntax-ppss)))
454450
(cond
455451
((nth 3 ppss)
456-
(haskell-indentation-first-indentation))
452+
(if (save-excursion
453+
(and (forward-line -1)
454+
(< (nth 8 ppss) (point))))
455+
;; if this string goes over more than one line we want to
456+
;; sync with the last line, not the first one
457+
(list (save-excursion
458+
(forward-line -1)
459+
(current-indentation)))
460+
461+
(append
462+
(haskell-indentation-first-indentation)
463+
(list (save-excursion
464+
(goto-char (nth 8 ppss))
465+
(current-column))))))
457466
((nth 4 ppss)
458467
(if (save-excursion
459468
(and (skip-syntax-forward "-")

tests/haskell-indentation-tests.el

+20
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,26 @@ fact n =
850850
(4 0 2 4 6)
851851
(5 0 2 4 6))
852852

853+
(hindent-test "47a multiline strings" "
854+
fact n = \"\\
855+
\\a\""
856+
(1 0)
857+
;; we want to offer both a continuation style and the
858+
;; align to left column style (like in lisp)
859+
(2 0 9)
860+
(3 0 2))
861+
862+
(hindent-test "47b multiline strings" "
863+
fact n = \"\\
864+
\\a\\
865+
\\x\""
866+
;; here we want to keep third line like the second one,
867+
;; although the second one wasn't best indented
868+
(1 0)
869+
(2 0 9)
870+
(3 6))
871+
872+
853873
(defmacro with-temp-switch-to-buffer (&rest body)
854874
"Create a temporary buffer, use `switch-to-buffer' and evaluate BODY there like `progn'.
855875

0 commit comments

Comments
 (0)