aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/insexpand.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/insexpand.c')
-rw-r--r--src/nvim/insexpand.c594
1 files changed, 353 insertions, 241 deletions
diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c
index da1063f699..6de3b0a9d0 100644
--- a/src/nvim/insexpand.c
+++ b/src/nvim/insexpand.c
@@ -4,11 +4,16 @@
// insexpand.c: functions for Insert mode completion
#include <assert.h>
-#include <inttypes.h>
+#include <limits.h>
#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "nvim/ascii.h"
+#include "nvim/autocmd.h"
#include "nvim/buffer.h"
#include "nvim/change.h"
#include "nvim/charset.h"
@@ -18,36 +23,48 @@
#include "nvim/edit.h"
#include "nvim/eval.h"
#include "nvim/eval/typval.h"
+#include "nvim/eval/typval_defs.h"
+#include "nvim/eval/userfunc.h"
+#include "nvim/ex_cmds_defs.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_eval.h"
#include "nvim/ex_getln.h"
#include "nvim/fileio.h"
+#include "nvim/garray.h"
#include "nvim/getchar.h"
+#include "nvim/gettext.h"
+#include "nvim/globals.h"
+#include "nvim/highlight_defs.h"
#include "nvim/indent.h"
#include "nvim/indent_c.h"
#include "nvim/insexpand.h"
#include "nvim/keycodes.h"
+#include "nvim/macros.h"
+#include "nvim/mark.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/move.h"
#include "nvim/option.h"
+#include "nvim/os/fs.h"
#include "nvim/os/input.h"
#include "nvim/os/time.h"
#include "nvim/path.h"
#include "nvim/popupmenu.h"
+#include "nvim/pos.h"
#include "nvim/regexp.h"
+#include "nvim/screen.h"
#include "nvim/search.h"
#include "nvim/spell.h"
#include "nvim/state.h"
#include "nvim/strings.h"
#include "nvim/tag.h"
#include "nvim/textformat.h"
+#include "nvim/types.h"
#include "nvim/ui.h"
#include "nvim/undo.h"
#include "nvim/vim.h"
-#include "nvim/window.h"
// Definitions used for CTRL-X submode.
// Note: If you change CTRL-X submode, you must also maintain ctrl_x_msgs[]
@@ -55,30 +72,31 @@
#define CTRL_X_WANT_IDENT 0x100
-#define CTRL_X_NORMAL 0 ///< CTRL-N CTRL-P completion, default
-#define CTRL_X_NOT_DEFINED_YET 1
-#define CTRL_X_SCROLL 2
-#define CTRL_X_WHOLE_LINE 3
-#define CTRL_X_FILES 4
-#define CTRL_X_TAGS (5 + CTRL_X_WANT_IDENT)
-#define CTRL_X_PATH_PATTERNS (6 + CTRL_X_WANT_IDENT)
-#define CTRL_X_PATH_DEFINES (7 + CTRL_X_WANT_IDENT)
-#define CTRL_X_FINISHED 8
-#define CTRL_X_DICTIONARY (9 + CTRL_X_WANT_IDENT)
-#define CTRL_X_THESAURUS (10 + CTRL_X_WANT_IDENT)
-#define CTRL_X_CMDLINE 11
-#define CTRL_X_FUNCTION 12
-#define CTRL_X_OMNI 13
-#define CTRL_X_SPELL 14
-#define CTRL_X_LOCAL_MSG 15 ///< only used in "ctrl_x_msgs"
-#define CTRL_X_EVAL 16 ///< for builtin function complete()
-#define CTRL_X_CMDLINE_CTRL_X 17 ///< CTRL-X typed in CTRL_X_CMDLINE
+enum {
+ CTRL_X_NORMAL = 0, ///< CTRL-N CTRL-P completion, default
+ CTRL_X_NOT_DEFINED_YET = 1,
+ CTRL_X_SCROLL = 2,
+ CTRL_X_WHOLE_LINE = 3,
+ CTRL_X_FILES = 4,
+ CTRL_X_TAGS = (5 + CTRL_X_WANT_IDENT),
+ CTRL_X_PATH_PATTERNS = (6 + CTRL_X_WANT_IDENT),
+ CTRL_X_PATH_DEFINES = (7 + CTRL_X_WANT_IDENT),
+ CTRL_X_FINISHED = 8,
+ CTRL_X_DICTIONARY = (9 + CTRL_X_WANT_IDENT),
+ CTRL_X_THESAURUS = (10 + CTRL_X_WANT_IDENT),
+ CTRL_X_CMDLINE = 11,
+ CTRL_X_FUNCTION = 12,
+ CTRL_X_OMNI = 13,
+ CTRL_X_SPELL = 14,
+ CTRL_X_LOCAL_MSG = 15, ///< only used in "ctrl_x_msgs"
+ CTRL_X_EVAL = 16, ///< for builtin function complete()
+ CTRL_X_CMDLINE_CTRL_X = 17, ///< CTRL-X typed in CTRL_X_CMDLINE
+};
#define CTRL_X_MSG(i) ctrl_x_msgs[(i) & ~CTRL_X_WANT_IDENT]
/// Message for CTRL-X mode, index is ctrl_x_mode.
-static char *ctrl_x_msgs[] =
-{
+static char *ctrl_x_msgs[] = {
N_(" Keyword completion (^N^P)"), // CTRL_X_NORMAL, ^P/^N compl.
N_(" ^X mode (^]^D^E^F^I^K^L^N^O^Ps^U^V^Y)"),
NULL, // CTRL_X_SCROLL: depends on state
@@ -152,7 +170,7 @@ typedef struct {
pos_T first_match_pos; ///< first match position
pos_T last_match_pos; ///< last match position
bool found_all; ///< found all matches of a certain type.
- char_u *dict; ///< dictionary file to search
+ char *dict; ///< dictionary file to search
int dict_f; ///< "dict" is an exact file name or not
} ins_compl_next_state_T;
@@ -215,11 +233,11 @@ static bool compl_interrupted = false;
static bool compl_restarting = false; ///< don't insert match
-///< When the first completion is done "compl_started" is set. When it's
-///< false the word to be completed must be located.
+/// When the first completion is done "compl_started" is set. When it's
+/// false the word to be completed must be located.
static bool compl_started = false;
-///< Which Ctrl-X mode are we in?
+/// Which Ctrl-X mode are we in?
static int ctrl_x_mode = CTRL_X_NORMAL;
static int compl_matches = 0; ///< number of completion matches
@@ -240,7 +258,6 @@ static expand_T compl_xp;
// List of flags for method of completion.
static int compl_cont_status = 0;
-
#define CONT_ADDING 1 ///< "normal" or "adding" expansion
#define CONT_INTRPT (2 + 4) ///< a ^X interrupted the current expansion
///< it's set only iff N_ADDS is set
@@ -420,7 +437,7 @@ void compl_status_clear(void)
compl_cont_status = 0;
}
-// @return true if completion is using the forward direction matches
+/// @return true if completion is using the forward direction matches
static bool compl_dir_forward(void)
{
return compl_direction == FORWARD;
@@ -452,7 +469,7 @@ bool check_compl_option(bool dict_opt)
msg_attr((dict_opt
? _("'dictionary' option is empty")
: _("'thesaurus' option is empty")), HL_ATTR(HLF_E));
- if (emsg_silent == 0) {
+ if (emsg_silent == 0 && !in_assert_fails) {
vim_beep(BO_COMPL);
setcursor();
ui_flush();
@@ -572,8 +589,8 @@ bool ins_compl_accept_char(int c)
/// Get the completed text by inferring the case of the originally typed text.
/// If the result is in allocated memory "tofree" is set to it.
-static char_u *ins_compl_infercase_gettext(char_u *str, int char_len, int compl_char_len,
- int min_len, char **tofree)
+static char *ins_compl_infercase_gettext(const char *str, int char_len, int compl_char_len,
+ int min_len, char **tofree)
{
bool has_lower = false;
bool was_letter = false;
@@ -581,7 +598,7 @@ static char_u *ins_compl_infercase_gettext(char_u *str, int char_len, int compl_
// Allocate wide character array for the completion and fill it.
int *const wca = xmalloc((size_t)char_len * sizeof(*wca));
{
- const char_u *p = str;
+ const char *p = str;
for (int i = 0; i < char_len; i++) {
wca[i] = mb_ptr2char_adv(&p);
}
@@ -589,7 +606,7 @@ static char_u *ins_compl_infercase_gettext(char_u *str, int char_len, int compl_
// Rule 1: Were any chars converted to lower?
{
- const char_u *p = (char_u *)compl_orig_text;
+ const char *p = compl_orig_text;
for (int i = 0; i < min_len; i++) {
const int c = mb_ptr2char_adv(&p);
if (mb_islower(c)) {
@@ -608,7 +625,7 @@ static char_u *ins_compl_infercase_gettext(char_u *str, int char_len, int compl_
// Rule 2: No lower case, 2nd consecutive letter converted to
// upper case.
if (!has_lower) {
- const char_u *p = (char_u *)compl_orig_text;
+ const char *p = compl_orig_text;
for (int i = 0; i < min_len; i++) {
const int c = mb_ptr2char_adv(&p);
if (was_letter && mb_isupper(c) && mb_islower(wca[i])) {
@@ -624,7 +641,7 @@ static char_u *ins_compl_infercase_gettext(char_u *str, int char_len, int compl_
// Copy the original case of the part we typed.
{
- const char_u *p = (char_u *)compl_orig_text;
+ const char *p = compl_orig_text;
for (int i = 0; i < min_len; i++) {
const int c = mb_ptr2char_adv(&p);
if (mb_islower(c)) {
@@ -637,7 +654,7 @@ static char_u *ins_compl_infercase_gettext(char_u *str, int char_len, int compl_
// Generate encoding specific output from wide character array.
garray_T gap;
- char *p = (char *)IObuff;
+ char *p = IObuff;
int i = 0;
ga_init(&gap, 1, 500);
while (i < char_len) {
@@ -646,7 +663,7 @@ static char_u *ins_compl_infercase_gettext(char_u *str, int char_len, int compl_
assert(gap.ga_data != NULL); // suppress clang "Dereference of NULL pointer"
p = (char *)gap.ga_data + gap.ga_len;
gap.ga_len += utf_char2bytes(wca[i++], p);
- } else if ((p - (char *)IObuff) + 6 >= IOSIZE) {
+ } else if ((p - IObuff) + 6 >= IOSIZE) {
// Multi-byte characters can occupy up to five bytes more than
// ASCII characters, and we also need one byte for NUL, so when
// getting to six bytes from the edge of IObuff switch to using a
@@ -667,7 +684,7 @@ static char_u *ins_compl_infercase_gettext(char_u *str, int char_len, int compl_
}
*p = NUL;
- return (char_u *)IObuff;
+ return IObuff;
}
/// This is like ins_compl_add(), but if 'ic' and 'inf' are set, then the
@@ -676,11 +693,11 @@ static char_u *ins_compl_infercase_gettext(char_u *str, int char_len, int compl_
/// the rest of the word to be in -- webb
///
/// @param[in] cont_s_ipos next ^X<> will set initial_pos
-int ins_compl_add_infercase(char_u *str_arg, int len, bool icase, char_u *fname, Direction dir,
+int ins_compl_add_infercase(char *str_arg, int len, bool icase, char *fname, Direction dir,
bool cont_s_ipos)
FUNC_ATTR_NONNULL_ARG(1)
{
- char_u *str = str_arg;
+ char *str = str_arg;
int char_len; // count multi-byte characters
int compl_char_len;
int flags = 0;
@@ -691,7 +708,7 @@ int ins_compl_add_infercase(char_u *str_arg, int len, bool icase, char_u *fname,
// Find actual length of completion.
{
- const char_u *p = str;
+ const char *p = str;
char_len = 0;
while (*p != NUL) {
MB_PTR_ADV(p);
@@ -701,7 +718,7 @@ int ins_compl_add_infercase(char_u *str_arg, int len, bool icase, char_u *fname,
// Find actual length of original text.
{
- const char_u *p = (char_u *)compl_orig_text;
+ const char *p = compl_orig_text;
compl_char_len = 0;
while (*p != NUL) {
MB_PTR_ADV(p);
@@ -722,7 +739,7 @@ int ins_compl_add_infercase(char_u *str_arg, int len, bool icase, char_u *fname,
flags |= CP_ICASE;
}
- int res = ins_compl_add((char *)str, len, (char *)fname, NULL, false, NULL, dir, flags, false);
+ int res = ins_compl_add(str, len, fname, NULL, false, NULL, dir, flags, false);
xfree(tofree);
return res;
}
@@ -785,7 +802,7 @@ static int ins_compl_add(char *const str, int len, char *const fname, char *cons
match = compl_first_match;
do {
if (!match_at_original_text(match)
- && STRNCMP(match->cp_str, str, len) == 0
+ && strncmp(match->cp_str, str, (size_t)len) == 0
&& ((int)strlen(match->cp_str) <= len || match->cp_str[len] == NUL)) {
FREE_CPTEXT(cptext, cptext_allocated);
return NOTDONE;
@@ -877,7 +894,7 @@ static int ins_compl_add(char *const str, int len, char *const fname, char *cons
/// @param match completion match
/// @param str character string to check
/// @param len length of "str"
-static bool ins_compl_equal(compl_T *match, char_u *str, size_t len)
+static bool ins_compl_equal(compl_T *match, char *str, size_t len)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
if (match->cp_flags & CP_EQUAL) {
@@ -886,13 +903,13 @@ static bool ins_compl_equal(compl_T *match, char_u *str, size_t len)
if (match->cp_flags & CP_ICASE) {
return STRNICMP(match->cp_str, str, len) == 0;
}
- return STRNCMP(match->cp_str, str, len) == 0;
+ return strncmp(match->cp_str, str, len) == 0;
}
/// Reduce the longest common string for match "match".
static void ins_compl_longest_match(compl_T *match)
{
- char_u *p, *s;
+ char *p, *s;
int c1, c2;
int had_match;
@@ -916,11 +933,11 @@ static void ins_compl_longest_match(compl_T *match)
}
// Reduce the text if this match differs from compl_leader.
- p = (char_u *)compl_leader;
- s = (char_u *)match->cp_str;
+ p = compl_leader;
+ s = match->cp_str;
while (*p != NUL) {
- c1 = utf_ptr2char((char *)p);
- c2 = utf_ptr2char((char *)s);
+ c1 = utf_ptr2char(p);
+ c2 = utf_ptr2char(s);
if ((match->cp_flags & CP_ICASE)
? (mb_tolower(c1) != mb_tolower(c2))
@@ -1135,7 +1152,7 @@ static int ins_compl_build_pum(void)
do {
if (!match_at_original_text(compl)
&& (compl_leader == NULL
- || ins_compl_equal(compl, (char_u *)compl_leader, (size_t)lead_len))) {
+ || ins_compl_equal(compl, compl_leader, (size_t)lead_len))) {
compl_match_arraysize++;
}
compl = compl->cp_next;
@@ -1160,7 +1177,7 @@ static int ins_compl_build_pum(void)
do {
if (!match_at_original_text(compl)
&& (compl_leader == NULL
- || ins_compl_equal(compl, (char_u *)compl_leader, (size_t)lead_len))) {
+ || ins_compl_equal(compl, compl_leader, (size_t)lead_len))) {
if (!shown_match_ok) {
if (compl == compl_shown_match || did_find_shown_match) {
// This item is the shown match or this is the
@@ -1177,16 +1194,16 @@ static int ins_compl_build_pum(void)
}
if (compl->cp_text[CPT_ABBR] != NULL) {
- compl_match_array[i].pum_text = (char_u *)compl->cp_text[CPT_ABBR];
+ compl_match_array[i].pum_text = compl->cp_text[CPT_ABBR];
} else {
- compl_match_array[i].pum_text = (char_u *)compl->cp_str;
+ compl_match_array[i].pum_text = compl->cp_str;
}
- compl_match_array[i].pum_kind = (char_u *)compl->cp_text[CPT_KIND];
- compl_match_array[i].pum_info = (char_u *)compl->cp_text[CPT_INFO];
+ compl_match_array[i].pum_kind = compl->cp_text[CPT_KIND];
+ compl_match_array[i].pum_info = compl->cp_text[CPT_INFO];
if (compl->cp_text[CPT_MENU] != NULL) {
- compl_match_array[i++].pum_extra = (char_u *)compl->cp_text[CPT_MENU];
+ compl_match_array[i++].pum_extra = compl->cp_text[CPT_MENU];
} else {
- compl_match_array[i++].pum_extra = (char_u *)compl->cp_fname;
+ compl_match_array[i++].pum_extra = compl->cp_fname;
}
}
@@ -1240,8 +1257,8 @@ void ins_compl_show_pum(void)
} else {
// popup menu already exists, only need to find the current item.
for (int i = 0; i < compl_match_arraysize; i++) {
- if (compl_match_array[i].pum_text == (char_u *)compl_shown_match->cp_str
- || compl_match_array[i].pum_text == (char_u *)compl_shown_match->cp_text[CPT_ABBR]) {
+ if (compl_match_array[i].pum_text == compl_shown_match->cp_str
+ || compl_match_array[i].pum_text == compl_shown_match->cp_text[CPT_ABBR]) {
cur = i;
break;
}
@@ -1277,10 +1294,10 @@ void ins_compl_show_pum(void)
///
/// @param flags DICT_FIRST and/or DICT_EXACT
/// @param thesaurus Thesaurus completion
-static void ins_compl_dictionaries(char_u *dict_start, char_u *pat, int flags, int thesaurus)
+static void ins_compl_dictionaries(char *dict_start, char *pat, int flags, int thesaurus)
{
- char *dict = (char *)dict_start;
- char_u *ptr;
+ char *dict = dict_start;
+ char *ptr;
char *buf;
regmatch_T regmatch;
char **files;
@@ -1311,16 +1328,16 @@ static void ins_compl_dictionaries(char_u *dict_start, char_u *pat, int flags, i
// to only match at the start of a line. Otherwise just match the
// pattern. Also need to double backslashes.
if (ctrl_x_mode_line_or_eval()) {
- char_u *pat_esc = vim_strsave_escaped(pat, (char_u *)"\\");
+ char *pat_esc = vim_strsave_escaped(pat, "\\");
- size_t len = STRLEN(pat_esc) + 10;
+ size_t len = strlen(pat_esc) + 10;
ptr = xmalloc(len);
- vim_snprintf((char *)ptr, len, "^\\s*\\zs\\V%s", pat_esc);
- regmatch.regprog = vim_regcomp((char *)ptr, RE_MAGIC);
+ vim_snprintf(ptr, len, "^\\s*\\zs\\V%s", pat_esc);
+ regmatch.regprog = vim_regcomp(ptr, RE_MAGIC);
xfree(pat_esc);
xfree(ptr);
} else {
- regmatch.regprog = vim_regcomp((char *)pat, p_magic ? RE_MAGIC : 0);
+ regmatch.regprog = vim_regcomp(pat, magic_isset() ? RE_MAGIC : 0);
if (regmatch.regprog == NULL) {
goto theend;
}
@@ -1355,10 +1372,10 @@ static void ins_compl_dictionaries(char_u *dict_start, char_u *pat, int flags, i
} else {
ptr = pat;
}
- spell_dump_compl((char *)ptr, regmatch.rm_ic, &dir, 0);
+ spell_dump_compl(ptr, regmatch.rm_ic, &dir, 0);
} else if (count > 0) { // avoid warning for using "files" uninit
ins_compl_files(count, files, thesaurus, flags,
- &regmatch, (char_u *)buf, &dir);
+ &regmatch, buf, &dir);
if (flags != DICT_EXACT) {
FreeWild(count, files);
}
@@ -1378,12 +1395,12 @@ theend:
/// skipping the word at 'skip_word'.
///
/// @return OK on success.
-static int thesaurus_add_words_in_line(char *fname, char_u **buf_arg, int dir, char_u *skip_word)
+static int thesaurus_add_words_in_line(char *fname, char **buf_arg, int dir, const char *skip_word)
{
int status = OK;
// Add the other matches on the line
- char_u *ptr = *buf_arg;
+ char *ptr = *buf_arg;
while (!got_int) {
// Find start of the next word. Skip white
// space and punctuation.
@@ -1391,7 +1408,7 @@ static int thesaurus_add_words_in_line(char *fname, char_u **buf_arg, int dir, c
if (*ptr == NUL || *ptr == NL) {
break;
}
- char_u *wstart = ptr;
+ char *wstart = ptr;
// Find end of the word.
// Japanese words may have characters in
@@ -1400,7 +1417,7 @@ static int thesaurus_add_words_in_line(char *fname, char_u **buf_arg, int dir, c
while (*ptr != NUL) {
const int l = utfc_ptr2len((const char *)ptr);
- if (l < 2 && !vim_iswordc(*ptr)) {
+ if (l < 2 && !vim_iswordc((uint8_t)(*ptr))) {
break;
}
ptr += l;
@@ -1409,7 +1426,7 @@ static int thesaurus_add_words_in_line(char *fname, char_u **buf_arg, int dir, c
// Add the word. Skip the regexp match.
if (wstart != skip_word) {
status = ins_compl_add_infercase(wstart, (int)(ptr - wstart), p_ic,
- (char_u *)fname, dir, false);
+ fname, dir, false);
if (status == FAIL) {
break;
}
@@ -1423,21 +1440,21 @@ static int thesaurus_add_words_in_line(char *fname, char_u **buf_arg, int dir, c
/// Process "count" dictionary/thesaurus "files" and add the text matching
/// "regmatch".
static void ins_compl_files(int count, char **files, int thesaurus, int flags, regmatch_T *regmatch,
- char_u *buf, Direction *dir)
+ char *buf, Direction *dir)
FUNC_ATTR_NONNULL_ARG(2, 7)
{
- char_u *ptr;
+ char *ptr;
int i;
FILE *fp;
int add_r;
for (i = 0; i < count && !got_int && !compl_interrupted; i++) {
fp = os_fopen(files[i], "r"); // open dictionary file
- if (flags != DICT_EXACT) {
+ if (flags != DICT_EXACT && !shortmess(SHM_COMPLETIONSCAN)) {
msg_hist_off = true; // reset in msg_trunc_attr()
- vim_snprintf((char *)IObuff, IOSIZE,
+ vim_snprintf(IObuff, IOSIZE,
_("Scanning dictionary: %s"), files[i]);
- (void)msg_trunc_attr((char *)IObuff, true, HL_ATTR(HLF_R));
+ (void)msg_trunc_attr(IObuff, true, HL_ATTR(HLF_R));
}
if (fp == NULL) {
@@ -1448,21 +1465,20 @@ static void ins_compl_files(int count, char **files, int thesaurus, int flags, r
// Check each line for a match.
while (!got_int && !compl_interrupted && !vim_fgets(buf, LSIZE, fp)) {
ptr = buf;
- while (vim_regexec(regmatch, (char *)buf, (colnr_T)(ptr - buf))) {
- ptr = (char_u *)regmatch->startp[0];
+ while (vim_regexec(regmatch, buf, (colnr_T)(ptr - buf))) {
+ ptr = regmatch->startp[0];
if (ctrl_x_mode_line_or_eval()) {
ptr = find_line_end(ptr);
} else {
ptr = find_word_end(ptr);
}
- add_r = ins_compl_add_infercase((char_u *)regmatch->startp[0],
- (int)(ptr - (char_u *)regmatch->startp[0]),
- p_ic, (char_u *)files[i], *dir, false);
+ add_r = ins_compl_add_infercase(regmatch->startp[0],
+ (int)(ptr - regmatch->startp[0]),
+ p_ic, files[i], *dir, false);
if (thesaurus) {
// For a thesaurus, add all the words in the line
ptr = buf;
- add_r = thesaurus_add_words_in_line(files[i], &ptr, *dir,
- (char_u *)regmatch->startp[0]);
+ add_r = thesaurus_add_words_in_line(files[i], &ptr, *dir, regmatch->startp[0]);
}
if (add_r == OK) {
// if dir was BACKWARD then honor it just once
@@ -1485,24 +1501,24 @@ static void ins_compl_files(int count, char **files, int thesaurus, int flags, r
/// Find the start of the next word.
/// Returns a pointer to the first char of the word. Also stops at a NUL.
-char_u *find_word_start(char_u *ptr)
+char *find_word_start(char *ptr)
FUNC_ATTR_PURE
{
while (*ptr != NUL && *ptr != '\n' && mb_get_class(ptr) <= 1) {
- ptr += utfc_ptr2len((char *)ptr);
+ ptr += utfc_ptr2len(ptr);
}
return ptr;
}
/// Find the end of the word. Assumes it starts inside a word.
/// Returns a pointer to just after the word.
-char_u *find_word_end(char_u *ptr)
+char *find_word_end(char *ptr)
FUNC_ATTR_PURE
{
const int start_class = mb_get_class(ptr);
if (start_class > 1) {
while (*ptr != NUL) {
- ptr += utfc_ptr2len((char *)ptr);
+ ptr += utfc_ptr2len(ptr);
if (mb_get_class(ptr) != start_class) {
break;
}
@@ -1512,12 +1528,13 @@ char_u *find_word_end(char_u *ptr)
}
/// Find the end of the line, omitting CR and NL at the end.
-/// Returns a pointer to just after the line.
-static char_u *find_line_end(char_u *ptr)
+///
+/// @return a pointer to just after the line.
+static char *find_line_end(char *ptr)
{
- char_u *s;
+ char *s;
- s = ptr + STRLEN(ptr);
+ s = ptr + strlen(ptr);
while (s > ptr && (s[-1] == CAR || s[-1] == NL)) {
s--;
}
@@ -1788,13 +1805,13 @@ static void ins_compl_set_original_text(char *str)
/// matches.
void ins_compl_addfrommatch(void)
{
- char_u *p;
+ char *p;
int len = (int)curwin->w_cursor.col - (int)compl_col;
int c;
compl_T *cp;
assert(compl_shown_match != NULL);
- p = (char_u *)compl_shown_match->cp_str;
- if ((int)STRLEN(p) <= len) { // the match is too short
+ p = compl_shown_match->cp_str;
+ if ((int)strlen(p) <= len) { // the match is too short
// When still at the original match use the first entry that matches
// the leader.
if (!match_at_original_text(compl_shown_match)) {
@@ -1805,17 +1822,17 @@ void ins_compl_addfrommatch(void)
for (cp = compl_shown_match->cp_next; cp != NULL
&& !is_first_match(cp); cp = cp->cp_next) {
if (compl_leader == NULL
- || ins_compl_equal(cp, (char_u *)compl_leader, STRLEN(compl_leader))) {
- p = (char_u *)cp->cp_str;
+ || ins_compl_equal(cp, compl_leader, strlen(compl_leader))) {
+ p = cp->cp_str;
break;
}
}
- if (p == NULL || (int)STRLEN(p) <= len) {
+ if (p == NULL || (int)strlen(p) <= len) {
return;
}
}
p += len;
- c = utf_ptr2char((char *)p);
+ c = utf_ptr2char(p);
ins_compl_addleader(c);
}
@@ -1957,9 +1974,9 @@ static bool ins_compl_stop(const int c, const int prev_mode, bool retval)
// of the original text that has changed.
// When using the longest match, edited the match or used
// CTRL-E then don't use the current match.
- char_u *ptr;
+ char *ptr;
if (compl_curr_match != NULL && compl_used_match && c != Ctrl_E) {
- ptr = (char_u *)compl_curr_match->cp_str;
+ ptr = compl_curr_match->cp_str;
} else {
ptr = NULL;
}
@@ -2008,17 +2025,17 @@ static bool ins_compl_stop(const int c, const int prev_mode, bool retval)
// but only do this, if the Popup is still visible
if (c == Ctrl_E) {
ins_compl_delete();
- char_u *p = NULL;
+ char *p = NULL;
if (compl_leader != NULL) {
- p = (char_u *)compl_leader;
+ p = compl_leader;
} else if (compl_first_match != NULL) {
- p = (char_u *)compl_orig_text;
+ p = compl_orig_text;
}
if (p != NULL) {
const int compl_len = get_compl_len();
- const int len = (int)STRLEN(p);
+ const int len = (int)strlen(p);
if (len > compl_len) {
- ins_bytes_len((char *)p + compl_len, (size_t)(len - compl_len));
+ ins_bytes_len(p + compl_len, (size_t)(len - compl_len));
}
}
retval = true;
@@ -2164,24 +2181,24 @@ bool ins_compl_prep(int c)
/// Fix the redo buffer for the completion leader replacing some of the typed
/// text. This inserts backspaces and appends the changed text.
/// "ptr" is the known leader text or NUL.
-static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg)
+static void ins_compl_fixRedoBufForLeader(char *ptr_arg)
{
int len;
- char_u *p;
- char_u *ptr = ptr_arg;
+ char *p;
+ char *ptr = ptr_arg;
if (ptr == NULL) {
if (compl_leader != NULL) {
- ptr = (char_u *)compl_leader;
+ ptr = compl_leader;
} else {
return; // nothing to do
}
}
if (compl_orig_text != NULL) {
- p = (char_u *)compl_orig_text;
+ p = compl_orig_text;
for (len = 0; p[len] != NUL && p[len] == ptr[len]; len++) {}
if (len > 0) {
- len -= utf_head_off((char *)p, (char *)p + len);
+ len -= utf_head_off(p, p + len);
}
for (p += len; *p != NUL; MB_PTR_ADV(p)) {
AppendCharToRedobuff(K_BS);
@@ -2189,7 +2206,7 @@ static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg)
} else {
len = 0;
}
- AppendToRedobuffLit((char *)ptr + len, -1);
+ AppendToRedobuffLit(ptr + len, -1);
}
/// Loops through the list of windows, loaded-buffers or non-loaded-buffers
@@ -2224,30 +2241,129 @@ static buf_T *ins_compl_next_buf(buf_T *buf, int flag)
return buf;
}
+static Callback cfu_cb; ///< 'completefunc' callback function
+static Callback ofu_cb; ///< 'omnifunc' callback function
+static Callback tsrfu_cb; ///< 'thesaurusfunc' callback function
+
+/// Copy a global callback function to a buffer local callback.
+static void copy_global_to_buflocal_cb(Callback *globcb, Callback *bufcb)
+{
+ callback_free(bufcb);
+ if (globcb->type != kCallbackNone) {
+ callback_copy(bufcb, globcb);
+ }
+}
+
+/// Parse the 'completefunc' option value and set the callback function.
+/// Invoked when the 'completefunc' option is set. The option value can be a
+/// name of a function (string), or function(<name>) or funcref(<name>) or a
+/// lambda expression.
+void set_completefunc_option(char **errmsg)
+{
+ if (option_set_callback_func(curbuf->b_p_cfu, &cfu_cb) == FAIL) {
+ *errmsg = e_invarg;
+ return;
+ }
+
+ set_buflocal_cfu_callback(curbuf);
+}
+
+/// Copy the global 'completefunc' callback function to the buffer-local
+/// 'completefunc' callback for "buf".
+void set_buflocal_cfu_callback(buf_T *buf)
+{
+ copy_global_to_buflocal_cb(&cfu_cb, &buf->b_cfu_cb);
+}
+
+/// Parse the 'omnifunc' option value and set the callback function.
+/// Invoked when the 'omnifunc' option is set. The option value can be a
+/// name of a function (string), or function(<name>) or funcref(<name>) or a
+/// lambda expression.
+void set_omnifunc_option(buf_T *buf, char **errmsg)
+{
+ if (option_set_callback_func(buf->b_p_ofu, &ofu_cb) == FAIL) {
+ *errmsg = e_invarg;
+ return;
+ }
+ set_buflocal_ofu_callback(buf);
+}
+
+/// Copy the global 'omnifunc' callback function to the buffer-local 'omnifunc'
+/// callback for "buf".
+void set_buflocal_ofu_callback(buf_T *buf)
+{
+ copy_global_to_buflocal_cb(&ofu_cb, &buf->b_ofu_cb);
+}
+
+/// Parse the 'thesaurusfunc' option value and set the callback function.
+/// Invoked when the 'thesaurusfunc' option is set. The option value can be a
+/// name of a function (string), or function(<name>) or funcref(<name>) or a
+/// lambda expression.
+void set_thesaurusfunc_option(char **errmsg)
+{
+ int retval;
+
+ if (*curbuf->b_p_tsrfu != NUL) {
+ // buffer-local option set
+ retval = option_set_callback_func(curbuf->b_p_tsrfu, &curbuf->b_tsrfu_cb);
+ } else {
+ // global option set
+ retval = option_set_callback_func(p_tsrfu, &tsrfu_cb);
+ }
+
+ if (retval == FAIL) {
+ *errmsg = e_invarg;
+ }
+}
+
+/// Mark the global 'completefunc' 'omnifunc' and 'thesaurusfunc' callbacks with
+/// "copyID" so that they are not garbage collected.
+bool set_ref_in_insexpand_funcs(int copyID)
+{
+ bool abort = set_ref_in_callback(&cfu_cb, copyID, NULL, NULL);
+ abort = abort || set_ref_in_callback(&ofu_cb, copyID, NULL, NULL);
+ abort = abort || set_ref_in_callback(&tsrfu_cb, copyID, NULL, NULL);
+
+ return abort;
+}
+
/// Get the user-defined completion function name for completion "type"
-static char_u *get_complete_funcname(int type)
+static char *get_complete_funcname(int type)
{
switch (type) {
case CTRL_X_FUNCTION:
- return (char_u *)curbuf->b_p_cfu;
+ return curbuf->b_p_cfu;
case CTRL_X_OMNI:
- return (char_u *)curbuf->b_p_ofu;
+ return curbuf->b_p_ofu;
case CTRL_X_THESAURUS:
- return *curbuf->b_p_tsrfu == NUL ? (char_u *)p_tsrfu : (char_u *)curbuf->b_p_tsrfu;
+ return *curbuf->b_p_tsrfu == NUL ? p_tsrfu : curbuf->b_p_tsrfu;
default:
- return (char_u *)"";
+ return "";
}
}
-/// Execute user defined complete function 'completefunc' or 'omnifunc', and
-/// get matches in "matches".
+/// Get the callback to use for insert mode completion.
+static Callback *get_insert_callback(int type)
+{
+ if (type == CTRL_X_FUNCTION) {
+ return &curbuf->b_cfu_cb;
+ }
+ if (type == CTRL_X_OMNI) {
+ return &curbuf->b_ofu_cb;
+ }
+ // CTRL_X_THESAURUS
+ return (*curbuf->b_p_tsrfu != NUL) ? &curbuf->b_tsrfu_cb : &tsrfu_cb;
+}
+
+/// Execute user defined complete function 'completefunc', 'omnifunc' or
+/// 'thesaurusfunc', and get matches in "matches".
///
-/// @param type CTRL_X_OMNI or CTRL_X_FUNCTION
-static void expand_by_function(int type, char_u *base)
+/// @param type either CTRL_X_OMNI or CTRL_X_FUNCTION or CTRL_X_THESAURUS
+static void expand_by_function(int type, char *base)
{
list_T *matchlist = NULL;
dict_T *matchdict = NULL;
- char_u *funcname;
+ char *funcname;
pos_T pos;
typval_T rettv;
const int save_State = State;
@@ -2264,7 +2380,7 @@ static void expand_by_function(int type, char_u *base)
args[1].v_type = VAR_STRING;
args[2].v_type = VAR_UNKNOWN;
args[0].vval.v_number = 0;
- args[1].vval.v_string = base != NULL ? (char *)base : "";
+ args[1].vval.v_string = base != NULL ? base : "";
pos = curwin->w_cursor;
// Lock the text to avoid weird things from happening. Also disallow
@@ -2272,8 +2388,10 @@ static void expand_by_function(int type, char_u *base)
// Insert mode in another buffer.
textlock++;
+ Callback *cb = get_insert_callback(type);
+
// Call a function, which returns a list or dict.
- if (call_vim_function((char *)funcname, 2, args, &rettv) == OK) {
+ if (callback_call(cb, 2, args, &rettv)) {
switch (rettv.v_type) {
case VAR_LIST:
matchlist = rettv.vval.v_list;
@@ -2518,12 +2636,12 @@ void f_complete_check(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
}
/// Return Insert completion mode name string
-static char_u *ins_compl_mode(void)
+static char *ins_compl_mode(void)
{
if (ctrl_x_mode_not_defined_yet() || ctrl_x_mode_scroll() || compl_started) {
- return (char_u *)ctrl_x_mode_names[ctrl_x_mode & ~CTRL_X_WANT_IDENT];
+ return ctrl_x_mode_names[ctrl_x_mode & ~CTRL_X_WANT_IDENT];
}
- return (char_u *)"";
+ return "";
}
/// Assign the sequence number to all the completion matches which don't have
@@ -2612,8 +2730,7 @@ static void get_complete_info(list_T *what_list, dict_T *retdict)
int ret = OK;
if (what_flag & CI_WHAT_MODE) {
- ret = tv_dict_add_str(retdict, S_LEN("mode"),
- (char *)ins_compl_mode());
+ ret = tv_dict_add_str(retdict, S_LEN("mode"), ins_compl_mode());
}
if (ret == OK && (what_flag & CI_WHAT_PUM_VISIBLE)) {
@@ -2637,6 +2754,7 @@ static void get_complete_info(list_T *what_list, dict_T *retdict)
tv_dict_add_str(di, S_LEN("kind"), EMPTY_IF_NULL(match->cp_text[CPT_KIND]));
tv_dict_add_str(di, S_LEN("info"), EMPTY_IF_NULL(match->cp_text[CPT_INFO]));
if (match->cp_user_data.v_type == VAR_UNKNOWN) {
+ // Add an empty string for backwards compatibility
tv_dict_add_str(di, S_LEN("user_data"), "");
} else {
tv_dict_add_tv(di, S_LEN("user_data"), &match->cp_user_data);
@@ -2740,7 +2858,7 @@ static int process_next_cpt_value(ins_compl_next_state_T *st, int *compl_type_ar
// Remember the first match so that the loop stops when we
// wrap and come back there a second time.
st->set_match_pos = true;
- } else if (vim_strchr("buwU", *st->e_cpt) != NULL
+ } else if (vim_strchr("buwU", (uint8_t)(*st->e_cpt)) != NULL
&& (st->ins_buf = ins_compl_next_buf(st->ins_buf, *st->e_cpt)) != curbuf) {
// Scan a buffer, but not the current one.
if (st->ins_buf->b_ml.ml_mfp != NULL) { // loaded buffer
@@ -2756,17 +2874,19 @@ static int process_next_cpt_value(ins_compl_next_state_T *st, int *compl_type_ar
goto done;
}
compl_type = CTRL_X_DICTIONARY;
- st->dict = (char_u *)st->ins_buf->b_fname;
+ st->dict = st->ins_buf->b_fname;
st->dict_f = DICT_EXACT;
}
- msg_hist_off = true; // reset in msg_trunc_attr()
- vim_snprintf((char *)IObuff, IOSIZE, _("Scanning: %s"),
- st->ins_buf->b_fname == NULL
- ? buf_spname(st->ins_buf)
- : st->ins_buf->b_sfname == NULL
- ? st->ins_buf->b_fname
- : st->ins_buf->b_sfname);
- (void)msg_trunc_attr((char *)IObuff, true, HL_ATTR(HLF_R));
+ if (!shortmess(SHM_COMPLETIONSCAN)) {
+ msg_hist_off = true; // reset in msg_trunc_attr()
+ vim_snprintf(IObuff, IOSIZE, _("Scanning: %s"),
+ st->ins_buf->b_fname == NULL
+ ? buf_spname(st->ins_buf)
+ : st->ins_buf->b_sfname == NULL
+ ? st->ins_buf->b_fname
+ : st->ins_buf->b_sfname);
+ (void)msg_trunc_attr(IObuff, true, HL_ATTR(HLF_R));
+ }
} else if (*st->e_cpt == NUL) {
status = INS_COMPL_CPT_END;
} else {
@@ -2779,7 +2899,7 @@ static int process_next_cpt_value(ins_compl_next_state_T *st, int *compl_type_ar
compl_type = CTRL_X_THESAURUS;
}
if (*++st->e_cpt != ',' && *st->e_cpt != NUL) {
- st->dict = (char_u *)st->e_cpt;
+ st->dict = st->e_cpt;
st->dict_f = DICT_FIRST;
}
} else if (*st->e_cpt == 'i') {
@@ -2787,16 +2907,18 @@ static int process_next_cpt_value(ins_compl_next_state_T *st, int *compl_type_ar
} else if (*st->e_cpt == 'd') {
compl_type = CTRL_X_PATH_DEFINES;
} else if (*st->e_cpt == ']' || *st->e_cpt == 't') {
- msg_hist_off = true; // reset in msg_trunc_attr()
compl_type = CTRL_X_TAGS;
- vim_snprintf((char *)IObuff, IOSIZE, "%s", _("Scanning tags."));
- (void)msg_trunc_attr((char *)IObuff, true, HL_ATTR(HLF_R));
+ if (!shortmess(SHM_COMPLETIONSCAN)) {
+ msg_hist_off = true; // reset in msg_trunc_attr()
+ vim_snprintf(IObuff, IOSIZE, "%s", _("Scanning tags."));
+ (void)msg_trunc_attr(IObuff, true, HL_ATTR(HLF_R));
+ }
} else {
compl_type = -1;
}
// in any case e_cpt is advanced to the next entry
- (void)copy_option_part(&st->e_cpt, (char *)IObuff, IOSIZE, ",");
+ (void)copy_option_part(&st->e_cpt, IObuff, IOSIZE, ",");
st->found_all = true;
if (compl_type == -1) {
@@ -2813,7 +2935,7 @@ done:
/// included files.
static void get_next_include_file_completion(int compl_type)
{
- find_pattern_in_path((char_u *)compl_pattern, compl_direction,
+ find_pattern_in_path(compl_pattern, compl_direction,
strlen(compl_pattern), false, false,
((compl_type == CTRL_X_PATH_DEFINES
&& !(compl_cont_status & CONT_SOL))
@@ -2823,17 +2945,17 @@ static void get_next_include_file_completion(int compl_type)
/// Get the next set of words matching "compl_pattern" in dictionary or
/// thesaurus files.
-static void get_next_dict_tsr_completion(int compl_type, char_u *dict, int dict_f)
+static void get_next_dict_tsr_completion(int compl_type, char *dict, int dict_f)
{
if (thesaurus_func_complete(compl_type)) {
- expand_by_function(compl_type, (char_u *)compl_pattern);
+ expand_by_function(compl_type, compl_pattern);
} else {
ins_compl_dictionaries(dict != NULL ? dict
: (compl_type == CTRL_X_THESAURUS
- ? (*curbuf->b_p_tsr == NUL ? p_tsr : (char_u *)curbuf->b_p_tsr)
+ ? (*curbuf->b_p_tsr == NUL ? p_tsr : curbuf->b_p_tsr)
: (*curbuf->b_p_dict ==
- NUL ? (char_u *)p_dict : (char_u *)curbuf->b_p_dict)),
- (char_u *)compl_pattern,
+ NUL ? p_dict : curbuf->b_p_dict)),
+ compl_pattern,
dict != NULL ? dict_f : 0,
compl_type == CTRL_X_THESAURUS);
}
@@ -2844,7 +2966,7 @@ static void get_next_tag_completion(void)
{
// set p_ic according to p_ic, p_scs and pat for find_tags().
const int save_p_ic = p_ic;
- p_ic = ignorecase((char_u *)compl_pattern);
+ p_ic = ignorecase(compl_pattern);
// Find up to TAG_MANY matches. Avoids that an enormous number
// of matches is found when compl_pattern is empty
@@ -2872,11 +2994,11 @@ static void get_next_filename_completion(void)
}
// May change home directory back to "~".
- tilde_replace((char_u *)compl_pattern, num_matches, matches);
+ tilde_replace(compl_pattern, num_matches, matches);
#ifdef BACKSLASH_IN_FILENAME
if (curbuf->b_p_csl[0] != NUL) {
for (int i = 0; i < num_matches; i++) {
- char_u *ptr = matches[i];
+ char *ptr = matches[i];
while (*ptr != NUL) {
if (curbuf->b_p_csl[0] == 's' && *ptr == '\\') {
*ptr = '/';
@@ -2896,7 +3018,7 @@ static void get_next_cmdline_completion(void)
{
char **matches;
int num_matches;
- if (expand_cmdline(&compl_xp, (char_u *)compl_pattern,
+ if (expand_cmdline(&compl_xp, compl_pattern,
(int)strlen(compl_pattern),
&num_matches, &matches) == EXPAND_OK) {
ins_compl_add_matches(num_matches, matches, false);
@@ -2907,7 +3029,7 @@ static void get_next_cmdline_completion(void)
static void get_next_spell_completion(linenr_T lnum)
{
char **matches;
- int num_matches = expand_spelling(lnum, (char_u *)compl_pattern, &matches);
+ int num_matches = expand_spelling(lnum, compl_pattern, &matches);
if (num_matches > 0) {
ins_compl_add_matches(num_matches, matches, p_ic);
} else {
@@ -2921,27 +3043,27 @@ static void get_next_spell_completion(linenr_T lnum)
/// @param cur_match_pos current match position
/// @param match_len
/// @param cont_s_ipos next ^X<> will set initial_pos
-static char_u *ins_comp_get_next_word_or_line(buf_T *ins_buf, pos_T *cur_match_pos, int *match_len,
- bool *cont_s_ipos)
+static char *ins_comp_get_next_word_or_line(buf_T *ins_buf, pos_T *cur_match_pos, int *match_len,
+ bool *cont_s_ipos)
{
*match_len = 0;
- char_u *ptr = (char_u *)ml_get_buf(ins_buf, cur_match_pos->lnum, false) + cur_match_pos->col;
+ char *ptr = ml_get_buf(ins_buf, cur_match_pos->lnum, false) + cur_match_pos->col;
int len;
if (ctrl_x_mode_line_or_eval()) {
if (compl_status_adding()) {
if (cur_match_pos->lnum >= ins_buf->b_ml.ml_line_count) {
return NULL;
}
- ptr = (char_u *)ml_get_buf(ins_buf, cur_match_pos->lnum + 1, false);
+ ptr = ml_get_buf(ins_buf, cur_match_pos->lnum + 1, false);
if (!p_paste) {
- ptr = (char_u *)skipwhite((char *)ptr);
+ ptr = skipwhite(ptr);
}
}
- len = (int)STRLEN(ptr);
+ len = (int)strlen(ptr);
} else {
- char_u *tmp_ptr = ptr;
+ char *tmp_ptr = ptr;
- if (compl_status_adding() && compl_length <= (int)STRLEN(tmp_ptr)) {
+ if (compl_status_adding() && compl_length <= (int)strlen(tmp_ptr)) {
tmp_ptr += compl_length;
// Skip if already inside a word.
if (vim_iswordp(tmp_ptr)) {
@@ -2958,10 +3080,10 @@ static char_u *ins_comp_get_next_word_or_line(buf_T *ins_buf, pos_T *cur_match_p
if (cur_match_pos->lnum < ins_buf->b_ml.ml_line_count) {
// Try next line, if any. the new word will be "join" as if the
// normal command "J" was used. IOSIZE is always greater than
- // compl_length, so the next STRNCPY always works -- Acevedo
- STRNCPY(IObuff, ptr, len); // NOLINT(runtime/printf)
- ptr = (char_u *)ml_get_buf(ins_buf, cur_match_pos->lnum + 1, false);
- tmp_ptr = ptr = (char_u *)skipwhite((char *)ptr);
+ // compl_length, so the next strncpy always works -- Acevedo
+ strncpy(IObuff, ptr, (size_t)len); // NOLINT(runtime/printf)
+ ptr = ml_get_buf(ins_buf, cur_match_pos->lnum + 1, false);
+ tmp_ptr = ptr = skipwhite(ptr);
// Find start of next word.
tmp_ptr = find_word_start(tmp_ptr);
// Find end of next word.
@@ -2983,12 +3105,12 @@ static char_u *ins_comp_get_next_word_or_line(buf_T *ins_buf, pos_T *cur_match_p
if (tmp_ptr - ptr >= IOSIZE - len) {
tmp_ptr = ptr + IOSIZE - len - 1;
}
- STRLCPY(IObuff + len, ptr, IOSIZE - len);
+ xstrlcpy(IObuff + len, ptr, (size_t)(IOSIZE - len));
len += (int)(tmp_ptr - ptr);
*cont_s_ipos = true;
}
IObuff[len] = NUL;
- ptr = (char_u *)IObuff;
+ ptr = IObuff;
}
if (len == compl_length) {
return NULL;
@@ -3037,10 +3159,10 @@ static int get_next_default_completion(ins_compl_next_state_T *st, pos_T *start_
// has added a word that was at the beginning of the line.
if (ctrl_x_mode_line_or_eval() || (compl_cont_status & CONT_SOL)) {
found_new_match = search_for_exact_line(st->ins_buf, st->cur_match_pos,
- compl_direction, (char_u *)compl_pattern);
+ compl_direction, compl_pattern);
} else {
found_new_match = searchit(NULL, st->ins_buf, st->cur_match_pos,
- NULL, compl_direction, (char_u *)compl_pattern, 1L,
+ NULL, compl_direction, compl_pattern, 1L,
SEARCH_KEEP + SEARCH_NFMSG, RE_LAST, NULL);
}
msg_silent--;
@@ -3084,13 +3206,13 @@ static int get_next_default_completion(ins_compl_next_state_T *st, pos_T *start_
continue;
}
int len;
- char_u *ptr = ins_comp_get_next_word_or_line(st->ins_buf, st->cur_match_pos,
- &len, &cont_s_ipos);
+ char *ptr = ins_comp_get_next_word_or_line(st->ins_buf, st->cur_match_pos,
+ &len, &cont_s_ipos);
if (ptr == NULL) {
continue;
}
if (ins_compl_add_infercase(ptr, len, p_ic,
- st->ins_buf == curbuf ? NULL : (char_u *)st->ins_buf->b_sfname,
+ st->ins_buf == curbuf ? NULL : st->ins_buf->b_sfname,
0, cont_s_ipos) != NOTDONE) {
found_new_match = OK;
break;
@@ -3137,7 +3259,7 @@ static bool get_next_completion_match(int type, ins_compl_next_state_T *st, pos_
case CTRL_X_FUNCTION:
case CTRL_X_OMNI:
- expand_by_function(type, (char_u *)compl_pattern);
+ expand_by_function(type, compl_pattern);
break;
case CTRL_X_SPELL:
@@ -3190,7 +3312,7 @@ static int ins_compl_get_exp(pos_T *ini)
assert(st.ins_buf != NULL);
compl_old_match = compl_curr_match; // remember the last current match
- st.cur_match_pos = (compl_dir_forward() ? &st.last_match_pos : &st.first_match_pos);
+ st.cur_match_pos = compl_dir_forward() ? &st.last_match_pos : &st.first_match_pos;
// For ^N/^P loop over all the flags/windows/buffers in 'complete'
for (;;) {
@@ -3281,7 +3403,7 @@ static int ins_compl_get_exp(pos_T *ini)
static void ins_compl_update_shown_match(void)
{
while (!ins_compl_equal(compl_shown_match,
- (char_u *)compl_leader, STRLEN(compl_leader))
+ compl_leader, strlen(compl_leader))
&& compl_shown_match->cp_next != NULL
&& !is_first_match(compl_shown_match->cp_next)) {
compl_shown_match = compl_shown_match->cp_next;
@@ -3290,10 +3412,10 @@ static void ins_compl_update_shown_match(void)
// If we didn't find it searching forward, and compl_shows_dir is
// backward, find the last match.
if (compl_shows_dir_backward()
- && !ins_compl_equal(compl_shown_match, (char_u *)compl_leader, STRLEN(compl_leader))
+ && !ins_compl_equal(compl_shown_match, compl_leader, strlen(compl_leader))
&& (compl_shown_match->cp_next == NULL
|| is_first_match(compl_shown_match->cp_next))) {
- while (!ins_compl_equal(compl_shown_match, (char_u *)compl_leader, STRLEN(compl_leader))
+ while (!ins_compl_equal(compl_shown_match, compl_leader, strlen(compl_leader))
&& compl_shown_match->cp_prev != NULL
&& !is_first_match(compl_shown_match->cp_prev)) {
compl_shown_match = compl_shown_match->cp_prev;
@@ -3360,9 +3482,9 @@ static void ins_compl_show_filename(void)
}
}
msg_hist_off = true;
- vim_snprintf((char *)IObuff, IOSIZE, "%s %s%s", lead,
+ vim_snprintf(IObuff, IOSIZE, "%s %s%s", lead,
s > compl_shown_match->cp_fname ? "<" : "", s);
- msg((char *)IObuff);
+ msg(IObuff);
msg_hist_off = false;
redraw_cmdline = false; // don't overwrite!
}
@@ -3438,7 +3560,7 @@ static int find_next_completion_match(bool allow_get_expansion, int todo, bool a
if (!match_at_original_text(compl_shown_match)
&& compl_leader != NULL
&& !ins_compl_equal(compl_shown_match,
- (char_u *)compl_leader, STRLEN(compl_leader))) {
+ compl_leader, strlen(compl_leader))) {
todo++;
} else {
// Remember a matching item.
@@ -3559,17 +3681,6 @@ static int ins_compl_next(bool allow_get_expansion, int count, bool insert_match
return num_matches;
}
-void pum_ext_select_item(int item, bool insert, bool finish)
-{
- if (!pum_visible() || item < -1 || item >= compl_match_arraysize) {
- return;
- }
- pum_want.active = true;
- pum_want.item = item;
- pum_want.insert = insert;
- pum_want.finish = finish;
-}
-
/// Call this while finding completions, to check whether the user has hit a key
/// that should change the currently displayed completion, or exit completion
/// mode. Also, when compl_pending is not zero, show a completion as soon as
@@ -3707,30 +3818,30 @@ static int get_normal_compl_info(char *line, int startcol, colnr_T curs_col)
{
if ((compl_cont_status & CONT_SOL) || ctrl_x_mode_path_defines()) {
if (!compl_status_adding()) {
- while (--startcol >= 0 && vim_isIDc(line[startcol])) {}
+ while (--startcol >= 0 && vim_isIDc((uint8_t)line[startcol])) {}
compl_col += ++startcol;
compl_length = curs_col - startcol;
}
if (p_ic) {
- compl_pattern = (char *)str_foldcase((char_u *)line + compl_col, compl_length, NULL, 0);
+ compl_pattern = str_foldcase(line + compl_col, compl_length, NULL, 0);
} else {
compl_pattern = xstrnsave(line + compl_col, (size_t)compl_length);
}
} else if (compl_status_adding()) {
- char_u *prefix = (char_u *)"\\<";
+ char *prefix = "\\<";
// we need up to 2 extra chars for the prefix
- compl_pattern = xmalloc(quote_meta(NULL, (char_u *)line + compl_col, compl_length) + 2);
- if (!vim_iswordp((char_u *)line + compl_col)
+ compl_pattern = xmalloc(quote_meta(NULL, line + compl_col, compl_length) + 2);
+ if (!vim_iswordp(line + compl_col)
|| (compl_col > 0
- && (vim_iswordp(mb_prevptr((char_u *)line, (char_u *)line + compl_col))))) {
- prefix = (char_u *)"";
+ && (vim_iswordp(mb_prevptr(line, line + compl_col))))) {
+ prefix = "";
}
STRCPY(compl_pattern, prefix);
- (void)quote_meta((char_u *)compl_pattern + STRLEN(prefix),
- (char_u *)line + compl_col, compl_length);
+ (void)quote_meta(compl_pattern + strlen(prefix),
+ line + compl_col, compl_length);
} else if (--startcol < 0
- || !vim_iswordp(mb_prevptr((char_u *)line, (char_u *)line + startcol + 1))) {
+ || !vim_iswordp(mb_prevptr(line, line + startcol + 1))) {
// Match any word of at least two chars
compl_pattern = xstrdup("\\<\\k\\k");
compl_col += curs_col;
@@ -3739,10 +3850,10 @@ static int get_normal_compl_info(char *line, int startcol, colnr_T curs_col)
// Search the point of change class of multibyte character
// or not a word single byte character backward.
startcol -= utf_head_off(line, line + startcol);
- int base_class = mb_get_class((char_u *)line + startcol);
+ int base_class = mb_get_class(line + startcol);
while (--startcol >= 0) {
int head_off = utf_head_off(line, line + startcol);
- if (base_class != mb_get_class((char_u *)line + startcol - head_off)) {
+ if (base_class != mb_get_class(line + startcol - head_off)) {
break;
}
startcol -= head_off;
@@ -3755,13 +3866,12 @@ static int get_normal_compl_info(char *line, int startcol, colnr_T curs_col)
// xmalloc(7) is enough -- Acevedo
compl_pattern = xmalloc(7);
STRCPY(compl_pattern, "\\<");
- (void)quote_meta((char_u *)compl_pattern + 2, (char_u *)line + compl_col, 1);
+ (void)quote_meta(compl_pattern + 2, line + compl_col, 1);
STRCAT(compl_pattern, "\\k");
} else {
- compl_pattern = xmalloc(quote_meta(NULL, (char_u *)line + compl_col,
- compl_length) + 2);
+ compl_pattern = xmalloc(quote_meta(NULL, line + compl_col, compl_length) + 2);
STRCPY(compl_pattern, "\\<");
- (void)quote_meta((char_u *)compl_pattern + 2, (char_u *)line + compl_col, compl_length);
+ (void)quote_meta(compl_pattern + 2, line + compl_col, compl_length);
}
}
@@ -3779,7 +3889,7 @@ static int get_wholeline_compl_info(char *line, colnr_T curs_col)
compl_length = 0;
}
if (p_ic) {
- compl_pattern = (char *)str_foldcase((char_u *)line + compl_col, compl_length, NULL, 0);
+ compl_pattern = str_foldcase(line + compl_col, compl_length, NULL, 0);
} else {
compl_pattern = xstrnsave(line + compl_col, (size_t)compl_length);
}
@@ -3789,17 +3899,17 @@ static int get_wholeline_compl_info(char *line, colnr_T curs_col)
/// Get the pattern, column and length for filename completion.
/// Sets the global variables: compl_col, compl_length and compl_pattern.
-static int get_filename_compl_info(char_u *line, int startcol, colnr_T curs_col)
+static int get_filename_compl_info(char *line, int startcol, colnr_T curs_col)
{
// Go back to just before the first filename character.
if (startcol > 0) {
- char_u *p = line + startcol;
+ char *p = line + startcol;
MB_PTR_BACK(line, p);
- while (p > line && vim_isfilec(utf_ptr2char((char *)p))) {
+ while (p > line && vim_isfilec(utf_ptr2char(p))) {
MB_PTR_BACK(line, p);
}
- if (p == line && vim_isfilec(utf_ptr2char((char *)p))) {
+ if (p == line && vim_isfilec(utf_ptr2char(p))) {
startcol = 0;
} else {
startcol = (int)(p - line) + 1;
@@ -3808,7 +3918,7 @@ static int get_filename_compl_info(char_u *line, int startcol, colnr_T curs_col)
compl_col += startcol;
compl_length = (int)curs_col - startcol;
- compl_pattern = addstar((char *)line + compl_col, (size_t)compl_length, EXPAND_FILES);
+ compl_pattern = addstar(line + compl_col, (size_t)compl_length, EXPAND_FILES);
return OK;
}
@@ -3818,7 +3928,7 @@ static int get_filename_compl_info(char_u *line, int startcol, colnr_T curs_col)
static int get_cmdline_compl_info(char *line, colnr_T curs_col)
{
compl_pattern = xstrnsave(line, (size_t)curs_col);
- set_cmd_context(&compl_xp, (char_u *)compl_pattern, (int)strlen(compl_pattern), curs_col, false);
+ set_cmd_context(&compl_xp, compl_pattern, (int)strlen(compl_pattern), curs_col, false);
if (compl_xp.xp_context == EXPAND_UNSUCCESSFUL
|| compl_xp.xp_context == EXPAND_NOTHING) {
// No completion possible, use an empty pattern to get a
@@ -3843,7 +3953,7 @@ static int get_userdefined_compl_info(colnr_T curs_col)
const int save_State = State;
// Call 'completefunc' or 'omnifunc' and get pattern length as a string
- char_u *funcname = get_complete_funcname(ctrl_x_mode);
+ char *funcname = get_complete_funcname(ctrl_x_mode);
if (*funcname == NUL) {
semsg(_(e_notset), ctrl_x_mode_function() ? "completefunc" : "omnifunc");
return FAIL;
@@ -3858,7 +3968,8 @@ static int get_userdefined_compl_info(colnr_T curs_col)
pos_T pos = curwin->w_cursor;
textlock++;
- colnr_T col = (colnr_T)call_func_retnr((char *)funcname, 2, args);
+ Callback *cb = get_insert_callback(ctrl_x_mode);
+ colnr_T col = (colnr_T)callback_call_retnr(cb, 2, args);
textlock--;
State = save_State;
@@ -3940,18 +4051,18 @@ static int get_spell_compl_info(int startcol, colnr_T curs_col)
/// become invalid and needs to be fetched again.
///
/// @return OK on success.
-static int compl_get_info(char_u *line, int startcol, colnr_T curs_col, bool *line_invalid)
+static int compl_get_info(char *line, int startcol, colnr_T curs_col, bool *line_invalid)
{
if (ctrl_x_mode_normal()
|| ((ctrl_x_mode & CTRL_X_WANT_IDENT)
&& !thesaurus_func_complete(ctrl_x_mode))) {
- return get_normal_compl_info((char *)line, startcol, curs_col);
+ return get_normal_compl_info(line, startcol, curs_col);
} else if (ctrl_x_mode_line_or_eval()) {
- return get_wholeline_compl_info((char *)line, curs_col);
+ return get_wholeline_compl_info(line, curs_col);
} else if (ctrl_x_mode_files()) {
return get_filename_compl_info(line, startcol, curs_col);
} else if (ctrl_x_mode == CTRL_X_CMDLINE) {
- return get_cmdline_compl_info((char *)line, curs_col);
+ return get_cmdline_compl_info(line, curs_col);
} else if (ctrl_x_mode_function() || ctrl_x_mode_omni()
|| thesaurus_func_complete(ctrl_x_mode)) {
if (get_userdefined_compl_info(curs_col) == FAIL) {
@@ -3979,7 +4090,7 @@ static int compl_get_info(char_u *line, int startcol, colnr_T curs_col, bool *li
/// the same line as the cursor then fix it (the line has been split because it
/// was longer than 'tw'). if SOL is set then skip the previous pattern, a word
/// at the beginning of the line has been inserted, we'll look for that.
-static void ins_compl_continue_search(char_u *line)
+static void ins_compl_continue_search(char *line)
{
// it is a continued search
compl_cont_status &= ~CONT_INTRPT; // remove INTRPT
@@ -3991,7 +4102,7 @@ static void ins_compl_continue_search(char_u *line)
// first non_blank in the line, if it is not a wordchar
// include it to get a better pattern, but then we don't
// want the "\\<" prefix, check it below.
- compl_col = (colnr_T)getwhitecols((char *)line);
+ compl_col = (colnr_T)getwhitecols(line);
compl_startpos.col = compl_col;
compl_startpos.lnum = curwin->w_cursor.lnum;
compl_cont_status &= ~CONT_SOL; // clear SOL if present
@@ -4001,9 +4112,7 @@ static void ins_compl_continue_search(char_u *line)
// mode but first we need to redefine compl_startpos
if (compl_cont_status & CONT_S_IPOS) {
compl_cont_status |= CONT_SOL;
- compl_startpos.col = (colnr_T)((char_u *)skipwhite((char *)line
- + compl_length
- + compl_startpos.col) - line);
+ compl_startpos.col = (colnr_T)(skipwhite(line + compl_length + compl_startpos.col) - line);
}
compl_col = compl_startpos.col;
}
@@ -4050,7 +4159,7 @@ static int ins_compl_start(void)
&& compl_cont_mode == ctrl_x_mode) {
// this same ctrl-x_mode was interrupted previously. Continue the
// completion.
- ins_compl_continue_search((char_u *)line);
+ ins_compl_continue_search(line);
} else {
compl_cont_status &= CONT_LOCAL;
}
@@ -4070,7 +4179,7 @@ static int ins_compl_start(void)
// Work out completion pattern and original text -- webb
bool line_invalid = false;
- if (compl_get_info((char_u *)line, startcol, curs_col, &line_invalid) == FAIL) {
+ if (compl_get_info(line, startcol, curs_col, &line_invalid) == FAIL) {
if (ctrl_x_mode_function() || ctrl_x_mode_omni()
|| thesaurus_func_complete(ctrl_x_mode)) {
// restore did_ai, so that adding comment leader works
@@ -4169,18 +4278,18 @@ static void ins_compl_show_statusmsg(void)
if (compl_curr_match->cp_number != -1) {
// Space for 10 text chars. + 2x10-digit no.s = 31.
// Translations may need more than twice that.
- static char_u match_ref[81];
+ static char match_ref[81];
if (compl_matches > 0) {
- vim_snprintf((char *)match_ref, sizeof(match_ref),
+ vim_snprintf(match_ref, sizeof(match_ref),
_("match %d of %d"),
compl_curr_match->cp_number, compl_matches);
} else {
- vim_snprintf((char *)match_ref, sizeof(match_ref),
+ vim_snprintf(match_ref, sizeof(match_ref),
_("match %d"),
compl_curr_match->cp_number);
}
- edit_submode_extra = (char *)match_ref;
+ edit_submode_extra = match_ref;
edit_submode_highl = HLF_R;
if (dollar_vcol >= 0) {
curs_columns(curwin, false);
@@ -4304,7 +4413,7 @@ static void show_pum(int prev_w_wrow, int prev_w_leftcol)
// If dest is not NULL the chars. are copied there quoting (with
// a backslash) the metachars, and dest would be NUL terminated.
// Returns the length (needed) of dest
-static unsigned quote_meta(char_u *dest, char_u *src, int len)
+static unsigned quote_meta(char *dest, char *src, int len)
{
unsigned m = (unsigned)len + 1; // one extra for the NUL
@@ -4318,7 +4427,7 @@ static unsigned quote_meta(char_u *dest, char_u *src, int len)
}
FALLTHROUGH;
case '~':
- if (!p_magic) { // quote these only if magic is set
+ if (!magic_isset()) { // quote these only if magic is set
break;
}
FALLTHROUGH;
@@ -4339,7 +4448,7 @@ static unsigned quote_meta(char_u *dest, char_u *src, int len)
*dest++ = *src;
}
// Copy remaining bytes of a multibyte character.
- const int mb_len = utfc_ptr2len((char *)src) - 1;
+ const int mb_len = utfc_ptr2len(src) - 1;
if (mb_len > 0 && len >= mb_len) {
for (int i = 0; i < mb_len; i++) {
len--;
@@ -4361,6 +4470,9 @@ static unsigned quote_meta(char_u *dest, char_u *src, int len)
void free_insexpand_stuff(void)
{
XFREE_CLEAR(compl_orig_text);
+ callback_free(&cfu_cb);
+ callback_free(&ofu_cb);
+ callback_free(&tsrfu_cb);
}
#endif