From cbec765915a8a76e86ac79dde8eeae663b019882 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Sat, 16 Oct 2021 18:40:57 +0200 Subject: vim-patch:8.2.3520: cannot define a function for thesaurus completion Problem: Cannot define a function for thesaurus completion. Solution: Add 'thesaurusfunc'. (Yegappan Lakshmanan, closes vim/vim#8987, closes 8950) https://github.com/vim/vim/commit/160e994d768d03a3c826b58115cde94df8fce607 --- src/nvim/buffer.c | 1 + src/nvim/buffer_defs.h | 1 + src/nvim/edit.c | 78 ++++++++++++++++++++++++++---------------- src/nvim/option.c | 4 +++ src/nvim/option_defs.h | 1 + src/nvim/options.lua | 9 +++++ src/nvim/testdir/test_edit.vim | 42 +++++++++++++++++++++++ 7 files changed, 107 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 826a197454..cfbbc5f9c5 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1967,6 +1967,7 @@ void free_buf_options(buf_T *buf, int free_p_ff) clear_string_option(&buf->b_p_cpt); clear_string_option(&buf->b_p_cfu); clear_string_option(&buf->b_p_ofu); + clear_string_option(&buf->b_p_thsfu); clear_string_option(&buf->b_p_gp); clear_string_option(&buf->b_p_mp); clear_string_option(&buf->b_p_efm); diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index 19b0a3c5c6..db12942bbd 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -698,6 +698,7 @@ struct file_buffer { #endif char_u *b_p_cfu; ///< 'completefunc' char_u *b_p_ofu; ///< 'omnifunc' + char_u *b_p_thsfu; ///< 'thesaurusfunc' char_u *b_p_tfu; ///< 'tagfunc' int b_p_eol; ///< 'endofline' int b_p_fixeol; ///< 'fixendofline' diff --git a/src/nvim/edit.c b/src/nvim/edit.c index b3a08971e9..29ce9ae3ec 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -2071,7 +2071,7 @@ static bool check_compl_option(bool dict_opt) { if (dict_opt ? (*curbuf->b_p_dict == NUL && *p_dict == NUL && !curwin->w_p_spell) - : (*curbuf->b_p_tsr == NUL && *p_tsr == NUL)) { + : (*curbuf->b_p_tsr == NUL && *p_tsr == NUL && *curbuf->b_p_thsfu == NUL)) { ctrl_x_mode = CTRL_X_NORMAL; edit_submode = NULL; msg_attr((dict_opt @@ -2544,7 +2544,7 @@ static void ins_compl_longest_match(compl_T *match) * Add an array of matches to the list of matches. * Frees matches[]. */ -static void ins_compl_add_matches(int num_matches, char_u **matches, int icase) +static void ins_compl_add_matches(int num_matches, char_u * *matches, int icase) FUNC_ATTR_NONNULL_ALL { int add_r = OK; @@ -2899,7 +2899,7 @@ static void ins_compl_dictionaries(char_u *dict_start, char_u *pat, int flags, i char_u *ptr; char_u *buf; regmatch_T regmatch; - char_u **files; + char_u * *files; int count; int save_p_scs; Direction dir = compl_direction; @@ -2990,7 +2990,7 @@ theend: xfree(buf); } -static void ins_compl_files(int count, char_u **files, int thesaurus, int flags, +static void ins_compl_files(int count, char_u * *files, int thesaurus, int flags, regmatch_T *regmatch, char_u *buf, Direction *dir) FUNC_ATTR_NONNULL_ARG(2, 7) { @@ -3924,6 +3924,20 @@ static buf_T *ins_compl_next_buf(buf_T *buf, int flag) } +/// Get the user-defined completion function name for completion 'type' +static char_u *get_complete_funcname(int type) { + switch (type) { + case CTRL_X_FUNCTION: + return curbuf->b_p_cfu; + case CTRL_X_OMNI: + return curbuf->b_p_ofu; + case CTRL_X_THESAURUS: + return curbuf->b_p_thsfu; + default: + return (char_u *)""; + } +} + /// Execute user defined complete function 'completefunc' or 'omnifunc', and /// get matches in "matches". /// @@ -3940,7 +3954,7 @@ static void expand_by_function(int type, char_u *base) const int save_State = State; assert(curbuf != NULL); - funcname = (type == CTRL_X_FUNCTION) ? curbuf->b_p_cfu : curbuf->b_p_ofu; + funcname = get_complete_funcname(type); if (*funcname == NUL) { return; } @@ -4096,7 +4110,15 @@ int ins_compl_add_tv(typval_T *const tv, const Direction dir, bool fast) return FAIL; } return ins_compl_add((char_u *)word, -1, NULL, - (char_u **)cptext, true, &user_data, dir, flags, dup); + (char_u * *)cptext, true, &user_data, dir, flags, dup); +} + +/// Returns TRUE when using a user-defined function for thesaurus completion. +static int thesaurus_func_complete(int type) +{ + return (type == CTRL_X_THESAURUS + && curbuf->b_p_thsfu != NULL + && *curbuf->b_p_thsfu != NUL); } // Get the next expansion(s), using "compl_pattern". @@ -4116,7 +4138,7 @@ static int ins_compl_get_exp(pos_T *ini) static buf_T *ins_buf = NULL; // buffer being scanned pos_T *pos; - char_u **matches; + char_u * *matches; int save_p_scs; bool save_p_ws; int save_p_ic; @@ -4272,17 +4294,17 @@ static int ins_compl_get_exp(pos_T *ini) case CTRL_X_DICTIONARY: case CTRL_X_THESAURUS: - ins_compl_dictionaries(dict != NULL ? dict - : (type == CTRL_X_THESAURUS - ? (*curbuf->b_p_tsr == NUL - ? p_tsr - : curbuf->b_p_tsr) - : (*curbuf->b_p_dict == NUL - ? p_dict - : curbuf->b_p_dict)), - compl_pattern, - dict != NULL ? dict_f - : 0, type == CTRL_X_THESAURUS); + if (thesaurus_func_complete(type)) { + expand_by_function(type, compl_pattern); + } else { + ins_compl_dictionaries(dict != NULL ? dict + : (type == CTRL_X_THESAURUS + ? (*curbuf->b_p_tsr == NUL ? p_tsr : curbuf->b_p_tsr) + : (*curbuf->b_p_dict == + NUL ? p_dict : curbuf->b_p_dict)), + compl_pattern, + dict != NULL ? dict_f : 0, type == CTRL_X_THESAURUS); + } dict = NULL; break; @@ -5095,7 +5117,9 @@ static int ins_complete(int c, bool enable_pum) } // Work out completion pattern and original text -- webb - if (ctrl_x_mode == CTRL_X_NORMAL || (ctrl_x_mode & CTRL_X_WANT_IDENT)) { + if (ctrl_x_mode == CTRL_X_NORMAL + || (ctrl_x_mode & CTRL_X_WANT_IDENT + && !thesaurus_func_complete(ctrl_x_mode))) { if ((compl_cont_status & CONT_SOL) || ctrl_x_mode == CTRL_X_PATH_DEFINES) { if (!(compl_cont_status & CONT_ADDING)) { @@ -5206,22 +5230,18 @@ static int ins_complete(int c, bool enable_pum) compl_col = (int)(compl_xp.xp_pattern - compl_pattern); } compl_length = curs_col - compl_col; - } else if (ctrl_x_mode == CTRL_X_FUNCTION || ctrl_x_mode == - CTRL_X_OMNI) { - /* - * Call user defined function 'completefunc' with "a:findstart" - * set to 1 to obtain the length of text to use for completion. - */ + } else if (ctrl_x_mode == CTRL_X_FUNCTION || ctrl_x_mode == CTRL_X_OMNI + || thesaurus_func_complete(ctrl_x_mode)) { + // Call user defined function 'completefunc' with "a:findstart" + // set to 1 to obtain the length of text to use for completion. char_u *funcname; pos_T pos; win_T *curwin_save; buf_T *curbuf_save; const int save_State = State; - /* Call 'completefunc' or 'omnifunc' and get pattern length as a - * string */ - funcname = ctrl_x_mode == CTRL_X_FUNCTION - ? curbuf->b_p_cfu : curbuf->b_p_ofu; + // Call 'completefunc' or 'omnifunc' and get pattern length as a string + funcname = get_complete_funcname(ctrl_x_mode); if (*funcname == NUL) { EMSG2(_(e_notset), ctrl_x_mode == CTRL_X_FUNCTION ? "completefunc" : "omnifunc"); diff --git a/src/nvim/option.c b/src/nvim/option.c index a8b86ec0a0..b6b1c4b8a2 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -139,6 +139,7 @@ static char_u *p_cpt; static char_u *p_cfu; static char_u *p_ofu; static char_u *p_tfu; +static char_u *p_thsfu; static int p_eol; static int p_fixeol; static int p_et; @@ -5915,6 +5916,8 @@ static char_u *get_varp(vimoption_T *p) return (char_u *)&(curbuf->b_p_sw); case PV_TFU: return (char_u *)&(curbuf->b_p_tfu); + case PV_THSFU: + return (char_u *)&(curbuf->b_p_thsfu); case PV_TS: return (char_u *)&(curbuf->b_p_ts); case PV_TW: @@ -6184,6 +6187,7 @@ void buf_copy_options(buf_T *buf, int flags) #endif buf->b_p_cfu = vim_strsave(p_cfu); buf->b_p_ofu = vim_strsave(p_ofu); + buf->b_p_thsfu = vim_strsave(p_thsfu); buf->b_p_tfu = vim_strsave(p_tfu); buf->b_p_sts = p_sts; buf->b_p_sts_nopaste = p_sts_nopaste; diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index 441d29cd9f..f667e0f63c 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -826,6 +826,7 @@ enum { BV_SW, BV_SWF, BV_TFU, + BV_THSFU, BV_TAGS, BV_TC, BV_TS, diff --git a/src/nvim/options.lua b/src/nvim/options.lua index 8b9cdefd57..a4a80a754c 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -2535,6 +2535,15 @@ return { varname='p_tsr', defaults={if_true=""} }, + { + full_name='thesaurusfunc', abbreviation='tsrfu', + short_desc=N_("function used for thesaurus completion"), + type='string', scope={'buffer'}, + secure=true, + alloced=true, + varname='p_thsfu', + defaults={if_true=""} + }, { full_name='tildeop', abbreviation='top', short_desc=N_("tilde command \"~\" behaves like an operator"), diff --git a/src/nvim/testdir/test_edit.vim b/src/nvim/testdir/test_edit.vim index 2b389c015f..9a35129232 100644 --- a/src/nvim/testdir/test_edit.vim +++ b/src/nvim/testdir/test_edit.vim @@ -870,6 +870,48 @@ func Test_edit_CTRL_T() bw! endfunc +" Test 'thesaurusfunc' +func MyThesaurus(findstart, base) + let mythesaurus = [ + \ #{word: "happy", + \ synonyms: "cheerful,blissful,flying high,looking good,peppy"}, + \ #{word: "kind", + \ synonyms: "amiable,bleeding-heart,heart in right place"}] + if a:findstart + " locate the start of the word + let line = getline('.') + let start = col('.') - 1 + while start > 0 && line[start - 1] =~ '\a' + let start -= 1 + endwhile + return start + else + " find strings matching with "a:base" + let res = [] + for w in mythesaurus + if w.word =~ '^' . a:base + call add(res, w.word) + call extend(res, split(w.synonyms, ",")) + endif + endfor + return res + endif +endfunc + +func Test_thesaurus_func() + new + set thesaurus= + set thesaurusfunc=MyThesaurus + call setline(1, "an ki") + call cursor(1, 1) + call feedkeys("A\\\\\", 'tnix') + call assert_equal(['an amiable', ''], getline(1, '$')) + set thesaurusfunc=NonExistingFunc + call assert_fails("normal $a\\", 'E117:') + set thesaurusfunc& + %bw! +endfunc + func Test_edit_CTRL_U() " Test 'completefunc' new -- cgit From 36ff5976b9fee823892a1abcfb484cf3f162bb3b Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Sun, 17 Oct 2021 16:22:28 +0200 Subject: vim-patch:8.2.3521: options completion test fails Problem: Options completion test fails. Solution: Add 'thesaurusfunc' to the results. https://github.com/vim/vim/commit/abdcfd1c837e244065d4fe04c7a78abae5af3f7e --- src/nvim/testdir/test_options.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim index 72c151142d..41c689849b 100644 --- a/src/nvim/testdir/test_options.vim +++ b/src/nvim/testdir/test_options.vim @@ -209,7 +209,7 @@ func Test_set_completion() " Expand abbreviation of options. call feedkeys(":set ts\\\"\", 'tx') - call assert_equal('"set tabstop thesaurus', @:) + call assert_equal('"set tabstop thesaurus thesaurusfunc', @:) " Expand current value call feedkeys(":set fileencodings=\\\"\", 'tx') -- cgit From b092171e7c632a2a6c8841056302ae281d993168 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Sun, 17 Oct 2021 16:24:34 +0200 Subject: vim-patch:8.2.3525: option variable name does not match option name Problem: Option variable name does not match option name. (Christ van Willigen) Solution: Rename the variable. https://github.com/vim/vim/commit/d4c4bfa0078a959ff90ef30288fd31d9d38f23d7 --- src/nvim/buffer.c | 2 +- src/nvim/buffer_defs.h | 2 +- src/nvim/edit.c | 8 ++++---- src/nvim/option.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index cfbbc5f9c5..809aa30692 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1967,7 +1967,7 @@ void free_buf_options(buf_T *buf, int free_p_ff) clear_string_option(&buf->b_p_cpt); clear_string_option(&buf->b_p_cfu); clear_string_option(&buf->b_p_ofu); - clear_string_option(&buf->b_p_thsfu); + clear_string_option(&buf->b_p_tsrfu); clear_string_option(&buf->b_p_gp); clear_string_option(&buf->b_p_mp); clear_string_option(&buf->b_p_efm); diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index db12942bbd..4f88aa8e76 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -698,7 +698,7 @@ struct file_buffer { #endif char_u *b_p_cfu; ///< 'completefunc' char_u *b_p_ofu; ///< 'omnifunc' - char_u *b_p_thsfu; ///< 'thesaurusfunc' + char_u *b_p_tsrfu; ///< 'thesaurusfunc' char_u *b_p_tfu; ///< 'tagfunc' int b_p_eol; ///< 'endofline' int b_p_fixeol; ///< 'fixendofline' diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 29ce9ae3ec..2d7b1437f7 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -2071,7 +2071,7 @@ static bool check_compl_option(bool dict_opt) { if (dict_opt ? (*curbuf->b_p_dict == NUL && *p_dict == NUL && !curwin->w_p_spell) - : (*curbuf->b_p_tsr == NUL && *p_tsr == NUL && *curbuf->b_p_thsfu == NUL)) { + : (*curbuf->b_p_tsr == NUL && *p_tsr == NUL && *curbuf->b_p_tsrfu == NUL)) { ctrl_x_mode = CTRL_X_NORMAL; edit_submode = NULL; msg_attr((dict_opt @@ -3932,7 +3932,7 @@ static char_u *get_complete_funcname(int type) { case CTRL_X_OMNI: return curbuf->b_p_ofu; case CTRL_X_THESAURUS: - return curbuf->b_p_thsfu; + return curbuf->b_p_tsrfu; default: return (char_u *)""; } @@ -4117,8 +4117,8 @@ int ins_compl_add_tv(typval_T *const tv, const Direction dir, bool fast) static int thesaurus_func_complete(int type) { return (type == CTRL_X_THESAURUS - && curbuf->b_p_thsfu != NULL - && *curbuf->b_p_thsfu != NUL); + && curbuf->b_p_tsrfu != NULL + && *curbuf->b_p_tsrfu != NUL); } // Get the next expansion(s), using "compl_pattern". diff --git a/src/nvim/option.c b/src/nvim/option.c index b6b1c4b8a2..527930f0ac 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -5916,7 +5916,7 @@ static char_u *get_varp(vimoption_T *p) return (char_u *)&(curbuf->b_p_sw); case PV_TFU: return (char_u *)&(curbuf->b_p_tfu); - case PV_THSFU: + case PV_TSRFU: return (char_u *)&(curbuf->b_p_thsfu); case PV_TS: return (char_u *)&(curbuf->b_p_ts); -- cgit From 2dc0af3a4ff16d311169ce2ecd120dd05778039c Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Sun, 17 Oct 2021 16:37:29 +0200 Subject: vim-patch:8.2.3528: 'thesaurus' and 'thesaurusfunc' do not have the same scope Problem: 'thesaurus' and 'thesaurusfunc' do not have the same scope. Solution: Make 'thesaurusfunc' global-local. https://github.com/vim/vim/commit/f4d8b76d304dabc39c06d2344cd4c7b28484811b --- src/nvim/buffer_defs.h | 2 +- src/nvim/edit.c | 24 ++++++++++++------------ src/nvim/option.c | 14 ++++++++++---- src/nvim/option_defs.h | 3 ++- src/nvim/options.lua | 4 ++-- src/nvim/testdir/test_edit.vim | 14 +++++++++++--- 6 files changed, 38 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index 4f88aa8e76..a1c5ea6924 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -698,7 +698,6 @@ struct file_buffer { #endif char_u *b_p_cfu; ///< 'completefunc' char_u *b_p_ofu; ///< 'omnifunc' - char_u *b_p_tsrfu; ///< 'thesaurusfunc' char_u *b_p_tfu; ///< 'tagfunc' int b_p_eol; ///< 'endofline' int b_p_fixeol; ///< 'fixendofline' @@ -768,6 +767,7 @@ struct file_buffer { unsigned b_tc_flags; ///< flags for 'tagcase' char_u *b_p_dict; ///< 'dictionary' local value char_u *b_p_tsr; ///< 'thesaurus' local value + char_u *b_p_tsrfu; ///< 'thesaurusfunc' local value long b_p_ul; ///< 'undolevels' local value int b_p_udf; ///< 'undofile' char_u *b_p_lw; ///< 'lispwords' local value diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 2d7b1437f7..3ea7b442c8 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -2071,7 +2071,8 @@ static bool check_compl_option(bool dict_opt) { if (dict_opt ? (*curbuf->b_p_dict == NUL && *p_dict == NUL && !curwin->w_p_spell) - : (*curbuf->b_p_tsr == NUL && *p_tsr == NUL && *curbuf->b_p_tsrfu == NUL)) { + : (*curbuf->b_p_tsr == NUL && *p_tsr == NUL + && *curbuf->b_p_tsrfu == NUL && *p_tsrfu == NUL)) { ctrl_x_mode = CTRL_X_NORMAL; edit_submode = NULL; msg_attr((dict_opt @@ -2544,7 +2545,7 @@ static void ins_compl_longest_match(compl_T *match) * Add an array of matches to the list of matches. * Frees matches[]. */ -static void ins_compl_add_matches(int num_matches, char_u * *matches, int icase) +static void ins_compl_add_matches(int num_matches, char_u **matches, int icase) FUNC_ATTR_NONNULL_ALL { int add_r = OK; @@ -2899,7 +2900,7 @@ static void ins_compl_dictionaries(char_u *dict_start, char_u *pat, int flags, i char_u *ptr; char_u *buf; regmatch_T regmatch; - char_u * *files; + char_u **files; int count; int save_p_scs; Direction dir = compl_direction; @@ -2990,7 +2991,7 @@ theend: xfree(buf); } -static void ins_compl_files(int count, char_u * *files, int thesaurus, int flags, +static void ins_compl_files(int count, char_u **files, int thesaurus, int flags, regmatch_T *regmatch, char_u *buf, Direction *dir) FUNC_ATTR_NONNULL_ARG(2, 7) { @@ -3932,7 +3933,7 @@ static char_u *get_complete_funcname(int type) { case CTRL_X_OMNI: return curbuf->b_p_ofu; case CTRL_X_THESAURUS: - return curbuf->b_p_tsrfu; + return *curbuf->b_p_tsrfu == NUL ? p_tsrfu : curbuf->b_p_tsrfu; default: return (char_u *)""; } @@ -4110,15 +4111,14 @@ int ins_compl_add_tv(typval_T *const tv, const Direction dir, bool fast) return FAIL; } return ins_compl_add((char_u *)word, -1, NULL, - (char_u * *)cptext, true, &user_data, dir, flags, dup); + (char_u **)cptext, true, &user_data, dir, flags, dup); } -/// Returns TRUE when using a user-defined function for thesaurus completion. -static int thesaurus_func_complete(int type) +/// Returns true when using a user-defined function for thesaurus completion. +static bool thesaurus_func_complete(int type) { - return (type == CTRL_X_THESAURUS - && curbuf->b_p_tsrfu != NULL - && *curbuf->b_p_tsrfu != NUL); + return type == CTRL_X_THESAURUS + && (*curbuf->b_p_tsrfu != NUL || *p_tsrfu != NUL); } // Get the next expansion(s), using "compl_pattern". @@ -4138,7 +4138,7 @@ static int ins_compl_get_exp(pos_T *ini) static buf_T *ins_buf = NULL; // buffer being scanned pos_T *pos; - char_u * *matches; + char_u **matches; int save_p_scs; bool save_p_ws; int save_p_ic; diff --git a/src/nvim/option.c b/src/nvim/option.c index 527930f0ac..f471861473 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -139,7 +139,6 @@ static char_u *p_cpt; static char_u *p_cfu; static char_u *p_ofu; static char_u *p_tfu; -static char_u *p_thsfu; static int p_eol; static int p_fixeol; static int p_et; @@ -2036,6 +2035,7 @@ void check_buf_options(buf_T *buf) check_string_option(&buf->b_p_tc); check_string_option(&buf->b_p_dict); check_string_option(&buf->b_p_tsr); + check_string_option(&buf->b_p_tsrfu); check_string_option(&buf->b_p_lw); check_string_option(&buf->b_p_bkc); check_string_option(&buf->b_p_menc); @@ -5538,6 +5538,9 @@ void unset_global_local_option(char *name, void *from) case PV_TSR: clear_string_option(&buf->b_p_tsr); break; + case PV_TSRFU: + clear_string_option(&buf->b_p_tsrfu); + break; case PV_FP: clear_string_option(&buf->b_p_fp); break; @@ -5621,6 +5624,8 @@ static char_u *get_varp_scope(vimoption_T *p, int opt_flags) return (char_u *)&(curbuf->b_p_dict); case PV_TSR: return (char_u *)&(curbuf->b_p_tsr); + case PV_TSRFU: + return (char_u *)&(curbuf->b_p_tsrfu); case PV_TFU: return (char_u *)&(curbuf->b_p_tfu); case PV_SBR: @@ -5697,6 +5702,9 @@ static char_u *get_varp(vimoption_T *p) case PV_TSR: return *curbuf->b_p_tsr != NUL ? (char_u *)&(curbuf->b_p_tsr) : p->var; + case PV_TSRFU: + return *curbuf->b_p_tsrfu != NUL + ? (char_u *)&(curbuf->b_p_tsrfu) : p->var; case PV_FP: return *curbuf->b_p_fp != NUL ? (char_u *)&(curbuf->b_p_fp) : p->var; @@ -5916,8 +5924,6 @@ static char_u *get_varp(vimoption_T *p) return (char_u *)&(curbuf->b_p_sw); case PV_TFU: return (char_u *)&(curbuf->b_p_tfu); - case PV_TSRFU: - return (char_u *)&(curbuf->b_p_thsfu); case PV_TS: return (char_u *)&(curbuf->b_p_ts); case PV_TW: @@ -6187,7 +6193,6 @@ void buf_copy_options(buf_T *buf, int flags) #endif buf->b_p_cfu = vim_strsave(p_cfu); buf->b_p_ofu = vim_strsave(p_ofu); - buf->b_p_thsfu = vim_strsave(p_thsfu); buf->b_p_tfu = vim_strsave(p_tfu); buf->b_p_sts = p_sts; buf->b_p_sts_nopaste = p_sts_nopaste; @@ -6258,6 +6263,7 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_inex = vim_strsave(p_inex); buf->b_p_dict = empty_option; buf->b_p_tsr = empty_option; + buf->b_p_tsrfu = empty_option; buf->b_p_qe = vim_strsave(p_qe); buf->b_p_udf = p_udf; buf->b_p_lw = empty_option; diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index f667e0f63c..358bfc20dc 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -686,6 +686,7 @@ EXTERN long p_titlelen; ///< 'titlelen' EXTERN char_u *p_titleold; ///< 'titleold' EXTERN char_u *p_titlestring; ///< 'titlestring' EXTERN char_u *p_tsr; ///< 'thesaurus' +EXTERN char_u *p_tsrfu; ///< 'thesaurusfunc' EXTERN int p_tgc; ///< 'termguicolors' EXTERN int p_ttimeout; ///< 'ttimeout' EXTERN long p_ttm; ///< 'ttimeoutlen' @@ -826,7 +827,7 @@ enum { BV_SW, BV_SWF, BV_TFU, - BV_THSFU, + BV_TSRFU, BV_TAGS, BV_TC, BV_TS, diff --git a/src/nvim/options.lua b/src/nvim/options.lua index a4a80a754c..71208dfc68 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -2538,10 +2538,10 @@ return { { full_name='thesaurusfunc', abbreviation='tsrfu', short_desc=N_("function used for thesaurus completion"), - type='string', scope={'buffer'}, + type='string', scope={'global', 'buffer'}, secure=true, alloced=true, - varname='p_thsfu', + varname='p_tsrfu', defaults={if_true=""} }, { diff --git a/src/nvim/testdir/test_edit.vim b/src/nvim/testdir/test_edit.vim index 9a35129232..23ad8dbfc5 100644 --- a/src/nvim/testdir/test_edit.vim +++ b/src/nvim/testdir/test_edit.vim @@ -900,16 +900,24 @@ endfunc func Test_thesaurus_func() new - set thesaurus= - set thesaurusfunc=MyThesaurus + set thesaurus=notused + set thesaurusfunc=NotUsed + setlocal thesaurusfunc=MyThesaurus call setline(1, "an ki") call cursor(1, 1) call feedkeys("A\\\\\", 'tnix') call assert_equal(['an amiable', ''], getline(1, '$')) + + setlocal thesaurusfunc=NonExistingFunc + call assert_fails("normal $a\\", 'E117:') + + setlocal thesaurusfunc= set thesaurusfunc=NonExistingFunc call assert_fails("normal $a\\", 'E117:') - set thesaurusfunc& %bw! + + set thesaurusfunc= + set thesaurus= endfunc func Test_edit_CTRL_U() -- cgit