Mercurial > vim
comparison src/insexpand.c @ 17704:73a93aae5f68 v8.1.1849
patch 8.1.1849
commit https://github.com/vim/vim/commit/9bca58f36d1f6a2ac0e4022caa5f355d39357a05
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Aug 15 21:31:52 2019 +0200
patch 8.1.1849
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 15 Aug 2019 21:45:04 +0200 |
parents | 77c3f6428b6c |
children | b423bd231f33 |
comparison
equal
deleted
inserted
replaced
17703:6d74651e8dca | 17704:73a93aae5f68 |
---|---|
857 /* | 857 /* |
858 * Start completion for the complete() function. | 858 * Start completion for the complete() function. |
859 * "startcol" is where the matched text starts (1 is first column). | 859 * "startcol" is where the matched text starts (1 is first column). |
860 * "list" is the list of matches. | 860 * "list" is the list of matches. |
861 */ | 861 */ |
862 void | 862 static void |
863 set_completion(colnr_T startcol, list_T *list) | 863 set_completion(colnr_T startcol, list_T *list) |
864 { | 864 { |
865 int save_w_wrow = curwin->w_wrow; | 865 int save_w_wrow = curwin->w_wrow; |
866 int save_w_leftcol = curwin->w_leftcol; | 866 int save_w_leftcol = curwin->w_leftcol; |
867 int flags = CP_ORIGINAL_TEXT; | 867 int flags = CP_ORIGINAL_TEXT; |
1520 } | 1520 } |
1521 | 1521 |
1522 /* | 1522 /* |
1523 * Get complete information | 1523 * Get complete information |
1524 */ | 1524 */ |
1525 void | 1525 static void |
1526 get_complete_info(list_T *what_list, dict_T *retdict) | 1526 get_complete_info(list_T *what_list, dict_T *retdict) |
1527 { | 1527 { |
1528 int ret = OK; | 1528 int ret = OK; |
1529 listitem_T *item; | 1529 listitem_T *item; |
1530 #define CI_WHAT_MODE 0x01 | 1530 #define CI_WHAT_MODE 0x01 |
2351 } | 2351 } |
2352 #endif // FEAT_COMPL_FUNC | 2352 #endif // FEAT_COMPL_FUNC |
2353 | 2353 |
2354 #if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL) || defined(PROTO) | 2354 #if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL) || defined(PROTO) |
2355 /* | 2355 /* |
2356 * Add completions from a list. | |
2357 */ | |
2358 static void | |
2359 ins_compl_add_list(list_T *list) | |
2360 { | |
2361 listitem_T *li; | |
2362 int dir = compl_direction; | |
2363 | |
2364 // Go through the List with matches and add each of them. | |
2365 for (li = list->lv_first; li != NULL; li = li->li_next) | |
2366 { | |
2367 if (ins_compl_add_tv(&li->li_tv, dir) == OK) | |
2368 // if dir was BACKWARD then honor it just once | |
2369 dir = FORWARD; | |
2370 else if (did_emsg) | |
2371 break; | |
2372 } | |
2373 } | |
2374 | |
2375 /* | |
2376 * Add completions from a dict. | |
2377 */ | |
2378 static void | |
2379 ins_compl_add_dict(dict_T *dict) | |
2380 { | |
2381 dictitem_T *di_refresh; | |
2382 dictitem_T *di_words; | |
2383 | |
2384 // Check for optional "refresh" item. | |
2385 compl_opt_refresh_always = FALSE; | |
2386 di_refresh = dict_find(dict, (char_u *)"refresh", 7); | |
2387 if (di_refresh != NULL && di_refresh->di_tv.v_type == VAR_STRING) | |
2388 { | |
2389 char_u *v = di_refresh->di_tv.vval.v_string; | |
2390 | |
2391 if (v != NULL && STRCMP(v, (char_u *)"always") == 0) | |
2392 compl_opt_refresh_always = TRUE; | |
2393 } | |
2394 | |
2395 // Add completions from a "words" list. | |
2396 di_words = dict_find(dict, (char_u *)"words", 5); | |
2397 if (di_words != NULL && di_words->di_tv.v_type == VAR_LIST) | |
2398 ins_compl_add_list(di_words->di_tv.vval.v_list); | |
2399 } | |
2400 | |
2401 /* | |
2402 * Add a match to the list of matches from a typeval_T. | 2356 * Add a match to the list of matches from a typeval_T. |
2403 * If the given string is already in the list of completions, then return | 2357 * If the given string is already in the list of completions, then return |
2404 * NOTDONE, otherwise add it to the list and return OK. If there is an error, | 2358 * NOTDONE, otherwise add it to the list and return OK. If there is an error, |
2405 * maybe because alloc() returns NULL, then FAIL is returned. | 2359 * maybe because alloc() returns NULL, then FAIL is returned. |
2406 */ | 2360 */ |
2407 int | 2361 static int |
2408 ins_compl_add_tv(typval_T *tv, int dir) | 2362 ins_compl_add_tv(typval_T *tv, int dir) |
2409 { | 2363 { |
2410 char_u *word; | 2364 char_u *word; |
2411 int dup = FALSE; | 2365 int dup = FALSE; |
2412 int empty = FALSE; | 2366 int empty = FALSE; |
2443 vim_memset(cptext, 0, sizeof(cptext)); | 2397 vim_memset(cptext, 0, sizeof(cptext)); |
2444 } | 2398 } |
2445 if (word == NULL || (!empty && *word == NUL)) | 2399 if (word == NULL || (!empty && *word == NUL)) |
2446 return FAIL; | 2400 return FAIL; |
2447 return ins_compl_add(word, -1, NULL, cptext, dir, flags, dup); | 2401 return ins_compl_add(word, -1, NULL, cptext, dir, flags, dup); |
2402 } | |
2403 | |
2404 /* | |
2405 * Add completions from a list. | |
2406 */ | |
2407 static void | |
2408 ins_compl_add_list(list_T *list) | |
2409 { | |
2410 listitem_T *li; | |
2411 int dir = compl_direction; | |
2412 | |
2413 // Go through the List with matches and add each of them. | |
2414 for (li = list->lv_first; li != NULL; li = li->li_next) | |
2415 { | |
2416 if (ins_compl_add_tv(&li->li_tv, dir) == OK) | |
2417 // if dir was BACKWARD then honor it just once | |
2418 dir = FORWARD; | |
2419 else if (did_emsg) | |
2420 break; | |
2421 } | |
2422 } | |
2423 | |
2424 /* | |
2425 * Add completions from a dict. | |
2426 */ | |
2427 static void | |
2428 ins_compl_add_dict(dict_T *dict) | |
2429 { | |
2430 dictitem_T *di_refresh; | |
2431 dictitem_T *di_words; | |
2432 | |
2433 // Check for optional "refresh" item. | |
2434 compl_opt_refresh_always = FALSE; | |
2435 di_refresh = dict_find(dict, (char_u *)"refresh", 7); | |
2436 if (di_refresh != NULL && di_refresh->di_tv.v_type == VAR_STRING) | |
2437 { | |
2438 char_u *v = di_refresh->di_tv.vval.v_string; | |
2439 | |
2440 if (v != NULL && STRCMP(v, (char_u *)"always") == 0) | |
2441 compl_opt_refresh_always = TRUE; | |
2442 } | |
2443 | |
2444 // Add completions from a "words" list. | |
2445 di_words = dict_find(dict, (char_u *)"words", 5); | |
2446 if (di_words != NULL && di_words->di_tv.v_type == VAR_LIST) | |
2447 ins_compl_add_list(di_words->di_tv.vval.v_list); | |
2448 } | |
2449 | |
2450 /* | |
2451 * "complete()" function | |
2452 */ | |
2453 void | |
2454 f_complete(typval_T *argvars, typval_T *rettv UNUSED) | |
2455 { | |
2456 int startcol; | |
2457 | |
2458 if ((State & INSERT) == 0) | |
2459 { | |
2460 emsg(_("E785: complete() can only be used in Insert mode")); | |
2461 return; | |
2462 } | |
2463 | |
2464 // Check for undo allowed here, because if something was already inserted | |
2465 // the line was already saved for undo and this check isn't done. | |
2466 if (!undo_allowed()) | |
2467 return; | |
2468 | |
2469 if (argvars[1].v_type != VAR_LIST || argvars[1].vval.v_list == NULL) | |
2470 { | |
2471 emsg(_(e_invarg)); | |
2472 return; | |
2473 } | |
2474 | |
2475 startcol = (int)tv_get_number_chk(&argvars[0], NULL); | |
2476 if (startcol <= 0) | |
2477 return; | |
2478 | |
2479 set_completion(startcol - 1, argvars[1].vval.v_list); | |
2480 } | |
2481 | |
2482 /* | |
2483 * "complete_add()" function | |
2484 */ | |
2485 void | |
2486 f_complete_add(typval_T *argvars, typval_T *rettv) | |
2487 { | |
2488 rettv->vval.v_number = ins_compl_add_tv(&argvars[0], 0); | |
2489 } | |
2490 | |
2491 /* | |
2492 * "complete_check()" function | |
2493 */ | |
2494 void | |
2495 f_complete_check(typval_T *argvars UNUSED, typval_T *rettv) | |
2496 { | |
2497 int saved = RedrawingDisabled; | |
2498 | |
2499 RedrawingDisabled = 0; | |
2500 ins_compl_check_keys(0, TRUE); | |
2501 rettv->vval.v_number = ins_compl_interrupted(); | |
2502 RedrawingDisabled = saved; | |
2503 } | |
2504 | |
2505 /* | |
2506 * "complete_info()" function | |
2507 */ | |
2508 void | |
2509 f_complete_info(typval_T *argvars, typval_T *rettv) | |
2510 { | |
2511 list_T *what_list = NULL; | |
2512 | |
2513 if (rettv_dict_alloc(rettv) != OK) | |
2514 return; | |
2515 | |
2516 if (argvars[0].v_type != VAR_UNKNOWN) | |
2517 { | |
2518 if (argvars[0].v_type != VAR_LIST) | |
2519 { | |
2520 emsg(_(e_listreq)); | |
2521 return; | |
2522 } | |
2523 what_list = argvars[0].vval.v_list; | |
2524 } | |
2525 get_complete_info(what_list, rettv->vval.v_dict); | |
2448 } | 2526 } |
2449 #endif | 2527 #endif |
2450 | 2528 |
2451 /* | 2529 /* |
2452 * Get the next expansion(s), using "compl_pattern". | 2530 * Get the next expansion(s), using "compl_pattern". |