diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-11-13 23:55:08 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-11-13 23:55:08 -0800 |
commit | 711d764b376670e32e6099800a148e8327379c99 (patch) | |
tree | e369defc1b4ac7869297c2805db007eb7d1aa656 /src/kilo.c | |
parent | 812b930815102eacd34a6f8a84ec790986a67e60 (diff) | |
download | teliva-711d764b376670e32e6099800a148e8327379c99.tar.gz |
jump to word at cursor by default
Diffstat (limited to 'src/kilo.c')
-rw-r--r-- | src/kilo.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/kilo.c b/src/kilo.c index 257261a..74f307d 100644 --- a/src/kilo.c +++ b/src/kilo.c @@ -929,6 +929,31 @@ static void editorMoveCursor(int key) { } } +int identifier_char(char c) { + /* keep sync'd with llex */ + return isalnum(c) || c == '_'; +} + +void word_at_cursor(char* out, int capacity) { + erow* row = &E.row[E.rowoff + E.cy]; + int cidx = E.coloff + E.cx; + int len = 0; + memset(out, 0, capacity); + /* scan back */ + while (cidx > 0) { + --cidx; + if (!identifier_char(row->chars[cidx])) + break; + } + /* now scan forward */ + for (len = 0; cidx+len < row->size; ++len) { + if (!identifier_char(row->chars[cidx+len])) + break; + } + if (len < capacity) + strncpy(out, &row->chars[cidx], len); +} + extern void save_to_current_definition_and_editor_buffer(lua_State *L, char *name); extern void load_editor_buffer_to_current_definition_in_image(lua_State *L); extern void editorRefreshBuffer(void); @@ -940,6 +965,9 @@ static void editorGo(lua_State* L) { editorSaveToDisk(); load_editor_buffer_to_current_definition_in_image(L); + word_at_cursor(query, CURRENT_DEFINITION_LEN); + qlen = strlen(query); + while(1) { editorSetStatusMessage("Jump to: %s", query); editorRefreshScreen(); |