diff options
author | Damien George <damien.p.george@gmail.com> | 2015-11-04 12:29:33 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-11-07 13:07:43 +0000 |
commit | b7ca9458773ee18c0b0bb4de55b670e06b70ecc5 (patch) | |
tree | 8ed32290b8f9af20c027d800e2ddb63878d18421 /lib/mp-readline/readline.c | |
parent | e6dccaf18eaaf7aeb80c51c796c2d2036ff49b6b (diff) | |
download | micropython-b7ca9458773ee18c0b0bb4de55b670e06b70ecc5.tar.gz micropython-b7ca9458773ee18c0b0bb4de55b670e06b70ecc5.zip |
lib/mp-readline: Make it easy to exit auto-indent mode by pressing enter.
This patch allows you to stop auto-indent by pressing enter on a second
blank line. Easier than having to use backspace, and prevents new users
from getting stuck in auto-indent mode.
Diffstat (limited to 'lib/mp-readline/readline.c')
-rw-r--r-- | lib/mp-readline/readline.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/mp-readline/readline.c b/lib/mp-readline/readline.c index b7c64aec3c..cbb99cc94c 100644 --- a/lib/mp-readline/readline.c +++ b/lib/mp-readline/readline.c @@ -370,6 +370,18 @@ STATIC void readline_auto_indent(void) { } } // i=start of line; j=first non-space + if (i > 0 && j + 1 == line->len) { + // previous line is not first line and is all spaces + for (size_t k = i - 1; k > 0; --k) { + if (line->buf[k - 1] == '\n') { + // don't auto-indent if last 2 lines are all spaces + return; + } else if (line->buf[k - 1] != ' ') { + // 2nd previous line is not all spaces + break; + } + } + } int n = (j - i) / 4; if (line->buf[line->len - 2] == ':') { n += 1; |