Skip to content

Commit 01bd442

Browse files
committed
infer and retain indent level
1 parent 1dcf7b1 commit 01bd442

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

TODO

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ string-literal
1919
- Also I could ignore non-indented leading lines, e.g.
2020
variable =
2121
"blah blah"
22-
- configurable indentation
22+
* configurable indentation
23+
. I retain existing indentation.
2324
vim:
2425
- vim config uses variable for --wrapped
2526
- What about variable indentation?

src/StringLiteral.hs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ process (wrapped, op, kind) = case (wrapped, op, kind) of
8484
(False, Just Add, Lines) -> addLines
8585
(False, Just Remove, Lines) -> removeLines
8686

87-
indentation :: Text
88-
indentation = " "
89-
9087
-- * backslashes
9188

9289
inferBackslashed :: [Text] -> Bool
@@ -205,14 +202,11 @@ span2 f xs = (pre, in2, post)
205202

206203
-- | Operate on indented text as if it weren't indented.
207204
focusIndented :: ([Text] -> [Text]) -> [Text] -> [Text]
208-
focusIndented f = indent . f . dedent
209-
210-
indent :: [Text] -> [Text]
211-
indent = map (\s -> if Text.null s then "" else indentation <> s)
212-
213-
dedent :: [Text] -> [Text]
214-
dedent lines = map (Text.drop indentation) lines
205+
focusIndented f lines = map indent . f . map (Text.drop indentation) $ lines
215206
where
207+
indent line
208+
| Text.null line = ""
209+
| otherwise = Text.replicate indentation " " <> line
216210
indentation
217211
| null lines = 0
218212
| otherwise = minimum $

src/StringLiteral_test.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ run = Tasty.defaultMain
2323

2424
test_focusIndented :: Tasty.TestTree
2525
test_focusIndented = Tasty.testGroup "focusIndented"
26-
[ ["x"] ==> [" !x"]
27-
, [" x"] ==> [" !x"]
26+
[ ["x"] ==> ["!x"]
27+
, [" x"] ==> [" !x"]
2828
, [" x", " y"] ==> [" !x", " ! y"]
2929
]
3030
where

0 commit comments

Comments
 (0)