Skip to content

Commit d478da6

Browse files
author
Ryan Cotter
committed
Added for for triple quote indentation
Upgraded pinned cligen version
1 parent 1426527 commit d478da6

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

inim.nim

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var
3131

3232
const
3333
NimblePkgVersion {.strdefine.} = ""
34-
# endsWith
34+
TripleQuoteTrigger = "\"\"\""
3535
IndentTriggers = [
3636
",", "=", ":",
3737
"var", "let", "const", "type", "import",
@@ -97,6 +97,7 @@ var
9797
buffer: File
9898
noiser = Noise.init()
9999
historyFile: string
100+
previously_triple_quoted: bool
100101

101102
template outputFg(color: ForegroundColor, bright: bool = false,
102103
body: untyped): untyped =
@@ -332,7 +333,15 @@ proc hasIndentTrigger*(line: string): bool =
332333
if line.len == 0:
333334
return
334335
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):
336345
result = true
337346

338347
proc doRepl() =
@@ -399,7 +408,9 @@ call(cmd) - Execute command cmd in current shell
399408
discard
400409

401410
# 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
403414
if indentLevel > 0:
404415
indentLevel -= 1
405416
elif indentLevel == 0:

inim.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ bin = @["inim"]
1111

1212
# Dependencies
1313

14-
requires "cligen >= 1.5.22"
14+
requires "cligen >= 1.5.23"
1515

1616
requires "noise >= 0.1.4"
1717

tests/test.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ suite "INim Test Suite":
3030
hasIndentTrigger("type") == true
3131
hasIndentTrigger("CallbackAction* = enum ") == true
3232
hasIndentTrigger("Response* = ref object ") == true
33+
hasIndentTrigger("var s = \"\"\"") == true
3334

3435
test "Executes piped code from file":
3536
check execCmdEx("cat tests/test_piping_file.nim | bin/inim").output.strip() == """4
@@ -43,4 +44,3 @@ suite "INim Test Suite":
4344

4445
test "Verify flags with '--' prefix work":
4546
check execCmdEx("""echo 'import threadpool; echo "SUCCESS"' | bin/inim --flag=--threads:on""").output.strip() == "SUCCESS"
46-

0 commit comments

Comments
 (0)