|
31 | 31 |
|
32 | 32 | const |
33 | 33 | NimblePkgVersion {.strdefine.} = "" |
34 | | - # endsWith |
| 34 | + TripleQuoteTrigger = "\"\"\"" |
35 | 35 | IndentTriggers = [ |
36 | 36 | ",", "=", ":", |
37 | 37 | "var", "let", "const", "type", "import", |
|
97 | 97 | buffer: File |
98 | 98 | noiser = Noise.init() |
99 | 99 | historyFile: string |
| 100 | + previously_triple_quoted: bool |
100 | 101 |
|
101 | 102 | template outputFg(color: ForegroundColor, bright: bool = false, |
102 | 103 | body: untyped): untyped = |
@@ -332,7 +333,15 @@ proc hasIndentTrigger*(line: string): bool = |
332 | 333 | if line.len == 0: |
333 | 334 | return |
334 | 335 | for trigger in IndentTriggers: |
335 | | - if line.strip().endsWith(trigger): |
| 336 | + let clean_line = line.strip() |
| 337 | + # Triple quoted triggers need to not increase the indent further |
| 338 | + if clean_line.contains(TripleQuoteTrigger): |
| 339 | + # Do not indent further |
| 340 | + if previously_triple_quoted: |
| 341 | + return |
| 342 | + previously_triple_quoted = true |
| 343 | + return true |
| 344 | + elif clean_line.endsWith(trigger): |
336 | 345 | result = true |
337 | 346 |
|
338 | 347 | proc doRepl() = |
@@ -399,7 +408,9 @@ call(cmd) - Execute command cmd in current shell |
399 | 408 | discard |
400 | 409 |
|
401 | 410 | # Empty line: exit indent level, otherwise do nothing |
402 | | - if currentExpression.strip() == "" or currentExpression.startsWith("else"): |
| 411 | + if currentExpression.strip() == "" or currentExpression.startsWith("else") or (previously_triple_quoted and currentExpression.strip() == TripleQuoteTrigger): |
| 412 | + if currentExpression.strip() == TripleQuoteTrigger: |
| 413 | + previously_triple_quoted = false |
403 | 414 | if indentLevel > 0: |
404 | 415 | indentLevel -= 1 |
405 | 416 | elif indentLevel == 0: |
|
0 commit comments