summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-23 13:07:37 -0500
committerpommicket <pommicket@gmail.com>2022-12-23 13:07:37 -0500
commit7bf8860601771be812e72c557fe9681c968bceaf (patch)
tree035f7a767628daf8cdda1160555f39a8cfc698b7
parente4774c14963bf51840bbf940c1181fe7fc7c3046 (diff)
identifier-trigger-characters setting
-rw-r--r--autocomplete.c4
-rw-r--r--buffer.c10
-rw-r--r--config.c1
-rw-r--r--main.c6
-rw-r--r--ted.cfg2
-rw-r--r--ted.h1
-rw-r--r--util.c15
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;
diff --git a/buffer.c b/buffer.c
index 949f19e..6df6c9c 100644
--- a/buffer.c
+++ b/buffer.c
@@ -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) {
diff --git a/config.c b/config.c
index 5f60b05..359f161 100644
--- a/config.c
+++ b/config.c
@@ -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},
diff --git a/main.c b/main.c
index 26195f5..edb8b11 100644
--- a/main.c
+++ b/main.c
@@ -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);
}
}
diff --git a/ted.cfg b/ted.cfg
index 12ff922..4d1d843 100644
--- a/ted.cfg
+++ b/ted.cfg
@@ -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
diff --git a/ted.h b/ted.h
index 547197c..f7d79ae 100644
--- a/ted.h
+++ b/ted.h
@@ -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;
diff --git a/util.c b/util.c
index e973674..32115cf 100644
--- a/util.c
+++ b/util.c
@@ -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);