Mercurial > vim
comparison src/insexpand.c @ 23772:f5225486d3de v8.2.2427
patch 8.2.2427: can still switch windows for 'completefunc'
Commit: https://github.com/vim/vim/commit/3eb6bd9c2b36dcce471bfb543c8d5488f1dc17a4
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Jan 29 21:47:24 2021 +0100
patch 8.2.2427: can still switch windows for 'completefunc'
Problem: Can still switch windows for 'completefunc'.
Solution: Also disallow switching windows for other completions.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 29 Jan 2021 22:00:04 +0100 |
parents | 385d33dfb7df |
children | 44e42eac77cb |
comparison
equal
deleted
inserted
replaced
23771:a61f1193e85c | 23772:f5225486d3de |
---|---|
119 # define CP_EQUAL 8 // ins_compl_equal() always returns TRUE | 119 # define CP_EQUAL 8 // ins_compl_equal() always returns TRUE |
120 # define CP_ICASE 16 // ins_compl_equal() ignores case | 120 # define CP_ICASE 16 // ins_compl_equal() ignores case |
121 | 121 |
122 static char e_hitend[] = N_("Hit end of paragraph"); | 122 static char e_hitend[] = N_("Hit end of paragraph"); |
123 # ifdef FEAT_COMPL_FUNC | 123 # ifdef FEAT_COMPL_FUNC |
124 static char e_complwin[] = N_("E839: Completion function changed window"); | |
125 static char e_compldel[] = N_("E840: Completion function deleted text"); | 124 static char e_compldel[] = N_("E840: Completion function deleted text"); |
126 # endif | 125 # endif |
127 | 126 |
128 /* | 127 /* |
129 * All the current matches are stored in a list. | 128 * All the current matches are stored in a list. |
2197 list_T *matchlist = NULL; | 2196 list_T *matchlist = NULL; |
2198 dict_T *matchdict = NULL; | 2197 dict_T *matchdict = NULL; |
2199 typval_T args[3]; | 2198 typval_T args[3]; |
2200 char_u *funcname; | 2199 char_u *funcname; |
2201 pos_T pos; | 2200 pos_T pos; |
2202 win_T *curwin_save; | |
2203 buf_T *curbuf_save; | |
2204 typval_T rettv; | 2201 typval_T rettv; |
2205 int save_State = State; | 2202 int save_State = State; |
2206 | 2203 |
2207 funcname = (type == CTRL_X_FUNCTION) ? curbuf->b_p_cfu : curbuf->b_p_ofu; | 2204 funcname = (type == CTRL_X_FUNCTION) ? curbuf->b_p_cfu : curbuf->b_p_ofu; |
2208 if (*funcname == NUL) | 2205 if (*funcname == NUL) |
2214 args[1].v_type = VAR_STRING; | 2211 args[1].v_type = VAR_STRING; |
2215 args[1].vval.v_string = base != NULL ? base : (char_u *)""; | 2212 args[1].vval.v_string = base != NULL ? base : (char_u *)""; |
2216 args[2].v_type = VAR_UNKNOWN; | 2213 args[2].v_type = VAR_UNKNOWN; |
2217 | 2214 |
2218 pos = curwin->w_cursor; | 2215 pos = curwin->w_cursor; |
2219 curwin_save = curwin; | |
2220 curbuf_save = curbuf; | |
2221 // Lock the text to avoid weird things from happening. Also disallow | 2216 // Lock the text to avoid weird things from happening. Also disallow |
2222 // switching to another window, it should not be needed and may end up in | 2217 // switching to another window, it should not be needed and may end up in |
2223 // Insert mode in another buffer. | 2218 // Insert mode in another buffer. |
2224 ++textwinlock; | 2219 ++textwinlock; |
2225 | 2220 |
2244 break; | 2239 break; |
2245 } | 2240 } |
2246 } | 2241 } |
2247 --textwinlock; | 2242 --textwinlock; |
2248 | 2243 |
2249 if (curwin_save != curwin || curbuf_save != curbuf) | |
2250 { | |
2251 emsg(_(e_complwin)); | |
2252 goto theend; | |
2253 } | |
2254 curwin->w_cursor = pos; // restore the cursor position | 2244 curwin->w_cursor = pos; // restore the cursor position |
2255 validate_cursor(); | 2245 validate_cursor(); |
2256 if (!EQUAL_POS(curwin->w_cursor, pos)) | 2246 if (!EQUAL_POS(curwin->w_cursor, pos)) |
2257 { | 2247 { |
2258 emsg(_(e_compldel)); | 2248 emsg(_(e_compldel)); |
3841 // set to 1 to obtain the length of text to use for completion. | 3831 // set to 1 to obtain the length of text to use for completion. |
3842 typval_T args[3]; | 3832 typval_T args[3]; |
3843 int col; | 3833 int col; |
3844 char_u *funcname; | 3834 char_u *funcname; |
3845 pos_T pos; | 3835 pos_T pos; |
3846 win_T *curwin_save; | |
3847 buf_T *curbuf_save; | |
3848 int save_State = State; | 3836 int save_State = State; |
3849 | 3837 |
3850 // Call 'completefunc' or 'omnifunc' and get pattern length as a | 3838 // Call 'completefunc' or 'omnifunc' and get pattern length as a |
3851 // string | 3839 // string |
3852 funcname = ctrl_x_mode == CTRL_X_FUNCTION | 3840 funcname = ctrl_x_mode == CTRL_X_FUNCTION |
3864 args[0].vval.v_number = 1; | 3852 args[0].vval.v_number = 1; |
3865 args[1].v_type = VAR_STRING; | 3853 args[1].v_type = VAR_STRING; |
3866 args[1].vval.v_string = (char_u *)""; | 3854 args[1].vval.v_string = (char_u *)""; |
3867 args[2].v_type = VAR_UNKNOWN; | 3855 args[2].v_type = VAR_UNKNOWN; |
3868 pos = curwin->w_cursor; | 3856 pos = curwin->w_cursor; |
3869 curwin_save = curwin; | 3857 ++textwinlock; |
3870 curbuf_save = curbuf; | |
3871 col = call_func_retnr(funcname, 2, args); | 3858 col = call_func_retnr(funcname, 2, args); |
3859 --textwinlock; | |
3872 | 3860 |
3873 State = save_State; | 3861 State = save_State; |
3874 if (curwin_save != curwin || curbuf_save != curbuf) | |
3875 { | |
3876 emsg(_(e_complwin)); | |
3877 return FAIL; | |
3878 } | |
3879 curwin->w_cursor = pos; // restore the cursor position | 3862 curwin->w_cursor = pos; // restore the cursor position |
3880 validate_cursor(); | 3863 validate_cursor(); |
3881 if (!EQUAL_POS(curwin->w_cursor, pos)) | 3864 if (!EQUAL_POS(curwin->w_cursor, pos)) |
3882 { | 3865 { |
3883 emsg(_(e_compldel)); | 3866 emsg(_(e_compldel)); |