diff --git a/inim.nim b/inim.nim index 3211047..50dd20f 100644 --- a/inim.nim +++ b/inim.nim @@ -31,9 +31,9 @@ var const NimblePkgVersion {.strdefine.} = "" - # endsWith + TripleQuoteTrigger = "\"\"\"" IndentTriggers = [ - ",", "=", ":", + ",", "=", ":", TripleQuoteTrigger, "var", "let", "const", "type", "import", "object", "RootObj", "enum" ] @@ -97,6 +97,7 @@ var buffer: File noiser = Noise.init() historyFile: string + previously_triple_quoted: bool template outputFg(color: ForegroundColor, bright: bool = false, body: untyped): untyped = @@ -332,7 +333,15 @@ proc hasIndentTrigger*(line: string): bool = if line.len == 0: return for trigger in IndentTriggers: - if line.strip().endsWith(trigger): + let clean_line = line.strip() + # Triple quoted triggers need to not increase the indent further + if line.endsWith(TripleQuoteTrigger): + # Do not indent further + if previously_triple_quoted: + return + previously_triple_quoted = true + return true + elif clean_line.endsWith(trigger): result = true proc doRepl() = @@ -399,7 +408,9 @@ call(cmd) - Execute command cmd in current shell discard # Empty line: exit indent level, otherwise do nothing - if currentExpression.strip() == "" or currentExpression.startsWith("else"): + if currentExpression.strip() == "" or currentExpression.startsWith("else") or (previously_triple_quoted and currentExpression.strip() == TripleQuoteTrigger): + if currentExpression.strip() == TripleQuoteTrigger: + previously_triple_quoted = false if indentLevel > 0: indentLevel -= 1 elif indentLevel == 0: diff --git a/inim.nimble b/inim.nimble index c12e0ea..6207698 100644 --- a/inim.nimble +++ b/inim.nimble @@ -11,7 +11,7 @@ bin = @["inim"] # Dependencies -requires "cligen >= 1.5.22" +requires "cligen >= 1.5.23" requires "noise >= 0.1.4" diff --git a/tests/test.nim b/tests/test.nim index 518dd72..acde357 100644 --- a/tests/test.nim +++ b/tests/test.nim @@ -30,6 +30,7 @@ suite "INim Test Suite": hasIndentTrigger("type") == true hasIndentTrigger("CallbackAction* = enum ") == true hasIndentTrigger("Response* = ref object ") == true + hasIndentTrigger("var s = \"\"\"") == true test "Executes piped code from file": check execCmdEx("cat tests/test_piping_file.nim | bin/inim").output.strip() == """4 @@ -43,4 +44,3 @@ suite "INim Test Suite": test "Verify flags with '--' prefix work": check execCmdEx("""echo 'import threadpool; echo "SUCCESS"' | bin/inim --flag=--threads:on""").output.strip() == "SUCCESS" -