aboutsummaryrefslogtreecommitdiff
path: root/py/repl.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-05-08 19:31:06 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-05-08 20:40:47 +0300
commitd59c2e5e45389d4d280ccec52f88bc469b15a469 (patch)
tree7c2b63539a9184cbd507cbde4dd73ede59fe5adf /py/repl.c
parent13a1acc7e2d4d7ad9812be8769671b79bdf402dc (diff)
py/repl: If there're no better alternatives, try to complete "import".
Also do that only for the first word in a line. The idea is that when you start up interpreter, high chance that you want to do an import. With this patch, this can be achieved with "i<tab>".
Diffstat (limited to 'py/repl.c')
-rw-r--r--py/repl.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/py/repl.c b/py/repl.c
index 7bd875908..c938a6aa2 100644
--- a/py/repl.c
+++ b/py/repl.c
@@ -126,6 +126,7 @@ bool mp_repl_continue_with_input(const char *input) {
mp_uint_t mp_repl_autocomplete(const char *str, mp_uint_t len, const mp_print_t *print, const char **compl_str) {
// scan backwards to find start of "a.b.c" chain
+ const char *org_str = str;
const char *top = str + len;
for (const char *s = top; --s >= str;) {
if (!(unichar_isalpha(*s) || unichar_isdigit(*s) || *s == '_' || *s == '.')) {
@@ -219,6 +220,16 @@ mp_uint_t mp_repl_autocomplete(const char *str, mp_uint_t len, const mp_print_t
// nothing found
if (n_found == 0) {
+ // If there're no better alternatives, and if it's first word
+ // in the line, try to complete "import".
+ if (s_start == org_str) {
+ static char import_str[] = "import ";
+ if (memcmp(s_start, import_str, s_len) == 0) {
+ *compl_str = import_str + s_len;
+ return sizeof(import_str) - 1 - s_len;
+ }
+ }
+
return 0;
}