8000 lib/mp-readline: Make it easy to exit auto-indent mode by pressing en… · unixjazz/circuitpython@b7ca945 · GitHub
[go: up one dir, main page]

Skip to content

Commit b7ca945

Browse files
committed
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.
1 parent e6dccaf commit b7ca945

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

docs/reference/repl.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ Finally type ``print(i)``, press RETURN, press BACKSPACE and press RETURN again:
4949
3
5050
>>>
5151

52+
Auto-indent won't be applied if the previous two lines were all spaces. This
53+
means that you can finish entering a compound statment by pressing RETURN
54+
twice, and then a third press will finish and execute.
55+
5256
Auto-completion
5357
---------------
5458

lib/mp-readline/readline.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,18 @@ STATIC void readline_auto_indent(void) {
370370
}
371371
}
372372
// i=start of line; j=first non-space
373+
if (i > 0 && j + 1 == line->len) {
374+
// previous line is not first line and is all spaces
375+
for (size_t k = i - 1; k > 0; --k) {
376+
if (line->buf[k - 1] == '\n') {
377+
// don't auto-indent if last 2 lines are all spaces
378+
return;
379+
} else if (line->buf[k - 1] != ' ') {
380+
// 2nd previous line is not all spaces
381+
break;
382+
}
383+
}
384+
}
373385
int n = (j - i) / 4;
374386
if (line->buf[line->len - 2] == ':') {
375387
n += 1;

0 commit comments

Comments
 (0)
0