Mercurial > vim
comparison src/insexpand.c @ 16239:5df26b29e809 v8.1.1124
patch 8.1.1124: insert completion flags are mixed up
commit https://github.com/vim/vim/commit/d9eefe3155277cec71105f52d34a76f7a3237e7f
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Apr 6 14:22:21 2019 +0200
patch 8.1.1124: insert completion flags are mixed up
Problem: Insert completion flags are mixed up.
Solution: Clean up flags use of ins_compl_add() and cp_flags.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 06 Apr 2019 14:30:04 +0200 |
parents | 56451a2677dc |
children | 0f65f2808470 |
comparison
equal
deleted
inserted
replaced
16238:85f58c613efc | 16239:5df26b29e809 |
---|---|
100 struct compl_S | 100 struct compl_S |
101 { | 101 { |
102 compl_T *cp_next; | 102 compl_T *cp_next; |
103 compl_T *cp_prev; | 103 compl_T *cp_prev; |
104 char_u *cp_str; // matched text | 104 char_u *cp_str; // matched text |
105 char cp_icase; // TRUE or FALSE: ignore case | |
106 char cp_equal; // TRUE or FALSE: ins_compl_equal always ok | |
107 char_u *(cp_text[CPT_COUNT]); // text for the menu | 105 char_u *(cp_text[CPT_COUNT]); // text for the menu |
108 char_u *cp_fname; // file containing the match, allocated when | 106 char_u *cp_fname; // file containing the match, allocated when |
109 // cp_flags has FREE_FNAME | 107 // cp_flags has CP_FREE_FNAME |
110 int cp_flags; // ORIGINAL_TEXT, CONT_S_IPOS or FREE_FNAME | 108 int cp_flags; // CP_ values |
111 int cp_number; // sequence number | 109 int cp_number; // sequence number |
112 }; | 110 }; |
113 | 111 |
114 // flags for ins_compl_add() | 112 // values for cp_flags |
115 # define ORIGINAL_TEXT (1) // the original text when the expansion begun | 113 # define CP_ORIGINAL_TEXT 1 // the original text when the expansion begun |
116 # define FREE_FNAME (2) | 114 # define CP_FREE_FNAME 2 // cp_fname is allocated |
115 # define CP_CONT_S_IPOS 4 // use CONT_S_IPOS for compl_cont_status | |
116 # define CP_EQUAL 8 // ins_compl_equal() always returns TRUE | |
117 # define CP_ICASE 16 // ins_compl_equal() ignores case | |
117 | 118 |
118 static char e_hitend[] = N_("Hit end of paragraph"); | 119 static char e_hitend[] = N_("Hit end of paragraph"); |
119 # ifdef FEAT_COMPL_FUNC | 120 # ifdef FEAT_COMPL_FUNC |
120 static char e_complwin[] = N_("E839: Completion function changed window"); | 121 static char e_complwin[] = N_("E839: Completion function changed window"); |
121 static char e_compldel[] = N_("E840: Completion function deleted text"); | 122 static char e_compldel[] = N_("E840: Completion function deleted text"); |
183 static expand_T compl_xp; | 184 static expand_T compl_xp; |
184 | 185 |
185 static int compl_opt_refresh_always = FALSE; | 186 static int compl_opt_refresh_always = FALSE; |
186 static int compl_opt_suppress_empty = FALSE; | 187 static int compl_opt_suppress_empty = FALSE; |
187 | 188 |
188 static int ins_compl_add(char_u *str, int len, int icase, char_u *fname, char_u **cptext, int cdir, int flags, int adup, int equal); | 189 static int ins_compl_add(char_u *str, int len, char_u *fname, char_u **cptext, int cdir, int flags, int adup); |
189 static void ins_compl_longest_match(compl_T *match); | 190 static void ins_compl_longest_match(compl_T *match); |
190 static void ins_compl_del_pum(void); | 191 static void ins_compl_del_pum(void); |
191 static void ins_compl_files(int count, char_u **files, int thesaurus, int flags, regmatch_T *regmatch, char_u *buf, int *dir); | 192 static void ins_compl_files(int count, char_u **files, int thesaurus, int flags, regmatch_T *regmatch, char_u *buf, int *dir); |
192 static char_u *find_line_end(char_u *ptr); | 193 static char_u *find_line_end(char_u *ptr); |
193 static void ins_compl_free(void); | 194 static void ins_compl_free(void); |
418 char_u *str_arg, | 419 char_u *str_arg, |
419 int len, | 420 int len, |
420 int icase, | 421 int icase, |
421 char_u *fname, | 422 char_u *fname, |
422 int dir, | 423 int dir, |
423 int flags) | 424 int cont_s_ipos) // next ^X<> will set initial_pos |
424 { | 425 { |
425 char_u *str = str_arg; | 426 char_u *str = str_arg; |
426 char_u *p; | 427 char_u *p; |
427 int i, c; | 428 int i, c; |
428 int actual_len; // Take multi-byte characters | 429 int actual_len; // Take multi-byte characters |
429 int actual_compl_length; // into account. | 430 int actual_compl_length; // into account. |
430 int min_len; | 431 int min_len; |
431 int *wca; // Wide character array. | 432 int *wca; // Wide character array. |
432 int has_lower = FALSE; | 433 int has_lower = FALSE; |
433 int was_letter = FALSE; | 434 int was_letter = FALSE; |
435 int flags = 0; | |
434 | 436 |
435 if (p_ic && curbuf->b_p_inf && len > 0) | 437 if (p_ic && curbuf->b_p_inf && len > 0) |
436 { | 438 { |
437 // Infer case of completed part. | 439 // Infer case of completed part. |
438 | 440 |
553 vim_free(wca); | 555 vim_free(wca); |
554 } | 556 } |
555 | 557 |
556 str = IObuff; | 558 str = IObuff; |
557 } | 559 } |
558 | 560 if (cont_s_ipos) |
559 return ins_compl_add(str, len, icase, fname, NULL, dir, | 561 flags |= CP_CONT_S_IPOS; |
560 flags, FALSE, FALSE); | 562 if (icase) |
563 flags |= CP_ICASE; | |
564 | |
565 return ins_compl_add(str, len, fname, NULL, dir, flags, FALSE); | |
561 } | 566 } |
562 | 567 |
563 /* | 568 /* |
564 * Add a match to the list of matches. | 569 * Add a match to the list of matches. |
565 * If the given string is already in the list of completions, then return | 570 * If the given string is already in the list of completions, then return |
568 */ | 573 */ |
569 static int | 574 static int |
570 ins_compl_add( | 575 ins_compl_add( |
571 char_u *str, | 576 char_u *str, |
572 int len, | 577 int len, |
573 int icase, | |
574 char_u *fname, | 578 char_u *fname, |
575 char_u **cptext, // extra text for popup menu or NULL | 579 char_u **cptext, // extra text for popup menu or NULL |
576 int cdir, | 580 int cdir, |
577 int flags, | 581 int flags_arg, |
578 int adup, // accept duplicate match | 582 int adup) // accept duplicate match |
579 int equal) // match is always accepted by ins_compl_equal | |
580 { | 583 { |
581 compl_T *match; | 584 compl_T *match; |
582 int dir = (cdir == 0 ? compl_direction : cdir); | 585 int dir = (cdir == 0 ? compl_direction : cdir); |
586 int flags = flags_arg; | |
583 | 587 |
584 ui_breakcheck(); | 588 ui_breakcheck(); |
585 if (got_int) | 589 if (got_int) |
586 return FAIL; | 590 return FAIL; |
587 if (len < 0) | 591 if (len < 0) |
591 if (compl_first_match != NULL && !adup) | 595 if (compl_first_match != NULL && !adup) |
592 { | 596 { |
593 match = compl_first_match; | 597 match = compl_first_match; |
594 do | 598 do |
595 { | 599 { |
596 if ( !(match->cp_flags & ORIGINAL_TEXT) | 600 if ( !(match->cp_flags & CP_ORIGINAL_TEXT) |
597 && STRNCMP(match->cp_str, str, len) == 0 | 601 && STRNCMP(match->cp_str, str, len) == 0 |
598 && match->cp_str[len] == NUL) | 602 && match->cp_str[len] == NUL) |
599 return NOTDONE; | 603 return NOTDONE; |
600 match = match->cp_next; | 604 match = match->cp_next; |
601 } while (match != NULL && match != compl_first_match); | 605 } while (match != NULL && match != compl_first_match); |
608 // Copy the values to the new match structure. | 612 // Copy the values to the new match structure. |
609 match = (compl_T *)alloc_clear((unsigned)sizeof(compl_T)); | 613 match = (compl_T *)alloc_clear((unsigned)sizeof(compl_T)); |
610 if (match == NULL) | 614 if (match == NULL) |
611 return FAIL; | 615 return FAIL; |
612 match->cp_number = -1; | 616 match->cp_number = -1; |
613 if (flags & ORIGINAL_TEXT) | 617 if (flags & CP_ORIGINAL_TEXT) |
614 match->cp_number = 0; | 618 match->cp_number = 0; |
615 if ((match->cp_str = vim_strnsave(str, len)) == NULL) | 619 if ((match->cp_str = vim_strnsave(str, len)) == NULL) |
616 { | 620 { |
617 vim_free(match); | 621 vim_free(match); |
618 return FAIL; | 622 return FAIL; |
619 } | 623 } |
620 match->cp_icase = icase; | |
621 match->cp_equal = equal; | |
622 | 624 |
623 // match-fname is: | 625 // match-fname is: |
624 // - compl_curr_match->cp_fname if it is a string equal to fname. | 626 // - compl_curr_match->cp_fname if it is a string equal to fname. |
625 // - a copy of fname, FREE_FNAME is set to free later THE allocated mem. | 627 // - a copy of fname, CP_FREE_FNAME is set to free later THE allocated mem. |
626 // - NULL otherwise. --Acevedo | 628 // - NULL otherwise. --Acevedo |
627 if (fname != NULL | 629 if (fname != NULL |
628 && compl_curr_match != NULL | 630 && compl_curr_match != NULL |
629 && compl_curr_match->cp_fname != NULL | 631 && compl_curr_match->cp_fname != NULL |
630 && STRCMP(fname, compl_curr_match->cp_fname) == 0) | 632 && STRCMP(fname, compl_curr_match->cp_fname) == 0) |
631 match->cp_fname = compl_curr_match->cp_fname; | 633 match->cp_fname = compl_curr_match->cp_fname; |
632 else if (fname != NULL) | 634 else if (fname != NULL) |
633 { | 635 { |
634 match->cp_fname = vim_strsave(fname); | 636 match->cp_fname = vim_strsave(fname); |
635 flags |= FREE_FNAME; | 637 flags |= CP_FREE_FNAME; |
636 } | 638 } |
637 else | 639 else |
638 match->cp_fname = NULL; | 640 match->cp_fname = NULL; |
639 match->cp_flags = flags; | 641 match->cp_flags = flags; |
640 | 642 |
667 else // if there's nothing before, it is the first match | 669 else // if there's nothing before, it is the first match |
668 compl_first_match = match; | 670 compl_first_match = match; |
669 compl_curr_match = match; | 671 compl_curr_match = match; |
670 | 672 |
671 // Find the longest common string if still doing that. | 673 // Find the longest common string if still doing that. |
672 if (compl_get_longest && (flags & ORIGINAL_TEXT) == 0) | 674 if (compl_get_longest && (flags & CP_ORIGINAL_TEXT) == 0) |
673 ins_compl_longest_match(match); | 675 ins_compl_longest_match(match); |
674 | 676 |
675 return OK; | 677 return OK; |
676 } | 678 } |
677 | 679 |
678 /* | 680 /* |
679 * Return TRUE if "str[len]" matches with match->cp_str, considering | 681 * Return TRUE if "str[len]" matches with match->cp_str, considering |
680 * match->cp_icase. | 682 * match->cp_flags. |
681 */ | 683 */ |
682 static int | 684 static int |
683 ins_compl_equal(compl_T *match, char_u *str, int len) | 685 ins_compl_equal(compl_T *match, char_u *str, int len) |
684 { | 686 { |
685 if (match->cp_equal) | 687 if (match->cp_flags & CP_EQUAL) |
686 return TRUE; | 688 return TRUE; |
687 if (match->cp_icase) | 689 if (match->cp_flags & CP_ICASE) |
688 return STRNICMP(match->cp_str, str, (size_t)len) == 0; | 690 return STRNICMP(match->cp_str, str, (size_t)len) == 0; |
689 return STRNCMP(match->cp_str, str, (size_t)len) == 0; | 691 return STRNCMP(match->cp_str, str, (size_t)len) == 0; |
690 } | 692 } |
691 | 693 |
692 /* | 694 /* |
732 else | 734 else |
733 { | 735 { |
734 c1 = *p; | 736 c1 = *p; |
735 c2 = *s; | 737 c2 = *s; |
736 } | 738 } |
737 if (match->cp_icase ? (MB_TOLOWER(c1) != MB_TOLOWER(c2)) | 739 if ((match->cp_flags & CP_ICASE) |
738 : (c1 != c2)) | 740 ? (MB_TOLOWER(c1) != MB_TOLOWER(c2)) : (c1 != c2)) |
739 break; | 741 break; |
740 if (has_mbyte) | 742 if (has_mbyte) |
741 { | 743 { |
742 MB_PTR_ADV(p); | 744 MB_PTR_ADV(p); |
743 MB_PTR_ADV(s); | 745 MB_PTR_ADV(s); |
781 int i; | 783 int i; |
782 int add_r = OK; | 784 int add_r = OK; |
783 int dir = compl_direction; | 785 int dir = compl_direction; |
784 | 786 |
785 for (i = 0; i < num_matches && add_r != FAIL; i++) | 787 for (i = 0; i < num_matches && add_r != FAIL; i++) |
786 if ((add_r = ins_compl_add(matches[i], -1, icase, | 788 if ((add_r = ins_compl_add(matches[i], -1, NULL, NULL, dir, |
787 NULL, NULL, dir, 0, FALSE, FALSE)) == OK) | 789 icase ? CP_ICASE : 0, FALSE)) == OK) |
788 // if dir was BACKWARD then honor it just once | 790 // if dir was BACKWARD then honor it just once |
789 dir = FORWARD; | 791 dir = FORWARD; |
790 FreeWild(num_matches, matches); | 792 FreeWild(num_matches, matches); |
791 } | 793 } |
792 | 794 |
859 void | 861 void |
860 set_completion(colnr_T startcol, list_T *list) | 862 set_completion(colnr_T startcol, list_T *list) |
861 { | 863 { |
862 int save_w_wrow = curwin->w_wrow; | 864 int save_w_wrow = curwin->w_wrow; |
863 int save_w_leftcol = curwin->w_leftcol; | 865 int save_w_leftcol = curwin->w_leftcol; |
866 int flags = CP_ORIGINAL_TEXT; | |
864 | 867 |
865 // If already doing completions stop it. | 868 // If already doing completions stop it. |
866 if (ctrl_x_mode != CTRL_X_NORMAL) | 869 if (ctrl_x_mode != CTRL_X_NORMAL) |
867 ins_compl_prep(' '); | 870 ins_compl_prep(' '); |
868 ins_compl_clear(); | 871 ins_compl_clear(); |
873 startcol = curwin->w_cursor.col; | 876 startcol = curwin->w_cursor.col; |
874 compl_col = startcol; | 877 compl_col = startcol; |
875 compl_length = (int)curwin->w_cursor.col - (int)startcol; | 878 compl_length = (int)curwin->w_cursor.col - (int)startcol; |
876 // compl_pattern doesn't need to be set | 879 // compl_pattern doesn't need to be set |
877 compl_orig_text = vim_strnsave(ml_get_curline() + compl_col, compl_length); | 880 compl_orig_text = vim_strnsave(ml_get_curline() + compl_col, compl_length); |
881 if (p_ic) | |
882 flags |= CP_ICASE; | |
878 if (compl_orig_text == NULL || ins_compl_add(compl_orig_text, | 883 if (compl_orig_text == NULL || ins_compl_add(compl_orig_text, |
879 -1, p_ic, NULL, NULL, 0, ORIGINAL_TEXT, FALSE, FALSE) != OK) | 884 -1, NULL, NULL, 0, flags, FALSE) != OK) |
880 return; | 885 return; |
881 | 886 |
882 ctrl_x_mode = CTRL_X_EVAL; | 887 ctrl_x_mode = CTRL_X_EVAL; |
883 | 888 |
884 ins_compl_add_list(list); | 889 ins_compl_add_list(list); |
977 compl = compl_first_match; | 982 compl = compl_first_match; |
978 i = 0; | 983 i = 0; |
979 do | 984 do |
980 { | 985 { |
981 if (compl == NULL | 986 if (compl == NULL |
982 || ((compl->cp_flags & ORIGINAL_TEXT) == 0 && ++i == 2)) | 987 || ((compl->cp_flags & CP_ORIGINAL_TEXT) == 0 && ++i == 2)) |
983 break; | 988 break; |
984 compl = compl->cp_next; | 989 compl = compl->cp_next; |
985 } while (compl != compl_first_match); | 990 } while (compl != compl_first_match); |
986 | 991 |
987 if (strstr((char *)p_cot, "menuone") != NULL) | 992 if (strstr((char *)p_cot, "menuone") != NULL) |
1023 compl = compl_first_match; | 1028 compl = compl_first_match; |
1024 if (compl_leader != NULL) | 1029 if (compl_leader != NULL) |
1025 lead_len = (int)STRLEN(compl_leader); | 1030 lead_len = (int)STRLEN(compl_leader); |
1026 do | 1031 do |
1027 { | 1032 { |
1028 if ((compl->cp_flags & ORIGINAL_TEXT) == 0 | 1033 if ((compl->cp_flags & CP_ORIGINAL_TEXT) == 0 |
1029 && (compl_leader == NULL | 1034 && (compl_leader == NULL |
1030 || ins_compl_equal(compl, compl_leader, lead_len))) | 1035 || ins_compl_equal(compl, compl_leader, lead_len))) |
1031 ++compl_match_arraysize; | 1036 ++compl_match_arraysize; |
1032 compl = compl->cp_next; | 1037 compl = compl->cp_next; |
1033 } while (compl != NULL && compl != compl_first_match); | 1038 } while (compl != NULL && compl != compl_first_match); |
1038 * compl_match_arraysize)); | 1043 * compl_match_arraysize)); |
1039 if (compl_match_array != NULL) | 1044 if (compl_match_array != NULL) |
1040 { | 1045 { |
1041 // If the current match is the original text don't find the first | 1046 // If the current match is the original text don't find the first |
1042 // match after it, don't highlight anything. | 1047 // match after it, don't highlight anything. |
1043 if (compl_shown_match->cp_flags & ORIGINAL_TEXT) | 1048 if (compl_shown_match->cp_flags & CP_ORIGINAL_TEXT) |
1044 shown_match_ok = TRUE; | 1049 shown_match_ok = TRUE; |
1045 | 1050 |
1046 i = 0; | 1051 i = 0; |
1047 compl = compl_first_match; | 1052 compl = compl_first_match; |
1048 do | 1053 do |
1049 { | 1054 { |
1050 if ((compl->cp_flags & ORIGINAL_TEXT) == 0 | 1055 if ((compl->cp_flags & CP_ORIGINAL_TEXT) == 0 |
1051 && (compl_leader == NULL | 1056 && (compl_leader == NULL |
1052 || ins_compl_equal(compl, compl_leader, lead_len))) | 1057 || ins_compl_equal(compl, compl_leader, lead_len))) |
1053 { | 1058 { |
1054 if (!shown_match_ok) | 1059 if (!shown_match_ok) |
1055 { | 1060 { |
1086 { | 1091 { |
1087 did_find_shown_match = TRUE; | 1092 did_find_shown_match = TRUE; |
1088 | 1093 |
1089 // When the original text is the shown match don't set | 1094 // When the original text is the shown match don't set |
1090 // compl_shown_match. | 1095 // compl_shown_match. |
1091 if (compl->cp_flags & ORIGINAL_TEXT) | 1096 if (compl->cp_flags & CP_ORIGINAL_TEXT) |
1092 shown_match_ok = TRUE; | 1097 shown_match_ok = TRUE; |
1093 | 1098 |
1094 if (!shown_match_ok && shown_compl != NULL) | 1099 if (!shown_match_ok && shown_compl != NULL) |
1095 { | 1100 { |
1096 // The shown match isn't displayed, set it to the | 1101 // The shown match isn't displayed, set it to the |
1305 ptr = find_line_end(ptr); | 1310 ptr = find_line_end(ptr); |
1306 else | 1311 else |
1307 ptr = find_word_end(ptr); | 1312 ptr = find_word_end(ptr); |
1308 add_r = ins_compl_add_infercase(regmatch->startp[0], | 1313 add_r = ins_compl_add_infercase(regmatch->startp[0], |
1309 (int)(ptr - regmatch->startp[0]), | 1314 (int)(ptr - regmatch->startp[0]), |
1310 p_ic, files[i], *dir, 0); | 1315 p_ic, files[i], *dir, FALSE); |
1311 if (thesaurus) | 1316 if (thesaurus) |
1312 { | 1317 { |
1313 char_u *wstart; | 1318 char_u *wstart; |
1314 | 1319 |
1315 // Add the other matches on the line | 1320 // Add the other matches on the line |
1341 | 1346 |
1342 // Add the word. Skip the regexp match. | 1347 // Add the word. Skip the regexp match. |
1343 if (wstart != regmatch->startp[0]) | 1348 if (wstart != regmatch->startp[0]) |
1344 add_r = ins_compl_add_infercase(wstart, | 1349 add_r = ins_compl_add_infercase(wstart, |
1345 (int)(ptr - wstart), | 1350 (int)(ptr - wstart), |
1346 p_ic, files[i], *dir, 0); | 1351 p_ic, files[i], *dir, FALSE); |
1347 } | 1352 } |
1348 } | 1353 } |
1349 if (add_r == OK) | 1354 if (add_r == OK) |
1350 // if dir was BACKWARD then honor it just once | 1355 // if dir was BACKWARD then honor it just once |
1351 *dir = FORWARD; | 1356 *dir = FORWARD; |
1444 { | 1449 { |
1445 match = compl_curr_match; | 1450 match = compl_curr_match; |
1446 compl_curr_match = compl_curr_match->cp_next; | 1451 compl_curr_match = compl_curr_match->cp_next; |
1447 vim_free(match->cp_str); | 1452 vim_free(match->cp_str); |
1448 // several entries may use the same fname, free it just once. | 1453 // several entries may use the same fname, free it just once. |
1449 if (match->cp_flags & FREE_FNAME) | 1454 if (match->cp_flags & CP_FREE_FNAME) |
1450 vim_free(match->cp_fname); | 1455 vim_free(match->cp_fname); |
1451 for (i = 0; i < CPT_COUNT; ++i) | 1456 for (i = 0; i < CPT_COUNT; ++i) |
1452 vim_free(match->cp_text[i]); | 1457 vim_free(match->cp_text[i]); |
1453 vim_free(match); | 1458 vim_free(match); |
1454 } while (compl_curr_match != NULL && compl_curr_match != compl_first_match); | 1459 } while (compl_curr_match != NULL && compl_curr_match != compl_first_match); |
1538 if (ret == OK && compl_first_match != NULL) | 1543 if (ret == OK && compl_first_match != NULL) |
1539 { | 1544 { |
1540 match = compl_first_match; | 1545 match = compl_first_match; |
1541 do | 1546 do |
1542 { | 1547 { |
1543 if (!(match->cp_flags & ORIGINAL_TEXT)) | 1548 if (!(match->cp_flags & CP_ORIGINAL_TEXT)) |
1544 { | 1549 { |
1545 di = dict_alloc(); | 1550 di = dict_alloc(); |
1546 if (di == NULL) | 1551 if (di == NULL) |
1547 return; | 1552 return; |
1548 ret = list_append_dict(li, di); | 1553 ret = list_append_dict(li, di); |
1816 ins_compl_set_original_text(char_u *str) | 1821 ins_compl_set_original_text(char_u *str) |
1817 { | 1822 { |
1818 char_u *p; | 1823 char_u *p; |
1819 | 1824 |
1820 // Replace the original text entry. | 1825 // Replace the original text entry. |
1821 // The ORIGINAL_TEXT flag is either at the first item or might possibly be | 1826 // The CP_ORIGINAL_TEXT flag is either at the first item or might possibly be |
1822 // at the last item for backward completion | 1827 // at the last item for backward completion |
1823 if (compl_first_match->cp_flags & ORIGINAL_TEXT) // safety check | 1828 if (compl_first_match->cp_flags & CP_ORIGINAL_TEXT) // safety check |
1824 { | 1829 { |
1825 p = vim_strsave(str); | 1830 p = vim_strsave(str); |
1826 if (p != NULL) | 1831 if (p != NULL) |
1827 { | 1832 { |
1828 vim_free(compl_first_match->cp_str); | 1833 vim_free(compl_first_match->cp_str); |
1829 compl_first_match->cp_str = p; | 1834 compl_first_match->cp_str = p; |
1830 } | 1835 } |
1831 } | 1836 } |
1832 else if (compl_first_match->cp_prev != NULL | 1837 else if (compl_first_match->cp_prev != NULL |
1833 && (compl_first_match->cp_prev->cp_flags & ORIGINAL_TEXT)) | 1838 && (compl_first_match->cp_prev->cp_flags & CP_ORIGINAL_TEXT)) |
1834 { | 1839 { |
1835 p = vim_strsave(str); | 1840 p = vim_strsave(str); |
1836 if (p != NULL) | 1841 if (p != NULL) |
1837 { | 1842 { |
1838 vim_free(compl_first_match->cp_prev->cp_str); | 1843 vim_free(compl_first_match->cp_prev->cp_str); |
1856 p = compl_shown_match->cp_str; | 1861 p = compl_shown_match->cp_str; |
1857 if ((int)STRLEN(p) <= len) // the match is too short | 1862 if ((int)STRLEN(p) <= len) // the match is too short |
1858 { | 1863 { |
1859 // When still at the original match use the first entry that matches | 1864 // When still at the original match use the first entry that matches |
1860 // the leader. | 1865 // the leader. |
1861 if (compl_shown_match->cp_flags & ORIGINAL_TEXT) | 1866 if (compl_shown_match->cp_flags & CP_ORIGINAL_TEXT) |
1862 { | 1867 { |
1863 p = NULL; | 1868 p = NULL; |
1864 for (cp = compl_shown_match->cp_next; cp != NULL | 1869 for (cp = compl_shown_match->cp_next; cp != NULL |
1865 && cp != compl_first_match; cp = cp->cp_next) | 1870 && cp != compl_first_match; cp = cp->cp_next) |
1866 { | 1871 { |
2368 */ | 2373 */ |
2369 int | 2374 int |
2370 ins_compl_add_tv(typval_T *tv, int dir) | 2375 ins_compl_add_tv(typval_T *tv, int dir) |
2371 { | 2376 { |
2372 char_u *word; | 2377 char_u *word; |
2373 int icase = FALSE; | 2378 int dup = FALSE; |
2374 int adup = FALSE; | 2379 int empty = FALSE; |
2375 int aempty = FALSE; | 2380 int flags = 0; |
2376 int aequal = FALSE; | |
2377 char_u *(cptext[CPT_COUNT]); | 2381 char_u *(cptext[CPT_COUNT]); |
2378 | 2382 |
2379 if (tv->v_type == VAR_DICT && tv->vval.v_dict != NULL) | 2383 if (tv->v_type == VAR_DICT && tv->vval.v_dict != NULL) |
2380 { | 2384 { |
2381 word = dict_get_string(tv->vval.v_dict, (char_u *)"word", FALSE); | 2385 word = dict_get_string(tv->vval.v_dict, (char_u *)"word", FALSE); |
2387 (char_u *)"kind", FALSE); | 2391 (char_u *)"kind", FALSE); |
2388 cptext[CPT_INFO] = dict_get_string(tv->vval.v_dict, | 2392 cptext[CPT_INFO] = dict_get_string(tv->vval.v_dict, |
2389 (char_u *)"info", FALSE); | 2393 (char_u *)"info", FALSE); |
2390 cptext[CPT_USER_DATA] = dict_get_string(tv->vval.v_dict, | 2394 cptext[CPT_USER_DATA] = dict_get_string(tv->vval.v_dict, |
2391 (char_u *)"user_data", FALSE); | 2395 (char_u *)"user_data", FALSE); |
2392 if (dict_get_string(tv->vval.v_dict, (char_u *)"icase", FALSE) != NULL) | 2396 if (dict_get_string(tv->vval.v_dict, (char_u *)"icase", FALSE) != NULL |
2393 icase = dict_get_number(tv->vval.v_dict, (char_u *)"icase"); | 2397 && dict_get_number(tv->vval.v_dict, (char_u *)"icase")) |
2398 flags |= CP_ICASE; | |
2394 if (dict_get_string(tv->vval.v_dict, (char_u *)"dup", FALSE) != NULL) | 2399 if (dict_get_string(tv->vval.v_dict, (char_u *)"dup", FALSE) != NULL) |
2395 adup = dict_get_number(tv->vval.v_dict, (char_u *)"dup"); | 2400 dup = dict_get_number(tv->vval.v_dict, (char_u *)"dup"); |
2396 if (dict_get_string(tv->vval.v_dict, (char_u *)"empty", FALSE) != NULL) | 2401 if (dict_get_string(tv->vval.v_dict, (char_u *)"empty", FALSE) != NULL) |
2397 aempty = dict_get_number(tv->vval.v_dict, (char_u *)"empty"); | 2402 empty = dict_get_number(tv->vval.v_dict, (char_u *)"empty"); |
2398 if (dict_get_string(tv->vval.v_dict, (char_u *)"equal", FALSE) != NULL) | 2403 if (dict_get_string(tv->vval.v_dict, (char_u *)"equal", FALSE) != NULL |
2399 aequal = dict_get_number(tv->vval.v_dict, (char_u *)"equal"); | 2404 && dict_get_number(tv->vval.v_dict, (char_u *)"equal")) |
2405 flags |= CP_EQUAL; | |
2400 } | 2406 } |
2401 else | 2407 else |
2402 { | 2408 { |
2403 word = tv_get_string_chk(tv); | 2409 word = tv_get_string_chk(tv); |
2404 vim_memset(cptext, 0, sizeof(cptext)); | 2410 vim_memset(cptext, 0, sizeof(cptext)); |
2405 } | 2411 } |
2406 if (word == NULL || (!aempty && *word == NUL)) | 2412 if (word == NULL || (!empty && *word == NUL)) |
2407 return FAIL; | 2413 return FAIL; |
2408 return ins_compl_add(word, -1, icase, NULL, cptext, dir, 0, adup, aequal); | 2414 return ins_compl_add(word, -1, NULL, cptext, dir, flags, dup); |
2409 } | 2415 } |
2410 #endif | 2416 #endif |
2411 | 2417 |
2412 /* | 2418 /* |
2413 * Get the next expansion(s), using "compl_pattern". | 2419 * Get the next expansion(s), using "compl_pattern". |
2670 p_ws = FALSE; | 2676 p_ws = FALSE; |
2671 else if (*e_cpt == '.') | 2677 else if (*e_cpt == '.') |
2672 p_ws = TRUE; | 2678 p_ws = TRUE; |
2673 for (;;) | 2679 for (;;) |
2674 { | 2680 { |
2675 int flags = 0; | 2681 int cont_s_ipos = FALSE; |
2676 | 2682 |
2677 ++msg_silent; // Don't want messages for wrapscan. | 2683 ++msg_silent; // Don't want messages for wrapscan. |
2678 | 2684 |
2679 // ctrl_x_mode_line_or_eval() || word-wise search that | 2685 // ctrl_x_mode_line_or_eval() || word-wise search that |
2680 // has added a word that was at the beginning of the line | 2686 // has added a word that was at the beginning of the line |
2776 // copy as much as possible of the new word | 2782 // copy as much as possible of the new word |
2777 if (tmp_ptr - ptr >= IOSIZE - len) | 2783 if (tmp_ptr - ptr >= IOSIZE - len) |
2778 tmp_ptr = ptr + IOSIZE - len - 1; | 2784 tmp_ptr = ptr + IOSIZE - len - 1; |
2779 STRNCPY(IObuff + len, ptr, tmp_ptr - ptr); | 2785 STRNCPY(IObuff + len, ptr, tmp_ptr - ptr); |
2780 len += (int)(tmp_ptr - ptr); | 2786 len += (int)(tmp_ptr - ptr); |
2781 flags |= CONT_S_IPOS; | 2787 cont_s_ipos = TRUE; |
2782 } | 2788 } |
2783 IObuff[len] = NUL; | 2789 IObuff[len] = NUL; |
2784 ptr = IObuff; | 2790 ptr = IObuff; |
2785 } | 2791 } |
2786 if (len == compl_length) | 2792 if (len == compl_length) |
2787 continue; | 2793 continue; |
2788 } | 2794 } |
2789 } | 2795 } |
2790 if (ins_compl_add_infercase(ptr, len, p_ic, | 2796 if (ins_compl_add_infercase(ptr, len, p_ic, |
2791 ins_buf == curbuf ? NULL : ins_buf->b_sfname, | 2797 ins_buf == curbuf ? NULL : ins_buf->b_sfname, |
2792 0, flags) != NOTDONE) | 2798 0, cont_s_ipos) != NOTDONE) |
2793 { | 2799 { |
2794 found_new_match = OK; | 2800 found_new_match = OK; |
2795 break; | 2801 break; |
2796 } | 2802 } |
2797 } | 2803 } |
2887 ins_compl_insert(int in_compl_func) | 2893 ins_compl_insert(int in_compl_func) |
2888 { | 2894 { |
2889 dict_T *dict; | 2895 dict_T *dict; |
2890 | 2896 |
2891 ins_bytes(compl_shown_match->cp_str + ins_compl_len()); | 2897 ins_bytes(compl_shown_match->cp_str + ins_compl_len()); |
2892 if (compl_shown_match->cp_flags & ORIGINAL_TEXT) | 2898 if (compl_shown_match->cp_flags & CP_ORIGINAL_TEXT) |
2893 compl_used_match = FALSE; | 2899 compl_used_match = FALSE; |
2894 else | 2900 else |
2895 compl_used_match = TRUE; | 2901 compl_used_match = TRUE; |
2896 | 2902 |
2897 // Set completed item. | 2903 // Set completed item. |
2947 // time of 'always', compl_shown_match become NULL. | 2953 // time of 'always', compl_shown_match become NULL. |
2948 if (compl_shown_match == NULL) | 2954 if (compl_shown_match == NULL) |
2949 return -1; | 2955 return -1; |
2950 | 2956 |
2951 if (compl_leader != NULL | 2957 if (compl_leader != NULL |
2952 && (compl_shown_match->cp_flags & ORIGINAL_TEXT) == 0) | 2958 && (compl_shown_match->cp_flags & CP_ORIGINAL_TEXT) == 0) |
2953 { | 2959 { |
2954 // Set "compl_shown_match" to the actually shown match, it may differ | 2960 // Set "compl_shown_match" to the actually shown match, it may differ |
2955 // when "compl_leader" is used to omit some of the matches. | 2961 // when "compl_leader" is used to omit some of the matches. |
2956 while (!ins_compl_equal(compl_shown_match, | 2962 while (!ins_compl_equal(compl_shown_match, |
2957 compl_leader, (int)STRLEN(compl_leader)) | 2963 compl_leader, (int)STRLEN(compl_leader)) |
3051 else | 3057 else |
3052 break; | 3058 break; |
3053 } | 3059 } |
3054 found_end = FALSE; | 3060 found_end = FALSE; |
3055 } | 3061 } |
3056 if ((compl_shown_match->cp_flags & ORIGINAL_TEXT) == 0 | 3062 if ((compl_shown_match->cp_flags & CP_ORIGINAL_TEXT) == 0 |
3057 && compl_leader != NULL | 3063 && compl_leader != NULL |
3058 && !ins_compl_equal(compl_shown_match, | 3064 && !ins_compl_equal(compl_shown_match, |
3059 compl_leader, (int)STRLEN(compl_leader))) | 3065 compl_leader, (int)STRLEN(compl_leader))) |
3060 ++todo; | 3066 ++todo; |
3061 else | 3067 else |
3302 int n; | 3308 int n; |
3303 int save_w_wrow; | 3309 int save_w_wrow; |
3304 int save_w_leftcol; | 3310 int save_w_leftcol; |
3305 int insert_match; | 3311 int insert_match; |
3306 int save_did_ai = did_ai; | 3312 int save_did_ai = did_ai; |
3313 int flags = CP_ORIGINAL_TEXT; | |
3307 | 3314 |
3308 compl_direction = ins_compl_key2dir(c); | 3315 compl_direction = ins_compl_key2dir(c); |
3309 insert_match = ins_compl_use_match(c); | 3316 insert_match = ins_compl_use_match(c); |
3310 | 3317 |
3311 if (!compl_started) | 3318 if (!compl_started) |
3702 ins_compl_fixRedoBufForLeader(NULL); | 3709 ins_compl_fixRedoBufForLeader(NULL); |
3703 | 3710 |
3704 // Always add completion for the original text. | 3711 // Always add completion for the original text. |
3705 vim_free(compl_orig_text); | 3712 vim_free(compl_orig_text); |
3706 compl_orig_text = vim_strnsave(line + compl_col, compl_length); | 3713 compl_orig_text = vim_strnsave(line + compl_col, compl_length); |
3714 if (p_ic) | |
3715 flags |= CP_ICASE; | |
3707 if (compl_orig_text == NULL || ins_compl_add(compl_orig_text, | 3716 if (compl_orig_text == NULL || ins_compl_add(compl_orig_text, |
3708 -1, p_ic, NULL, NULL, 0, ORIGINAL_TEXT, FALSE, FALSE) != OK) | 3717 -1, NULL, NULL, 0, flags, FALSE) != OK) |
3709 { | 3718 { |
3710 VIM_CLEAR(compl_pattern); | 3719 VIM_CLEAR(compl_pattern); |
3711 VIM_CLEAR(compl_orig_text); | 3720 VIM_CLEAR(compl_orig_text); |
3712 return FAIL; | 3721 return FAIL; |
3713 } | 3722 } |
3765 && ctrl_x_mode != CTRL_X_PATH_PATTERNS | 3774 && ctrl_x_mode != CTRL_X_PATH_PATTERNS |
3766 && ctrl_x_mode != CTRL_X_PATH_DEFINES)) | 3775 && ctrl_x_mode != CTRL_X_PATH_DEFINES)) |
3767 compl_cont_status &= ~CONT_N_ADDS; | 3776 compl_cont_status &= ~CONT_N_ADDS; |
3768 } | 3777 } |
3769 | 3778 |
3770 if (compl_curr_match->cp_flags & CONT_S_IPOS) | 3779 if (compl_curr_match->cp_flags & CP_CONT_S_IPOS) |
3771 compl_cont_status |= CONT_S_IPOS; | 3780 compl_cont_status |= CONT_S_IPOS; |
3772 else | 3781 else |
3773 compl_cont_status &= ~CONT_S_IPOS; | 3782 compl_cont_status &= ~CONT_S_IPOS; |
3774 | 3783 |
3775 if (edit_submode_extra == NULL) | 3784 if (edit_submode_extra == NULL) |
3776 { | 3785 { |
3777 if (compl_curr_match->cp_flags & ORIGINAL_TEXT) | 3786 if (compl_curr_match->cp_flags & CP_ORIGINAL_TEXT) |
3778 { | 3787 { |
3779 edit_submode_extra = (char_u *)_("Back at original"); | 3788 edit_submode_extra = (char_u *)_("Back at original"); |
3780 edit_submode_highl = HLF_W; | 3789 edit_submode_highl = HLF_W; |
3781 } | 3790 } |
3782 else if (compl_cont_status & CONT_S_IPOS) | 3791 else if (compl_cont_status & CONT_S_IPOS) |