/* Completes name of the environment variables. */ static void complete_envvar(const char str[]) { extern char **environ; char **p = environ; const size_t len = strlen(str); while(*p != NULL) { if(strncmp(*p, str, len) == 0) { char *const equal = strchr(*p, '='); /* Actually equal shouldn't be NULL unless environ content is corrupted. * But the check below won't harm. */ if(equal != NULL) { *equal = '\0'; vle_compl_add_match(*p); *equal = '='; } } p++; } vle_compl_finish_group(); vle_compl_add_last_match(str); }
void complete_colorschemes(const char name[]) { int i; size_t len; int schemes_len; char **schemes; len = strlen(name); schemes = list_color_schemes(&schemes_len); for(i = 0; i < schemes_len; i++) { if(schemes[i][0] != '.' || name[0] == '.') { if(strnoscmp(name, schemes[i], len) == 0) { vle_compl_add_match(schemes[i]); } } } free_string_array(schemes, schemes_len); vle_compl_finish_group(); vle_compl_add_last_match(name); }
static void complete_filetype(const char *str) { const char *filename = get_current_file_name(curr_view); assoc_records_t ft = get_all_programs_for_file(filename); complete_progs(str, ft); free(ft.list); complete_progs(str, get_magic_handlers(filename)); vle_compl_finish_group(); vle_compl_add_last_match(str); }
static void complete_highlight_groups(const char *str) { int i; const size_t len = strlen(str); for(i = 0; i < MAXNUM_COLOR - 2; i++) { if(strncasecmp(str, HI_GROUPS[i], len) == 0) { vle_compl_add_match(HI_GROUPS[i]); } } vle_compl_finish_group(); vle_compl_add_last_match(str); }
/* Performs str completion using items in the list of length list_len. */ static void complete_from_string_list(const char str[], const char *list[], size_t list_len) { int i; const size_t len = strlen(str); for(i = 0; i < list_len; i++) { if(strncmp(str, list[i], len) == 0) { vle_compl_add_match(list[i]); } } vle_compl_finish_group(); vle_compl_add_last_match(str); }
void complete_group_name(const char *str) { struct group* gr; size_t len = strlen(str); setgrent(); while((gr = getgrent()) != NULL) { if(strncmp(gr->gr_name, str, len) == 0) { vle_compl_add_match(gr->gr_name); } } vle_compl_finish_group(); vle_compl_add_last_match(str); }
static void complete_winrun(const char *str) { static const char *VARIANTS[] = { "^", "$", "%", ".", "," }; const size_t len = strlen(str); int i; for(i = 0; i < ARRAY_LEN(VARIANTS); i++) { if(strncmp(str, VARIANTS[i], len) == 0) { vle_compl_add_match(VARIANTS[i]); } } vle_compl_finish_group(); vle_compl_add_last_match(str); }
void complete_user_name(const char *str) { struct passwd* pw; size_t len; len = strlen(str); setpwent(); while((pw = getpwent()) != NULL) { if(strncmp(pw->pw_name, str, len) == 0) { vle_compl_add_match(pw->pw_name); } } vle_compl_finish_group(); vle_compl_add_last_match(str); }
static int complete_args(int id, const char *args, int argc, char **argv, int arg_pos, void *extra_arg) { const char *arg; vle_compl_reset(); vle_compl_add_match("followlinks"); vle_compl_add_match("fastrun"); vle_compl_finish_group(); vle_compl_add_last_match("f"); arg = strrchr(args, ' '); if(arg == NULL) arg = args; else arg++; return arg - args; }
static void complete_help(const char *str) { int i; if(!cfg.use_vim_help) { return; } for(i = 0; tags[i] != NULL; i++) { if(strstr(tags[i], str) != NULL) { vle_compl_add_match(tags[i]); } } vle_compl_finish_group(); vle_compl_add_last_match(str); }
void bmarks_complete(int n, char *tags[], const char str[]) { const size_t len = strlen(str); size_t i; for(i = 0U; i < bmark_count; ++i) { char *tag = bmarks[i].tags, *state = NULL; while((tag = split_and_get(tag, ',', &state)) != NULL) { if(strncmp(tag, str, len) == 0 && !is_in_string_array(tags, n, tag)) { vle_compl_add_match(tag, ""); } } } vle_compl_finish_group(); vle_compl_add_last_match(str); }
static void filename_completion_internal(DIR * dir, const char * dirname, const char * filename, CompletionType type) { struct dirent *d; size_t filename_len = strlen(filename); while((d = readdir(dir)) != NULL) { if(filename[0] == '\0' && d->d_name[0] == '.') continue; if(strnoscmp(d->d_name, filename, filename_len) != 0) continue; if(type == CT_DIRONLY && !is_dirent_targets_dir(d)) continue; else if(type == CT_EXECONLY && !is_dirent_targets_exec(d)) continue; else if(type == CT_DIREXEC && !is_dirent_targets_dir(d) && !is_dirent_targets_exec(d)) continue; if(is_dirent_targets_dir(d) && type != CT_ALL_WOS) { char with_slash[strlen(d->d_name) + 1 + 1]; snprintf(with_slash, sizeof(with_slash), "%s/", d->d_name); vle_compl_add_path_match(with_slash); } else { vle_compl_add_path_match(d->d_name); } } vle_compl_finish_group(); if(type != CT_EXECONLY) { vle_compl_add_last_path_match(filename); } }
/* Composes and draws suggestion box. */ static void display_suggestion_box(const wchar_t input[]) { size_t prefix; /* Don't do this for ESC because it's prefix for other keys. */ if(!should_display_suggestion_box() || wcscmp(input, L"\033") == 0) { return; } /* Fill completion list with suggestions of keys and marks. */ vle_compl_reset(); vle_keys_suggest(input, &process_suggestion, !(cfg.sug.flags & SF_KEYS), (cfg.sug.flags & SF_FOLDSUBKEYS)); /* Completion grouping removes duplicates. Because user-defined keys are * reported first, this has an effect of leaving only them in the resulting * list, which is correct as they have higher priority. */ vle_compl_finish_group(); /* Handle registers suggestions. */ prefix = wcsspn(input, L"0123456789"); if((cfg.sug.flags & SF_REGISTERS) && input[prefix] == L'"' && input[prefix + 1U] == L'\0') { regs_sync_from_shared_memory(); /* No vle_compl_finish_group() after this to prevent sorting and * deduplication. */ regs_suggest(&process_suggestion, cfg.sug.maxregfiles); } if(vle_compl_get_count() != 0) { draw_suggestion_box(); suggestions_are_visible = 1; } }
static int complete_highlight_arg(const char *str) { /* TODO: Refactor this function complete_highlight_arg() */ char *equal = strchr(str, '='); int result = (equal == NULL) ? 0 : (equal - str + 1); size_t len = strlen((equal == NULL) ? str : ++equal); if(equal == NULL) { static const char *args[] = { "cterm", "ctermfg", "ctermbg", }; int i; for(i = 0; i < ARRAY_LEN(args); i++) { if(strncmp(str, args[i], len) == 0) { vle_compl_add_match(args[i]); } } } else { if(strncmp(str, "cterm", equal - str - 1) == 0) { static const char *STYLES[] = { "bold", "underline", "reverse", "inverse", "standout", "none", }; int i; char *comma = strrchr(equal, ','); if(comma != NULL) { result += comma - equal + 1; equal = comma + 1; len = strlen(equal); } for(i = 0; i < ARRAY_LEN(STYLES); i++) { if(strncasecmp(equal, STYLES[i], len) == 0) { vle_compl_add_match(STYLES[i]); } } } else { int i; if(strncasecmp(equal, "default", len) == 0) { vle_compl_add_match("default"); } if(strncasecmp(equal, "none", len) == 0) { vle_compl_add_match("none"); } for(i = 0; i < ARRAY_LEN(XTERM256_COLOR_NAMES); i++) { if(strncasecmp(equal, XTERM256_COLOR_NAMES[i], len) == 0) { vle_compl_add_match(XTERM256_COLOR_NAMES[i]); } } for(i = 0; i < ARRAY_LEN(LIGHT_COLOR_NAMES); i++) { if(strncasecmp(equal, LIGHT_COLOR_NAMES[i], len) == 0) { vle_compl_add_match(LIGHT_COLOR_NAMES[i]); } } } } vle_compl_finish_group(); vle_compl_add_last_match((equal == NULL) ? str : equal); return result; }