comparison src/insexpand.c @ 20118:252d2bb90394 v8.2.0614

patch 8.2.0614: get ml_get error when deleting a line in 'completefunc' Commit: https://github.com/vim/vim/commit/ff06f283e3e4b3ec43012dd3b83f8454c98f6639 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Apr 21 22:01:14 2020 +0200 patch 8.2.0614: get ml_get error when deleting a line in 'completefunc' Problem: Get ml_get error when deleting a line in 'completefunc'. (Yegappan Lakshmanan) Solution: Lock the text while evaluating 'completefunc'.
author Bram Moolenaar <Bram@vim.org>
date Tue, 21 Apr 2020 22:15:04 +0200
parents aadd1cae2ff5
children 06a1dd50463e
comparison
equal deleted inserted replaced
20117:60a0e7ed241d 20118:252d2bb90394
2215 args[2].v_type = VAR_UNKNOWN; 2215 args[2].v_type = VAR_UNKNOWN;
2216 2216
2217 pos = curwin->w_cursor; 2217 pos = curwin->w_cursor;
2218 curwin_save = curwin; 2218 curwin_save = curwin;
2219 curbuf_save = curbuf; 2219 curbuf_save = curbuf;
2220 // Lock the text to avoid weird things from happening.
2221 ++textlock;
2220 2222
2221 // Call a function, which returns a list or dict. 2223 // Call a function, which returns a list or dict.
2222 if (call_vim_function(funcname, 2, args, &rettv) == OK) 2224 if (call_vim_function(funcname, 2, args, &rettv) == OK)
2223 { 2225 {
2224 switch (rettv.v_type) 2226 switch (rettv.v_type)
2237 // TODO: Give error message? 2239 // TODO: Give error message?
2238 clear_tv(&rettv); 2240 clear_tv(&rettv);
2239 break; 2241 break;
2240 } 2242 }
2241 } 2243 }
2244 --textlock;
2242 2245
2243 if (curwin_save != curwin || curbuf_save != curbuf) 2246 if (curwin_save != curwin || curbuf_save != curbuf)
2244 { 2247 {
2245 emsg(_(e_complwin)); 2248 emsg(_(e_complwin));
2246 goto theend; 2249 goto theend;
2429 */ 2432 */
2430 void 2433 void
2431 f_complete(typval_T *argvars, typval_T *rettv UNUSED) 2434 f_complete(typval_T *argvars, typval_T *rettv UNUSED)
2432 { 2435 {
2433 int startcol; 2436 int startcol;
2437 int save_textlock = textlock;
2434 2438
2435 if ((State & INSERT) == 0) 2439 if ((State & INSERT) == 0)
2436 { 2440 {
2437 emsg(_("E785: complete() can only be used in Insert mode")); 2441 emsg(_("E785: complete() can only be used in Insert mode"));
2438 return; 2442 return;
2439 } 2443 }
2444
2445 // "textlock" is set when evaluating 'completefunc' but we can change text
2446 // here.
2447 textlock = 0;
2440 2448
2441 // Check for undo allowed here, because if something was already inserted 2449 // Check for undo allowed here, because if something was already inserted
2442 // the line was already saved for undo and this check isn't done. 2450 // the line was already saved for undo and this check isn't done.
2443 if (!undo_allowed()) 2451 if (!undo_allowed())
2444 return; 2452 return;
2445 2453
2446 if (argvars[1].v_type != VAR_LIST || argvars[1].vval.v_list == NULL) 2454 if (argvars[1].v_type != VAR_LIST || argvars[1].vval.v_list == NULL)
2447 {
2448 emsg(_(e_invarg)); 2455 emsg(_(e_invarg));
2449 return; 2456 else
2450 } 2457 {
2451 2458 startcol = (int)tv_get_number_chk(&argvars[0], NULL);
2452 startcol = (int)tv_get_number_chk(&argvars[0], NULL); 2459 if (startcol > 0)
2453 if (startcol <= 0) 2460 set_completion(startcol - 1, argvars[1].vval.v_list);
2454 return; 2461 }
2455 2462 textlock = save_textlock;
2456 set_completion(startcol - 1, argvars[1].vval.v_list);
2457 } 2463 }
2458 2464
2459 /* 2465 /*
2460 * "complete_add()" function 2466 * "complete_add()" function
2461 */ 2467 */