diff options
-rw-r--r-- | autocomplete.c | 4 | ||||
-rw-r--r-- | buffer.c | 10 | ||||
-rw-r--r-- | config.c | 1 | ||||
-rw-r--r-- | main.c | 6 | ||||
-rw-r--r-- | ted.cfg | 2 | ||||
-rw-r--r-- | ted.h | 1 | ||||
-rw-r--r-- | util.c | 15 |
7 files changed, 26 insertions, 13 deletions
diff --git a/autocomplete.c b/autocomplete.c index a71e45a..335a502 100644 --- a/autocomplete.c +++ b/autocomplete.c @@ -128,10 +128,10 @@ static void autocomplete_process_lsp_response(Ted *ted, const LSPResponse *respo bool was_waiting = ac->waiting_for_lsp; ac->waiting_for_lsp = false; if (!ac->open) { - // user hit escape before completions arrived. + // user hit escape or down or something before completions arrived. return; } - // @TODO: check if same buffer is open and if cursor has moved + const LSPRequest *request = &response->request; if (request->type == LSP_REQUEST_COMPLETION) { const LSPResponseCompletion *completion = &response->data.completion; @@ -1206,16 +1206,6 @@ i64 buffer_cursor_move_down(TextBuffer *buffer, i64 by) { return ret; } -// Is this character a "word" character? -// This determines how buffer_pos_move_words (i.e. ctrl+left/right) works -static bool is_word(char32_t c) { - return c > WCHAR_MAX || c == '_' || iswalnum((wint_t)c); -} - -static bool is_space(char32_t c) { - return c > WCHAR_MAX || iswspace((wint_t)c); -} - // move left / right by the specified number of words // returns the number of words successfully moved forward i64 buffer_pos_move_words(TextBuffer *buffer, BufferPos *pos, i64 nwords) { @@ -250,6 +250,7 @@ static OptionBool const options_bool[] = { {"regenerate-tags-if-not-found", &options_zero.regenerate_tags_if_not_found, true}, {"indent-with-spaces", &options_zero.indent_with_spaces, true}, {"trigger-characters", &options_zero.trigger_characters, true}, + {"identifier-trigger-characters", &options_zero.identifier_trigger_characters, true}, }; static OptionU8 const options_u8[] = { {"tab-width", &options_zero.tab_width, 1, 100, true}, @@ -1,7 +1,7 @@ /* @TODO: - fix unicode_utf8_to_utf32 to handle bad UTF-8 (i.e. continuation bytes which aren't actually continuation bytes) -- provide completion context? +- provide completion context + don't flash cursor for triggers with no completions - dont do completion if provides_completion = false - scroll through completions - only show "Loading..." if it's taking some time (prevent flash) @@ -836,6 +836,10 @@ int main(int argc, char **argv) { break; } } + + if (settings->identifier_trigger_characters && is_word(last_char) + && !is_digit(last_char)) + autocomplete_open(ted); } } @@ -31,6 +31,8 @@ build-default-command = make restore-session = on # show autocomplete menu when a trigger character (e.g. '.') is typed (LSP only) trigger-characters = on +# should all identifier characters (e.g. a-z) be treated as trigger characters? +identifier-trigger-characters = off # search depth for files to generate tags for. # if set to 0, tag generation/regeneration will do nothing @@ -184,6 +184,7 @@ typedef struct { bool regenerate_tags_if_not_found; bool indent_with_spaces; bool trigger_characters; + bool identifier_trigger_characters; u8 tab_width; u8 cursor_width; u8 undo_save_time; @@ -7,6 +7,21 @@ #error "Unrecognized operating system." #endif + +// Is this character a "word" character? +static bool is_word(char32_t c) { + return c > WCHAR_MAX || c == '_' || iswalnum((wint_t)c); +} + +static bool is_digit(char32_t c) { + return c < WCHAR_MAX && iswdigit((wint_t)c); +} + +static bool is_space(char32_t c) { + return c < WCHAR_MAX && iswspace((wint_t)c); +} + + static u8 util_popcount(u64 x) { #ifdef __GNUC__ return (u8)__builtin_popcountll(x); |