comparison src/insexpand.c @ 26944:8dbdd68627bd v8.2.4001

patch 8.2.4001: insert complete code uses global variables Commit: https://github.com/vim/vim/commit/d94fbfc74a8b8073e7a256c95fa6f39fc527c726 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Tue Jan 4 17:01:44 2022 +0000 patch 8.2.4001: insert complete code uses global variables Problem: Insert complete code uses global variables. Solution: Make variables local to the file and use accessor functions. (Yegappan Lakshmanan, closes #9470)
author Bram Moolenaar <Bram@vim.org>
date Tue, 04 Jan 2022 18:15:03 +0100
parents b975b7c16ba1
children d92e0d85923f
comparison
equal deleted inserted replaced
26943:61f686b38df9 26944:8dbdd68627bd
175 static int compl_started = FALSE; 175 static int compl_started = FALSE;
176 176
177 // Which Ctrl-X mode are we in? 177 // Which Ctrl-X mode are we in?
178 static int ctrl_x_mode = CTRL_X_NORMAL; 178 static int ctrl_x_mode = CTRL_X_NORMAL;
179 179
180 static int compl_matches = 0; 180 static int compl_matches = 0; // number of completion matches
181 static char_u *compl_pattern = NULL; 181 static char_u *compl_pattern = NULL;
182 static int compl_direction = FORWARD; 182 static int compl_direction = FORWARD;
183 static int compl_shows_dir = FORWARD; 183 static int compl_shows_dir = FORWARD;
184 static int compl_pending = 0; // > 1 for postponed CTRL-N 184 static int compl_pending = 0; // > 1 for postponed CTRL-N
185 static pos_T compl_startpos; 185 static pos_T compl_startpos;
186 // Length in bytes of the text being completed (this is deleted to be replaced
187 // by the match.)
188 static int compl_length = 0;
186 static colnr_T compl_col = 0; // column where the text starts 189 static colnr_T compl_col = 0; // column where the text starts
187 // that is being completed 190 // that is being completed
188 static char_u *compl_orig_text = NULL; // text as it was before 191 static char_u *compl_orig_text = NULL; // text as it was before
189 // completion started 192 // completion started
190 static int compl_cont_mode = 0; 193 static int compl_cont_mode = 0;
191 static expand_T compl_xp; 194 static expand_T compl_xp;
195
196 // List of flags for method of completion.
197 static int compl_cont_status = 0;
198 # define CONT_ADDING 1 // "normal" or "adding" expansion
199 # define CONT_INTRPT (2 + 4) // a ^X interrupted the current expansion
200 // it's set only iff N_ADDS is set
201 # define CONT_N_ADDS 4 // next ^X<> will add-new or expand-current
202 # define CONT_S_IPOS 8 // next ^X<> will set initial_pos?
203 // if so, word-wise-expansion will set SOL
204 # define CONT_SOL 16 // pattern includes start of line, just for
205 // word-wise expansion, not set for ^X^L
206 # define CONT_LOCAL 32 // for ctrl_x_mode 0, ^X^P/^X^N do a local
207 // expansion, (eg use complete=.)
192 208
193 static int compl_opt_refresh_always = FALSE; 209 static int compl_opt_refresh_always = FALSE;
194 static int compl_opt_suppress_empty = FALSE; 210 static int compl_opt_suppress_empty = FALSE;
195 211
196 static int ins_compl_add(char_u *str, int len, char_u *fname, char_u **cptext, typval_T *user_data, int cdir, int flags, int adup); 212 static int ins_compl_add(char_u *str, int len, char_u *fname, char_u **cptext, typval_T *user_data, int cdir, int flags, int adup);
199 static void ins_compl_files(int count, char_u **files, int thesaurus, int flags, regmatch_T *regmatch, char_u *buf, int *dir); 215 static void ins_compl_files(int count, char_u **files, int thesaurus, int flags, regmatch_T *regmatch, char_u *buf, int *dir);
200 static char_u *find_line_end(char_u *ptr); 216 static char_u *find_line_end(char_u *ptr);
201 static void ins_compl_free(void); 217 static void ins_compl_free(void);
202 static int ins_compl_need_restart(void); 218 static int ins_compl_need_restart(void);
203 static void ins_compl_new_leader(void); 219 static void ins_compl_new_leader(void);
204 static int ins_compl_len(void); 220 static int get_compl_len(void);
205 static void ins_compl_restart(void); 221 static void ins_compl_restart(void);
206 static void ins_compl_set_original_text(char_u *str); 222 static void ins_compl_set_original_text(char_u *str);
207 static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg); 223 static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg);
208 # if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL) 224 # if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL)
209 static void ins_compl_add_list(list_T *list); 225 static void ins_compl_add_list(list_T *list);
266 return ctrl_x_mode == CTRL_X_CMDLINE 282 return ctrl_x_mode == CTRL_X_CMDLINE
267 || ctrl_x_mode == CTRL_X_CMDLINE_CTRL_X; } 283 || ctrl_x_mode == CTRL_X_CMDLINE_CTRL_X; }
268 int ctrl_x_mode_function(void) { return ctrl_x_mode == CTRL_X_FUNCTION; } 284 int ctrl_x_mode_function(void) { return ctrl_x_mode == CTRL_X_FUNCTION; }
269 int ctrl_x_mode_omni(void) { return ctrl_x_mode == CTRL_X_OMNI; } 285 int ctrl_x_mode_omni(void) { return ctrl_x_mode == CTRL_X_OMNI; }
270 int ctrl_x_mode_spell(void) { return ctrl_x_mode == CTRL_X_SPELL; } 286 int ctrl_x_mode_spell(void) { return ctrl_x_mode == CTRL_X_SPELL; }
287 static int ctrl_x_mode_eval(void) { return ctrl_x_mode == CTRL_X_EVAL; }
271 int ctrl_x_mode_line_or_eval(void) { 288 int ctrl_x_mode_line_or_eval(void) {
272 return ctrl_x_mode == CTRL_X_WHOLE_LINE || ctrl_x_mode == CTRL_X_EVAL; } 289 return ctrl_x_mode == CTRL_X_WHOLE_LINE || ctrl_x_mode == CTRL_X_EVAL; }
273 290
274 /* 291 /*
275 * Whether other than default completion has been selected. 292 * Whether other than default completion has been selected.
289 { 306 {
290 return ctrl_x_mode == CTRL_X_NOT_DEFINED_YET; 307 return ctrl_x_mode == CTRL_X_NOT_DEFINED_YET;
291 } 308 }
292 309
293 /* 310 /*
294 * Return TRUE if the 'dict' or 'tsr' option can be used. 311 * Return TRUE if currently in "normal" or "adding" insert completion matches
312 * state
313 */
314 int
315 compl_status_adding(void)
316 {
317 return compl_cont_status & CONT_ADDING;
318 }
319
320 /*
321 * Return TRUE if the completion pattern includes start of line, just for
322 * word-wise expansion.
323 */
324 int
325 compl_status_sol(void)
326 {
327 return compl_cont_status & CONT_SOL;
328 }
329
330 /*
331 * Return TRUE if ^X^P/^X^N will do a local completion (i.e. use complete=.)
332 */
333 int
334 compl_status_local(void)
335 {
336 return compl_cont_status & CONT_LOCAL;
337 }
338
339 /*
340 * Clear the completion status flags
341 */
342 void
343 compl_status_clear(void)
344 {
345 compl_cont_status = 0;
346 }
347
348 /*
349 * Return TRUE if completion is using the forward direction matches
350 */
351 static int
352 compl_dir_forward(void)
353 {
354 return compl_direction == FORWARD;
355 }
356
357 /*
358 * Return TRUE if currently showing forward completion matches
359 */
360 static int
361 compl_shows_dir_forward(void)
362 {
363 return compl_shows_dir == FORWARD;
364 }
365
366 /*
367 * Return TRUE if currently showing backward completion matches
368 */
369 static int
370 compl_shows_dir_backward(void)
371 {
372 return compl_shows_dir == BACKWARD;
373 }
374
375 /*
376 * Return TRUE if the 'dictionary' or 'thesaurus' option can be used.
295 */ 377 */
296 int 378 int
297 has_compl_option(int dict_opt) 379 has_compl_option(int dict_opt)
298 { 380 {
299 if (dict_opt ? (*curbuf->b_p_dict == NUL && *p_dict == NUL 381 if (dict_opt ? (*curbuf->b_p_dict == NUL && *p_dict == NUL
326 } 408 }
327 return TRUE; 409 return TRUE;
328 } 410 }
329 411
330 /* 412 /*
331 * Is the character 'c' a valid key to go to or keep us in CTRL-X mode? 413 * Is the character "c" a valid key to go to or keep us in CTRL-X mode?
332 * This depends on the current mode. 414 * This depends on the current mode.
333 */ 415 */
334 int 416 int
335 vim_is_ctrl_x_key(int c) 417 vim_is_ctrl_x_key(int c)
336 { 418 {
390 internal_error("vim_is_ctrl_x_key()"); 472 internal_error("vim_is_ctrl_x_key()");
391 return FALSE; 473 return FALSE;
392 } 474 }
393 475
394 /* 476 /*
395 * Returns TRUE if the currently shown text is the original text when the 477 * Return TRUE if "match" is the original text when the completion began.
396 * completion began.
397 */ 478 */
398 static int 479 static int
399 ins_compl_at_original_text(compl_T *match) 480 match_at_original_text(compl_T *match)
400 { 481 {
401 return match->cp_flags & CP_ORIGINAL_TEXT; 482 return match->cp_flags & CP_ORIGINAL_TEXT;
483 }
484
485 /*
486 * Returns TRUE if "match" is the first match in the completion list.
487 */
488 static int
489 is_first_match(compl_T *match)
490 {
491 return match == compl_first_match;
402 } 492 }
403 493
404 /* 494 /*
405 * Return TRUE when character "c" is part of the item currently being 495 * Return TRUE when character "c" is part of the item currently being
406 * completed. Used to decide whether to abandon complete mode when the menu 496 * completed. Used to decide whether to abandon complete mode when the menu
644 if (compl_first_match != NULL && !adup) 734 if (compl_first_match != NULL && !adup)
645 { 735 {
646 match = compl_first_match; 736 match = compl_first_match;
647 do 737 do
648 { 738 {
649 if (!ins_compl_at_original_text(match) 739 if (!match_at_original_text(match)
650 && STRNCMP(match->cp_str, str, len) == 0 740 && STRNCMP(match->cp_str, str, len) == 0
651 && match->cp_str[len] == NUL) 741 && match->cp_str[len] == NUL)
652 return NOTDONE; 742 return NOTDONE;
653 match = match->cp_next; 743 match = match->cp_next;
654 } while (match != NULL && match != compl_first_match); 744 } while (match != NULL && !is_first_match(match));
655 } 745 }
656 746
657 // Remove any popup menu before changing the list of matches. 747 // Remove any popup menu before changing the list of matches.
658 ins_compl_del_pum(); 748 ins_compl_del_pum();
659 749
761 if (compl_leader == NULL) 851 if (compl_leader == NULL)
762 return; 852 return;
763 853
764 had_match = (curwin->w_cursor.col > compl_col); 854 had_match = (curwin->w_cursor.col > compl_col);
765 ins_compl_delete(); 855 ins_compl_delete();
766 ins_bytes(compl_leader + ins_compl_len()); 856 ins_bytes(compl_leader + get_compl_len());
767 ins_redraw(FALSE); 857 ins_redraw(FALSE);
768 858
769 // When the match isn't there (to avoid matching itself) remove it 859 // When the match isn't there (to avoid matching itself) remove it
770 // again after redrawing. 860 // again after redrawing.
771 if (!had_match) 861 if (!had_match)
809 { 899 {
810 // Leader was shortened, need to change the inserted text. 900 // Leader was shortened, need to change the inserted text.
811 *p = NUL; 901 *p = NUL;
812 had_match = (curwin->w_cursor.col > compl_col); 902 had_match = (curwin->w_cursor.col > compl_col);
813 ins_compl_delete(); 903 ins_compl_delete();
814 ins_bytes(compl_leader + ins_compl_len()); 904 ins_bytes(compl_leader + get_compl_len());
815 ins_redraw(FALSE); 905 ins_redraw(FALSE);
816 906
817 // When the match isn't there (to avoid matching itself) remove it 907 // When the match isn't there (to avoid matching itself) remove it
818 // again after redrawing. 908 // again after redrawing.
819 if (!had_match) 909 if (!had_match)
859 return 0; 949 return 0;
860 950
861 // Find the end of the list. 951 // Find the end of the list.
862 match = compl_first_match; 952 match = compl_first_match;
863 // there's always an entry for the compl_orig_text, it doesn't count. 953 // there's always an entry for the compl_orig_text, it doesn't count.
864 while (match->cp_next != NULL && match->cp_next != compl_first_match) 954 while (match->cp_next != NULL && !is_first_match(match->cp_next))
865 { 955 {
866 match = match->cp_next; 956 match = match->cp_next;
867 ++count; 957 ++count;
868 } 958 }
869 match->cp_next = compl_first_match; 959 match->cp_next = compl_first_match;
978 // one (ignoring the original text). 1068 // one (ignoring the original text).
979 compl = compl_first_match; 1069 compl = compl_first_match;
980 i = 0; 1070 i = 0;
981 do 1071 do
982 { 1072 {
983 if (compl == NULL 1073 if (compl == NULL || (!match_at_original_text(compl) && ++i == 2))
984 || (!ins_compl_at_original_text(compl) && ++i == 2))
985 break; 1074 break;
986 compl = compl->cp_next; 1075 compl = compl->cp_next;
987 } while (compl != compl_first_match); 1076 } while (!is_first_match(compl));
988 1077
989 if (strstr((char *)p_cot, "menuone") != NULL) 1078 if (strstr((char *)p_cot, "menuone") != NULL)
990 return (i >= 1); 1079 return (i >= 1);
991 return (i >= 2); 1080 return (i >= 2);
992 } 1081 }
1075 if (compl_leader != NULL) 1164 if (compl_leader != NULL)
1076 lead_len = (int)STRLEN(compl_leader); 1165 lead_len = (int)STRLEN(compl_leader);
1077 1166
1078 do 1167 do
1079 { 1168 {
1080 if (!ins_compl_at_original_text(compl) 1169 if (!match_at_original_text(compl)
1081 && (compl_leader == NULL 1170 && (compl_leader == NULL
1082 || ins_compl_equal(compl, compl_leader, lead_len))) 1171 || ins_compl_equal(compl, compl_leader, lead_len)))
1083 ++compl_match_arraysize; 1172 ++compl_match_arraysize;
1084 compl = compl->cp_next; 1173 compl = compl->cp_next;
1085 } while (compl != NULL && compl != compl_first_match); 1174 } while (compl != NULL && !is_first_match(compl));
1086 1175
1087 if (compl_match_arraysize == 0) 1176 if (compl_match_arraysize == 0)
1088 return -1; 1177 return -1;
1089 1178
1090 compl_match_array = ALLOC_CLEAR_MULT(pumitem_T, compl_match_arraysize); 1179 compl_match_array = ALLOC_CLEAR_MULT(pumitem_T, compl_match_arraysize);
1091 if (compl_match_array == NULL) 1180 if (compl_match_array == NULL)
1092 return -1; 1181 return -1;
1093 1182
1094 // If the current match is the original text don't find the first 1183 // If the current match is the original text don't find the first
1095 // match after it, don't highlight anything. 1184 // match after it, don't highlight anything.
1096 if (ins_compl_at_original_text(compl_shown_match)) 1185 if (match_at_original_text(compl_shown_match))
1097 shown_match_ok = TRUE; 1186 shown_match_ok = TRUE;
1098 1187
1099 i = 0; 1188 i = 0;
1100 compl = compl_first_match; 1189 compl = compl_first_match;
1101 do 1190 do
1102 { 1191 {
1103 if (!ins_compl_at_original_text(compl) 1192 if (!match_at_original_text(compl)
1104 && (compl_leader == NULL 1193 && (compl_leader == NULL
1105 || ins_compl_equal(compl, compl_leader, lead_len))) 1194 || ins_compl_equal(compl, compl_leader, lead_len)))
1106 { 1195 {
1107 if (!shown_match_ok) 1196 if (!shown_match_ok)
1108 { 1197 {
1139 { 1228 {
1140 did_find_shown_match = TRUE; 1229 did_find_shown_match = TRUE;
1141 1230
1142 // When the original text is the shown match don't set 1231 // When the original text is the shown match don't set
1143 // compl_shown_match. 1232 // compl_shown_match.
1144 if (ins_compl_at_original_text(compl)) 1233 if (match_at_original_text(compl))
1145 shown_match_ok = TRUE; 1234 shown_match_ok = TRUE;
1146 1235
1147 if (!shown_match_ok && shown_compl != NULL) 1236 if (!shown_match_ok && shown_compl != NULL)
1148 { 1237 {
1149 // The shown match isn't displayed, set it to the 1238 // The shown match isn't displayed, set it to the
1151 compl_shown_match = shown_compl; 1240 compl_shown_match = shown_compl;
1152 shown_match_ok = TRUE; 1241 shown_match_ok = TRUE;
1153 } 1242 }
1154 } 1243 }
1155 compl = compl->cp_next; 1244 compl = compl->cp_next;
1156 } while (compl != NULL && compl != compl_first_match); 1245 } while (compl != NULL && !is_first_match(compl));
1157 1246
1158 if (!shown_match_ok) // no displayed match at all 1247 if (!shown_match_ok) // no displayed match at all
1159 cur = -1; 1248 cur = -1;
1160 1249
1161 return cur; 1250 return cur;
1566 vim_free(match->cp_text[i]); 1655 vim_free(match->cp_text[i]);
1567 #ifdef FEAT_EVAL 1656 #ifdef FEAT_EVAL
1568 clear_tv(&match->cp_user_data); 1657 clear_tv(&match->cp_user_data);
1569 #endif 1658 #endif
1570 vim_free(match); 1659 vim_free(match);
1571 } while (compl_curr_match != NULL && compl_curr_match != compl_first_match); 1660 } while (compl_curr_match != NULL && !is_first_match(compl_curr_match));
1572 compl_first_match = compl_curr_match = NULL; 1661 compl_first_match = compl_curr_match = NULL;
1573 compl_shown_match = NULL; 1662 compl_shown_match = NULL;
1574 compl_old_match = NULL; 1663 compl_old_match = NULL;
1575 } 1664 }
1576 1665
1666 /*
1667 * Reset/clear the completion state.
1668 */
1577 void 1669 void
1578 ins_compl_clear(void) 1670 ins_compl_clear(void)
1579 { 1671 {
1580 compl_cont_status = 0; 1672 compl_cont_status = 0;
1581 compl_started = FALSE; 1673 compl_started = FALSE;
1646 { 1738 {
1647 return compl_col; 1739 return compl_col;
1648 } 1740 }
1649 1741
1650 /* 1742 /*
1743 * Return the length in bytes of the text being completed
1744 */
1745 int
1746 ins_compl_len(void)
1747 {
1748 return compl_length;
1749 }
1750
1751 /*
1651 * Delete one character before the cursor and show the subset of the matches 1752 * Delete one character before the cursor and show the subset of the matches
1652 * that match the word that is now before the cursor. 1753 * that match the word that is now before the cursor.
1653 * Returns the character to be used, NUL if the work is done and another char 1754 * Returns the character to be used, NUL if the work is done and another char
1654 * to be got from the user. 1755 * to be got from the user.
1655 */ 1756 */
1665 1766
1666 // Stop completion when the whole word was deleted. For Omni completion 1767 // Stop completion when the whole word was deleted. For Omni completion
1667 // allow the word to be deleted, we won't match everything. 1768 // allow the word to be deleted, we won't match everything.
1668 // Respect the 'backspace' option. 1769 // Respect the 'backspace' option.
1669 if ((int)(p - line) - (int)compl_col < 0 1770 if ((int)(p - line) - (int)compl_col < 0
1670 || ((int)(p - line) - (int)compl_col == 0 1771 || ((int)(p - line) - (int)compl_col == 0 && !ctrl_x_mode_omni())
1671 && ctrl_x_mode != CTRL_X_OMNI) 1772 || ctrl_x_mode_eval()
1672 || ctrl_x_mode == CTRL_X_EVAL
1673 || (!can_bs(BS_START) && (int)(p - line) - (int)compl_col 1773 || (!can_bs(BS_START) && (int)(p - line) - (int)compl_col
1674 - compl_length < 0)) 1774 - compl_length < 0))
1675 return K_BS; 1775 return K_BS;
1676 1776
1677 // Deleted more than what was used to find matches or didn't finish 1777 // Deleted more than what was used to find matches or didn't finish
1700 ins_compl_need_restart(void) 1800 ins_compl_need_restart(void)
1701 { 1801 {
1702 // Return TRUE if we didn't complete finding matches or when the 1802 // Return TRUE if we didn't complete finding matches or when the
1703 // 'completefunc' returned "always" in the "refresh" dictionary item. 1803 // 'completefunc' returned "always" in the "refresh" dictionary item.
1704 return compl_was_interrupted 1804 return compl_was_interrupted
1705 || ((ctrl_x_mode == CTRL_X_FUNCTION || ctrl_x_mode == CTRL_X_OMNI) 1805 || ((ctrl_x_mode_function() || ctrl_x_mode_omni())
1706 && compl_opt_refresh_always); 1806 && compl_opt_refresh_always);
1707 } 1807 }
1708 1808
1709 /* 1809 /*
1710 * Called after changing "compl_leader". 1810 * Called after changing "compl_leader".
1714 static void 1814 static void
1715 ins_compl_new_leader(void) 1815 ins_compl_new_leader(void)
1716 { 1816 {
1717 ins_compl_del_pum(); 1817 ins_compl_del_pum();
1718 ins_compl_delete(); 1818 ins_compl_delete();
1719 ins_bytes(compl_leader + ins_compl_len()); 1819 ins_bytes(compl_leader + get_compl_len());
1720 compl_used_match = FALSE; 1820 compl_used_match = FALSE;
1721 1821
1722 if (compl_started) 1822 if (compl_started)
1723 ins_compl_set_original_text(compl_leader); 1823 ins_compl_set_original_text(compl_leader);
1724 else 1824 else
1757 /* 1857 /*
1758 * Return the length of the completion, from the completion start column to 1858 * Return the length of the completion, from the completion start column to
1759 * the cursor column. Making sure it never goes below zero. 1859 * the cursor column. Making sure it never goes below zero.
1760 */ 1860 */
1761 static int 1861 static int
1762 ins_compl_len(void) 1862 get_compl_len(void)
1763 { 1863 {
1764 int off = (int)curwin->w_cursor.col - (int)compl_col; 1864 int off = (int)curwin->w_cursor.col - (int)compl_col;
1765 1865
1766 if (off < 0) 1866 if (off < 0)
1767 return 0; 1867 return 0;
1836 char_u *p; 1936 char_u *p;
1837 1937
1838 // Replace the original text entry. 1938 // Replace the original text entry.
1839 // The CP_ORIGINAL_TEXT flag is either at the first item or might possibly 1939 // The CP_ORIGINAL_TEXT flag is either at the first item or might possibly
1840 // be at the last item for backward completion 1940 // be at the last item for backward completion
1841 if (ins_compl_at_original_text(compl_first_match)) // safety check 1941 if (match_at_original_text(compl_first_match)) // safety check
1842 { 1942 {
1843 p = vim_strsave(str); 1943 p = vim_strsave(str);
1844 if (p != NULL) 1944 if (p != NULL)
1845 { 1945 {
1846 vim_free(compl_first_match->cp_str); 1946 vim_free(compl_first_match->cp_str);
1847 compl_first_match->cp_str = p; 1947 compl_first_match->cp_str = p;
1848 } 1948 }
1849 } 1949 }
1850 else if (compl_first_match->cp_prev != NULL 1950 else if (compl_first_match->cp_prev != NULL
1851 && ins_compl_at_original_text(compl_first_match->cp_prev)) 1951 && match_at_original_text(compl_first_match->cp_prev))
1852 { 1952 {
1853 p = vim_strsave(str); 1953 p = vim_strsave(str);
1854 if (p != NULL) 1954 if (p != NULL)
1855 { 1955 {
1856 vim_free(compl_first_match->cp_prev->cp_str); 1956 vim_free(compl_first_match->cp_prev->cp_str);
1874 p = compl_shown_match->cp_str; 1974 p = compl_shown_match->cp_str;
1875 if ((int)STRLEN(p) <= len) // the match is too short 1975 if ((int)STRLEN(p) <= len) // the match is too short
1876 { 1976 {
1877 // When still at the original match use the first entry that matches 1977 // When still at the original match use the first entry that matches
1878 // the leader. 1978 // the leader.
1879 if (!ins_compl_at_original_text(compl_shown_match)) 1979 if (!match_at_original_text(compl_shown_match))
1880 return; 1980 return;
1881 1981
1882 p = NULL; 1982 p = NULL;
1883 for (cp = compl_shown_match->cp_next; cp != NULL 1983 for (cp = compl_shown_match->cp_next; cp != NULL
1884 && cp != compl_first_match; cp = cp->cp_next) 1984 && !is_first_match(cp); cp = cp->cp_next)
1885 { 1985 {
1886 if (compl_leader == NULL 1986 if (compl_leader == NULL
1887 || ins_compl_equal(cp, compl_leader, 1987 || ins_compl_equal(cp, compl_leader,
1888 (int)STRLEN(compl_leader))) 1988 (int)STRLEN(compl_leader)))
1889 { 1989 {
1898 c = PTR2CHAR(p); 1998 c = PTR2CHAR(p);
1899 ins_compl_addleader(c); 1999 ins_compl_addleader(c);
1900 } 2000 }
1901 2001
1902 /* 2002 /*
1903 * Set the CTRL-X completion mode based on the key 'c' typed after a CTRL-X. 2003 * Set the CTRL-X completion mode based on the key "c" typed after a CTRL-X.
1904 * Uses the global variables: ctrl_x_mode, edit_submode, edit_submode_pre, 2004 * Uses the global variables: ctrl_x_mode, edit_submode, edit_submode_pre,
1905 * compl_cont_mode and compl_cont_status. 2005 * compl_cont_mode and compl_cont_status.
1906 * Returns TRUE when the character is not to be inserted. 2006 * Returns TRUE when the character is not to be inserted.
1907 */ 2007 */
1908 static int 2008 static int
2103 // but only do this, if the Popup is still visible 2203 // but only do this, if the Popup is still visible
2104 if (c == Ctrl_E) 2204 if (c == Ctrl_E)
2105 { 2205 {
2106 ins_compl_delete(); 2206 ins_compl_delete();
2107 if (compl_leader != NULL) 2207 if (compl_leader != NULL)
2108 ins_bytes(compl_leader + ins_compl_len()); 2208 ins_bytes(compl_leader + get_compl_len());
2109 else if (compl_first_match != NULL) 2209 else if (compl_first_match != NULL)
2110 ins_bytes(compl_orig_text + ins_compl_len()); 2210 ins_bytes(compl_orig_text + get_compl_len());
2111 retval = TRUE; 2211 retval = TRUE;
2112 } 2212 }
2113 2213
2114 auto_format(FALSE, TRUE); 2214 auto_format(FALSE, TRUE);
2115 2215
2223 ctrl_x_mode = CTRL_X_NOT_DEFINED_YET; 2323 ctrl_x_mode = CTRL_X_NOT_DEFINED_YET;
2224 } 2324 }
2225 } 2325 }
2226 2326
2227 // Set "compl_get_longest" when finding the first matches. 2327 // Set "compl_get_longest" when finding the first matches.
2228 if (ctrl_x_mode == CTRL_X_NOT_DEFINED_YET 2328 if (ctrl_x_mode_not_defined_yet()
2229 || (ctrl_x_mode == CTRL_X_NORMAL && !compl_started)) 2329 || (ctrl_x_mode_normal() && !compl_started))
2230 { 2330 {
2231 compl_get_longest = (strstr((char *)p_cot, "longest") != NULL); 2331 compl_get_longest = (strstr((char *)p_cot, "longest") != NULL);
2232 compl_used_match = TRUE; 2332 compl_used_match = TRUE;
2233 2333
2234 } 2334 }
2235 2335
2236 if (ctrl_x_mode == CTRL_X_NOT_DEFINED_YET) 2336 if (ctrl_x_mode_not_defined_yet())
2237 // We have just typed CTRL-X and aren't quite sure which CTRL-X mode 2337 // We have just typed CTRL-X and aren't quite sure which CTRL-X mode
2238 // it will be yet. Now we decide. 2338 // it will be yet. Now we decide.
2239 retval = set_ctrl_x_mode(c); 2339 retval = set_ctrl_x_mode(c);
2240 else if (ctrl_x_mode != CTRL_X_NORMAL) 2340 else if (ctrl_x_mode_not_default())
2241 { 2341 {
2242 // We're already in CTRL-X mode, do we stay in it? 2342 // We're already in CTRL-X mode, do we stay in it?
2243 if (!vim_is_ctrl_x_key(c)) 2343 if (!vim_is_ctrl_x_key(c))
2244 { 2344 {
2245 if (ctrl_x_mode == CTRL_X_SCROLL) 2345 if (ctrl_x_mode_scroll())
2246 ctrl_x_mode = CTRL_X_NORMAL; 2346 ctrl_x_mode = CTRL_X_NORMAL;
2247 else 2347 else
2248 ctrl_x_mode = CTRL_X_FINISHED; 2348 ctrl_x_mode = CTRL_X_FINISHED;
2249 edit_submode = NULL; 2349 edit_submode = NULL;
2250 } 2350 }
2255 { 2355 {
2256 // Show error message from attempted keyword completion (probably 2356 // Show error message from attempted keyword completion (probably
2257 // 'Pattern not found') until another key is hit, then go back to 2357 // 'Pattern not found') until another key is hit, then go back to
2258 // showing what mode we are in. 2358 // showing what mode we are in.
2259 showmode(); 2359 showmode();
2260 if ((ctrl_x_mode == CTRL_X_NORMAL && c != Ctrl_N && c != Ctrl_P 2360 if ((ctrl_x_mode_normal() && c != Ctrl_N && c != Ctrl_P
2261 && c != Ctrl_R && !ins_compl_pum_key(c)) 2361 && c != Ctrl_R && !ins_compl_pum_key(c))
2262 || ctrl_x_mode == CTRL_X_FINISHED) 2362 || ctrl_x_mode == CTRL_X_FINISHED)
2263 retval = ins_compl_stop(c, prev_mode, retval); 2363 retval = ins_compl_stop(c, prev_mode, retval);
2264 } 2364 }
2265 else if (ctrl_x_mode == CTRL_X_LOCAL_MSG) 2365 else if (ctrl_x_mode == CTRL_X_LOCAL_MSG)
2388 return retval; 2488 return retval;
2389 } 2489 }
2390 2490
2391 /* 2491 /*
2392 * Copy the global 'completefunc' callback function to the buffer-local 2492 * Copy the global 'completefunc' callback function to the buffer-local
2393 * 'completefunc' callback for 'buf'. 2493 * 'completefunc' callback for "buf".
2394 */ 2494 */
2395 void 2495 void
2396 set_buflocal_cfu_callback(buf_T *buf UNUSED) 2496 set_buflocal_cfu_callback(buf_T *buf UNUSED)
2397 { 2497 {
2398 # ifdef FEAT_EVAL 2498 # ifdef FEAT_EVAL
2418 return retval; 2518 return retval;
2419 } 2519 }
2420 2520
2421 /* 2521 /*
2422 * Copy the global 'omnifunc' callback function to the buffer-local 'omnifunc' 2522 * Copy the global 'omnifunc' callback function to the buffer-local 'omnifunc'
2423 * callback for 'buf'. 2523 * callback for "buf".
2424 */ 2524 */
2425 void 2525 void
2426 set_buflocal_ofu_callback(buf_T *buf UNUSED) 2526 set_buflocal_ofu_callback(buf_T *buf UNUSED)
2427 { 2527 {
2428 # ifdef FEAT_EVAL 2528 # ifdef FEAT_EVAL
2456 return retval; 2556 return retval;
2457 } 2557 }
2458 2558
2459 /* 2559 /*
2460 * Mark the global 'completefunc' 'omnifunc' and 'thesaurusfunc' callbacks with 2560 * Mark the global 'completefunc' 'omnifunc' and 'thesaurusfunc' callbacks with
2461 * 'copyID' so that they are not garbage collected. 2561 * "copyID" so that they are not garbage collected.
2462 */ 2562 */
2463 int 2563 int
2464 set_ref_in_insexpand_funcs(int copyID) 2564 set_ref_in_insexpand_funcs(int copyID)
2465 { 2565 {
2466 int abort = FALSE; 2566 int abort = FALSE;
2471 2571
2472 return abort; 2572 return abort;
2473 } 2573 }
2474 2574
2475 /* 2575 /*
2476 * Get the user-defined completion function name for completion 'type' 2576 * Get the user-defined completion function name for completion "type"
2477 */ 2577 */
2478 static char_u * 2578 static char_u *
2479 get_complete_funcname(int type) 2579 get_complete_funcname(int type)
2480 { 2580 {
2481 switch (type) 2581 switch (type)
2492 } 2592 }
2493 2593
2494 /* 2594 /*
2495 * Get the callback to use for insert mode completion. 2595 * Get the callback to use for insert mode completion.
2496 */ 2596 */
2497 callback_T * 2597 static callback_T *
2498 get_insert_callback(int type) 2598 get_insert_callback(int type)
2499 { 2599 {
2500 if (type == CTRL_X_FUNCTION) 2600 if (type == CTRL_X_FUNCTION)
2501 return &curbuf->b_cfu_cb; 2601 return &curbuf->b_cfu_cb;
2502 if (type == CTRL_X_OMNI) 2602 if (type == CTRL_X_OMNI)
2700 int save_w_wrow = curwin->w_wrow; 2800 int save_w_wrow = curwin->w_wrow;
2701 int save_w_leftcol = curwin->w_leftcol; 2801 int save_w_leftcol = curwin->w_leftcol;
2702 int flags = CP_ORIGINAL_TEXT; 2802 int flags = CP_ORIGINAL_TEXT;
2703 2803
2704 // If already doing completions stop it. 2804 // If already doing completions stop it.
2705 if (ctrl_x_mode != CTRL_X_NORMAL) 2805 if (ctrl_x_mode_not_default())
2706 ins_compl_prep(' '); 2806 ins_compl_prep(' ');
2707 ins_compl_clear(); 2807 ins_compl_clear();
2708 ins_compl_free(); 2808 ins_compl_free();
2709 2809
2710 compl_direction = FORWARD; 2810 compl_direction = FORWARD;
2818 * Return Insert completion mode name string 2918 * Return Insert completion mode name string
2819 */ 2919 */
2820 static char_u * 2920 static char_u *
2821 ins_compl_mode(void) 2921 ins_compl_mode(void)
2822 { 2922 {
2823 if (ctrl_x_mode == CTRL_X_NOT_DEFINED_YET || ctrl_x_mode == CTRL_X_SCROLL 2923 if (ctrl_x_mode_not_defined_yet() || ctrl_x_mode_scroll() || compl_started)
2824 || compl_started)
2825 return (char_u *)ctrl_x_mode_names[ctrl_x_mode & ~CTRL_X_WANT_IDENT]; 2924 return (char_u *)ctrl_x_mode_names[ctrl_x_mode & ~CTRL_X_WANT_IDENT];
2826 2925
2827 return (char_u *)""; 2926 return (char_u *)"";
2828 } 2927 }
2829 2928
2835 ins_compl_update_sequence_numbers() 2934 ins_compl_update_sequence_numbers()
2836 { 2935 {
2837 int number = 0; 2936 int number = 0;
2838 compl_T *match; 2937 compl_T *match;
2839 2938
2840 if (compl_direction == FORWARD) 2939 if (compl_dir_forward())
2841 { 2940 {
2842 // search backwards for the first valid (!= -1) number. 2941 // search backwards for the first valid (!= -1) number.
2843 // This should normally succeed already at the first loop 2942 // This should normally succeed already at the first loop
2844 // cycle, so it's fast! 2943 // cycle, so it's fast!
2845 for (match = compl_curr_match->cp_prev; match != NULL 2944 for (match = compl_curr_match->cp_prev; match != NULL
2846 && match != compl_first_match; 2945 && !is_first_match(match); match = match->cp_prev)
2847 match = match->cp_prev)
2848 if (match->cp_number != -1) 2946 if (match->cp_number != -1)
2849 { 2947 {
2850 number = match->cp_number; 2948 number = match->cp_number;
2851 break; 2949 break;
2852 } 2950 }
2862 { 2960 {
2863 // search forwards (upwards) for the first valid (!= -1) 2961 // search forwards (upwards) for the first valid (!= -1)
2864 // number. This should normally succeed already at the 2962 // number. This should normally succeed already at the
2865 // first loop cycle, so it's fast! 2963 // first loop cycle, so it's fast!
2866 for (match = compl_curr_match->cp_next; match != NULL 2964 for (match = compl_curr_match->cp_next; match != NULL
2867 && match != compl_first_match; 2965 && !is_first_match(match); match = match->cp_next)
2868 match = match->cp_next)
2869 if (match->cp_number != -1) 2966 if (match->cp_number != -1)
2870 { 2967 {
2871 number = match->cp_number; 2968 number = match->cp_number;
2872 break; 2969 break;
2873 } 2970 }
2939 if (ret == OK && compl_first_match != NULL) 3036 if (ret == OK && compl_first_match != NULL)
2940 { 3037 {
2941 match = compl_first_match; 3038 match = compl_first_match;
2942 do 3039 do
2943 { 3040 {
2944 if (!ins_compl_at_original_text(match)) 3041 if (!match_at_original_text(match))
2945 { 3042 {
2946 di = dict_alloc(); 3043 di = dict_alloc();
2947 if (di == NULL) 3044 if (di == NULL)
2948 return; 3045 return;
2949 ret = list_append_dict(li, di); 3046 ret = list_append_dict(li, di);
2960 else 3057 else
2961 dict_add_tv(di, "user_data", &match->cp_user_data); 3058 dict_add_tv(di, "user_data", &match->cp_user_data);
2962 } 3059 }
2963 match = match->cp_next; 3060 match = match->cp_next;
2964 } 3061 }
2965 while (match != NULL && match != compl_first_match); 3062 while (match != NULL && !is_first_match(match));
2966 } 3063 }
2967 } 3064 }
2968 3065
2969 if (ret == OK && (what_flag & CI_WHAT_SELECTED)) 3066 if (ret == OK && (what_flag & CI_WHAT_SELECTED))
2970 { 3067 {
3085 { 3182 {
3086 st->ins_buf = curbuf; 3183 st->ins_buf = curbuf;
3087 st->first_match_pos = *start_match_pos; 3184 st->first_match_pos = *start_match_pos;
3088 // Move the cursor back one character so that ^N can match the 3185 // Move the cursor back one character so that ^N can match the
3089 // word immediately after the cursor. 3186 // word immediately after the cursor.
3090 if (ctrl_x_mode == CTRL_X_NORMAL && dec(&st->first_match_pos) < 0) 3187 if (ctrl_x_mode_normal() && dec(&st->first_match_pos) < 0)
3091 { 3188 {
3092 // Move the cursor to after the last character in the 3189 // Move the cursor to after the last character in the
3093 // buffer, so that word at start of buffer is found 3190 // buffer, so that word at start of buffer is found
3094 // correctly. 3191 // correctly.
3095 st->first_match_pos.lnum = st->ins_buf->b_ml.ml_line_count; 3192 st->first_match_pos.lnum = st->ins_buf->b_ml.ml_line_count;
3239 // Find up to TAG_MANY matches. Avoids that an enormous number 3336 // Find up to TAG_MANY matches. Avoids that an enormous number
3240 // of matches is found when compl_pattern is empty 3337 // of matches is found when compl_pattern is empty
3241 g_tag_at_cursor = TRUE; 3338 g_tag_at_cursor = TRUE;
3242 if (find_tags(compl_pattern, &num_matches, &matches, 3339 if (find_tags(compl_pattern, &num_matches, &matches,
3243 TAG_REGEXP | TAG_NAMES | TAG_NOIC | TAG_INS_COMP 3340 TAG_REGEXP | TAG_NAMES | TAG_NOIC | TAG_INS_COMP
3244 | (ctrl_x_mode != CTRL_X_NORMAL ? TAG_VERBOSE : 0), 3341 | (ctrl_x_mode_not_default() ? TAG_VERBOSE : 0),
3245 TAG_MANY, curbuf->b_ffname) == OK && num_matches > 0) 3342 TAG_MANY, curbuf->b_ffname) == OK && num_matches > 0)
3246 ins_compl_add_matches(num_matches, matches, p_ic); 3343 ins_compl_add_matches(num_matches, matches, p_ic);
3247 g_tag_at_cursor = FALSE; 3344 g_tag_at_cursor = FALSE;
3248 p_ic = save_p_ic; 3345 p_ic = save_p_ic;
3249 } 3346 }
3336 *match_len = 0; 3433 *match_len = 0;
3337 ptr = ml_get_buf(ins_buf, cur_match_pos->lnum, FALSE) + 3434 ptr = ml_get_buf(ins_buf, cur_match_pos->lnum, FALSE) +
3338 cur_match_pos->col; 3435 cur_match_pos->col;
3339 if (ctrl_x_mode_line_or_eval()) 3436 if (ctrl_x_mode_line_or_eval())
3340 { 3437 {
3341 if (compl_cont_status & CONT_ADDING) 3438 if (compl_status_adding())
3342 { 3439 {
3343 if (cur_match_pos->lnum >= ins_buf->b_ml.ml_line_count) 3440 if (cur_match_pos->lnum >= ins_buf->b_ml.ml_line_count)
3344 return NULL; 3441 return NULL;
3345 ptr = ml_get_buf(ins_buf, cur_match_pos->lnum + 1, FALSE); 3442 ptr = ml_get_buf(ins_buf, cur_match_pos->lnum + 1, FALSE);
3346 if (!p_paste) 3443 if (!p_paste)
3350 } 3447 }
3351 else 3448 else
3352 { 3449 {
3353 char_u *tmp_ptr = ptr; 3450 char_u *tmp_ptr = ptr;
3354 3451
3355 if (compl_cont_status & CONT_ADDING) 3452 if (compl_status_adding())
3356 { 3453 {
3357 tmp_ptr += compl_length; 3454 tmp_ptr += compl_length;
3358 // Skip if already inside a word. 3455 // Skip if already inside a word.
3359 if (vim_iswordp(tmp_ptr)) 3456 if (vim_iswordp(tmp_ptr))
3360 return NULL; 3457 return NULL;
3363 } 3460 }
3364 // Find end of this word. 3461 // Find end of this word.
3365 tmp_ptr = find_word_end(tmp_ptr); 3462 tmp_ptr = find_word_end(tmp_ptr);
3366 len = (int)(tmp_ptr - ptr); 3463 len = (int)(tmp_ptr - ptr);
3367 3464
3368 if ((compl_cont_status & CONT_ADDING) && len == compl_length) 3465 if (compl_status_adding() && len == compl_length)
3369 { 3466 {
3370 if (cur_match_pos->lnum < ins_buf->b_ml.ml_line_count) 3467 if (cur_match_pos->lnum < ins_buf->b_ml.ml_line_count)
3371 { 3468 {
3372 // Try next line, if any. the new word will be 3469 // Try next line, if any. the new word will be
3373 // "join" as if the normal command "J" was used. 3470 // "join" as if the normal command "J" was used.
3455 3552
3456 ++msg_silent; // Don't want messages for wrapscan. 3553 ++msg_silent; // Don't want messages for wrapscan.
3457 3554
3458 // ctrl_x_mode_line_or_eval() || word-wise search that 3555 // ctrl_x_mode_line_or_eval() || word-wise search that
3459 // has added a word that was at the beginning of the line 3556 // has added a word that was at the beginning of the line
3460 if (ctrl_x_mode_line_or_eval() 3557 if (ctrl_x_mode_line_or_eval() || (compl_cont_status & CONT_SOL))
3461 || (compl_cont_status & CONT_SOL))
3462 found_new_match = search_for_exact_line(st->ins_buf, 3558 found_new_match = search_for_exact_line(st->ins_buf,
3463 st->cur_match_pos, compl_direction, compl_pattern); 3559 st->cur_match_pos, compl_direction, compl_pattern);
3464 else 3560 else
3465 found_new_match = searchit(NULL, st->ins_buf, st->cur_match_pos, 3561 found_new_match = searchit(NULL, st->ins_buf, st->cur_match_pos,
3466 NULL, compl_direction, compl_pattern, 1L, 3562 NULL, compl_direction, compl_pattern, 1L,
3477 else if (st->first_match_pos.lnum == st->last_match_pos.lnum 3573 else if (st->first_match_pos.lnum == st->last_match_pos.lnum
3478 && st->first_match_pos.col == st->last_match_pos.col) 3574 && st->first_match_pos.col == st->last_match_pos.col)
3479 { 3575 {
3480 found_new_match = FAIL; 3576 found_new_match = FAIL;
3481 } 3577 }
3482 else if ((compl_direction == FORWARD) 3578 else if (compl_dir_forward()
3483 && (st->prev_match_pos.lnum > st->cur_match_pos->lnum 3579 && (st->prev_match_pos.lnum > st->cur_match_pos->lnum
3484 || (st->prev_match_pos.lnum == st->cur_match_pos->lnum 3580 || (st->prev_match_pos.lnum == st->cur_match_pos->lnum
3485 && st->prev_match_pos.col >= st->cur_match_pos->col))) 3581 && st->prev_match_pos.col >= st->cur_match_pos->col)))
3486 { 3582 {
3487 if (looped_around) 3583 if (looped_around)
3488 found_new_match = FAIL; 3584 found_new_match = FAIL;
3489 else 3585 else
3490 looped_around = TRUE; 3586 looped_around = TRUE;
3491 } 3587 }
3492 else if ((compl_direction != FORWARD) 3588 else if (!compl_dir_forward()
3493 && (st->prev_match_pos.lnum < st->cur_match_pos->lnum 3589 && (st->prev_match_pos.lnum < st->cur_match_pos->lnum
3494 || (st->prev_match_pos.lnum == st->cur_match_pos->lnum 3590 || (st->prev_match_pos.lnum == st->cur_match_pos->lnum
3495 && st->prev_match_pos.col <= st->cur_match_pos->col))) 3591 && st->prev_match_pos.col <= st->cur_match_pos->col)))
3496 { 3592 {
3497 if (looped_around) 3593 if (looped_around)
3502 st->prev_match_pos = *st->cur_match_pos; 3598 st->prev_match_pos = *st->cur_match_pos;
3503 if (found_new_match == FAIL) 3599 if (found_new_match == FAIL)
3504 break; 3600 break;
3505 3601
3506 // when ADDING, the text before the cursor matches, skip it 3602 // when ADDING, the text before the cursor matches, skip it
3507 if ((compl_cont_status & CONT_ADDING) && st->ins_buf == curbuf 3603 if (compl_status_adding() && st->ins_buf == curbuf
3508 && start_pos->lnum == st->cur_match_pos->lnum 3604 && start_pos->lnum == st->cur_match_pos->lnum
3509 && start_pos->col == st->cur_match_pos->col) 3605 && start_pos->col == st->cur_match_pos->col)
3510 continue; 3606 continue;
3511 3607
3512 ptr = ins_comp_get_next_word_or_line(st->ins_buf, st->cur_match_pos, 3608 ptr = ins_comp_get_next_word_or_line(st->ins_buf, st->cur_match_pos,
3527 3623
3528 return found_new_match; 3624 return found_new_match;
3529 } 3625 }
3530 3626
3531 /* 3627 /*
3532 * get the next set of completion matches for 'type'. 3628 * get the next set of completion matches for "type".
3533 * Returns TRUE if a new match is found. Otherwise returns FALSE. 3629 * Returns TRUE if a new match is found. Otherwise returns FALSE.
3534 */ 3630 */
3535 static int 3631 static int
3536 get_next_completion_match(int type, ins_compl_next_state_T *st, pos_T *ini) 3632 get_next_completion_match(int type, ins_compl_next_state_T *st, pos_T *ini)
3537 { 3633 {
3621 } 3717 }
3622 else if (st.ins_buf != curbuf && !buf_valid(st.ins_buf)) 3718 else if (st.ins_buf != curbuf && !buf_valid(st.ins_buf))
3623 st.ins_buf = curbuf; // In case the buffer was wiped out. 3719 st.ins_buf = curbuf; // In case the buffer was wiped out.
3624 3720
3625 compl_old_match = compl_curr_match; // remember the last current match 3721 compl_old_match = compl_curr_match; // remember the last current match
3626 st.cur_match_pos = (compl_direction == FORWARD) 3722 st.cur_match_pos = (compl_dir_forward())
3627 ? &st.last_match_pos : &st.first_match_pos; 3723 ? &st.last_match_pos : &st.first_match_pos;
3628 3724
3629 // For ^N/^P loop over all the flags/windows/buffers in 'complete'. 3725 // For ^N/^P loop over all the flags/windows/buffers in 'complete'.
3630 for (;;) 3726 for (;;)
3631 { 3727 {
3633 st.set_match_pos = FALSE; 3729 st.set_match_pos = FALSE;
3634 3730
3635 // For ^N/^P pick a new entry from e_cpt if compl_started is off, 3731 // For ^N/^P pick a new entry from e_cpt if compl_started is off,
3636 // or if found_all says this entry is done. For ^X^L only use the 3732 // or if found_all says this entry is done. For ^X^L only use the
3637 // entries from 'complete' that look in loaded buffers. 3733 // entries from 'complete' that look in loaded buffers.
3638 if ((ctrl_x_mode == CTRL_X_NORMAL 3734 if ((ctrl_x_mode_normal() || ctrl_x_mode_line_or_eval())
3639 || ctrl_x_mode_line_or_eval())
3640 && (!compl_started || st.found_all)) 3735 && (!compl_started || st.found_all))
3641 { 3736 {
3642 int status = process_next_cpt_value(&st, &type, ini); 3737 int status = process_next_cpt_value(&st, &type, ini);
3643 3738
3644 if (status == INS_COMPL_CPT_END) 3739 if (status == INS_COMPL_CPT_END)
3656 found_new_match = get_next_completion_match(type, &st, ini); 3751 found_new_match = get_next_completion_match(type, &st, ini);
3657 3752
3658 // break the loop for specialized modes (use 'complete' just for the 3753 // break the loop for specialized modes (use 'complete' just for the
3659 // generic ctrl_x_mode == CTRL_X_NORMAL) or when we've found a new 3754 // generic ctrl_x_mode == CTRL_X_NORMAL) or when we've found a new
3660 // match 3755 // match
3661 if ((ctrl_x_mode != CTRL_X_NORMAL 3756 if ((ctrl_x_mode_not_default() && !ctrl_x_mode_line_or_eval())
3662 && !ctrl_x_mode_line_or_eval()) || found_new_match != FAIL) 3757 || found_new_match != FAIL)
3663 { 3758 {
3664 if (got_int) 3759 if (got_int)
3665 break; 3760 break;
3666 // Fill the popup menu as soon as possible. 3761 // Fill the popup menu as soon as possible.
3667 if (type != -1) 3762 if (type != -1)
3668 ins_compl_check_keys(0, FALSE); 3763 ins_compl_check_keys(0, FALSE);
3669 3764
3670 if ((ctrl_x_mode != CTRL_X_NORMAL 3765 if ((ctrl_x_mode_not_default()
3671 && !ctrl_x_mode_line_or_eval()) || compl_interrupted) 3766 && !ctrl_x_mode_line_or_eval()) || compl_interrupted)
3672 break; 3767 break;
3673 compl_started = TRUE; 3768 compl_started = TRUE;
3674 } 3769 }
3675 else 3770 else
3681 compl_started = FALSE; 3776 compl_started = FALSE;
3682 } 3777 }
3683 } 3778 }
3684 compl_started = TRUE; 3779 compl_started = TRUE;
3685 3780
3686 if ((ctrl_x_mode == CTRL_X_NORMAL || ctrl_x_mode_line_or_eval()) 3781 if ((ctrl_x_mode_normal() || ctrl_x_mode_line_or_eval())
3687 && *st.e_cpt == NUL) // Got to end of 'complete' 3782 && *st.e_cpt == NUL) // Got to end of 'complete'
3688 found_new_match = FAIL; 3783 found_new_match = FAIL;
3689 3784
3690 i = -1; // total of matches, unknown 3785 i = -1; // total of matches, unknown
3691 if (found_new_match == FAIL || (ctrl_x_mode != CTRL_X_NORMAL 3786 if (found_new_match == FAIL || (ctrl_x_mode_not_default()
3692 && !ctrl_x_mode_line_or_eval())) 3787 && !ctrl_x_mode_line_or_eval()))
3693 i = ins_compl_make_cyclic(); 3788 i = ins_compl_make_cyclic();
3694 3789
3695 if (compl_old_match != NULL) 3790 if (compl_old_match != NULL)
3696 { 3791 {
3697 // If several matches were added (FORWARD) or the search failed and has 3792 // If several matches were added (FORWARD) or the search failed and has
3698 // just been made cyclic then we have to move compl_curr_match to the 3793 // just been made cyclic then we have to move compl_curr_match to the
3699 // next or previous entry (if any) -- Acevedo 3794 // next or previous entry (if any) -- Acevedo
3700 compl_curr_match = compl_direction == FORWARD ? compl_old_match->cp_next 3795 compl_curr_match = compl_dir_forward() ? compl_old_match->cp_next
3701 : compl_old_match->cp_prev; 3796 : compl_old_match->cp_prev;
3702 if (compl_curr_match == NULL) 3797 if (compl_curr_match == NULL)
3703 compl_curr_match = compl_old_match; 3798 compl_curr_match = compl_old_match;
3704 } 3799 }
3705 trigger_modechanged(); 3800 trigger_modechanged();
3715 ins_compl_update_shown_match(void) 3810 ins_compl_update_shown_match(void)
3716 { 3811 {
3717 while (!ins_compl_equal(compl_shown_match, 3812 while (!ins_compl_equal(compl_shown_match,
3718 compl_leader, (int)STRLEN(compl_leader)) 3813 compl_leader, (int)STRLEN(compl_leader))
3719 && compl_shown_match->cp_next != NULL 3814 && compl_shown_match->cp_next != NULL
3720 && compl_shown_match->cp_next != compl_first_match) 3815 && !is_first_match(compl_shown_match->cp_next))
3721 compl_shown_match = compl_shown_match->cp_next; 3816 compl_shown_match = compl_shown_match->cp_next;
3722 3817
3723 // If we didn't find it searching forward, and compl_shows_dir is 3818 // If we didn't find it searching forward, and compl_shows_dir is
3724 // backward, find the last match. 3819 // backward, find the last match.
3725 if (compl_shows_dir == BACKWARD 3820 if (compl_shows_dir_backward()
3726 && !ins_compl_equal(compl_shown_match, 3821 && !ins_compl_equal(compl_shown_match,
3727 compl_leader, (int)STRLEN(compl_leader)) 3822 compl_leader, (int)STRLEN(compl_leader))
3728 && (compl_shown_match->cp_next == NULL 3823 && (compl_shown_match->cp_next == NULL
3729 || compl_shown_match->cp_next == compl_first_match)) 3824 || is_first_match(compl_shown_match->cp_next)))
3730 { 3825 {
3731 while (!ins_compl_equal(compl_shown_match, 3826 while (!ins_compl_equal(compl_shown_match,
3732 compl_leader, (int)STRLEN(compl_leader)) 3827 compl_leader, (int)STRLEN(compl_leader))
3733 && compl_shown_match->cp_prev != NULL 3828 && compl_shown_match->cp_prev != NULL
3734 && compl_shown_match->cp_prev != compl_first_match) 3829 && !is_first_match(compl_shown_match->cp_prev))
3735 compl_shown_match = compl_shown_match->cp_prev; 3830 compl_shown_match = compl_shown_match->cp_prev;
3736 } 3831 }
3737 } 3832 }
3738 3833
3739 /* 3834 /*
3744 { 3839 {
3745 int col; 3840 int col;
3746 3841
3747 // In insert mode: Delete the typed part. 3842 // In insert mode: Delete the typed part.
3748 // In replace mode: Put the old characters back, if any. 3843 // In replace mode: Put the old characters back, if any.
3749 col = compl_col + (compl_cont_status & CONT_ADDING ? compl_length : 0); 3844 col = compl_col + (compl_status_adding() ? compl_length : 0);
3750 if ((int)curwin->w_cursor.col > col) 3845 if ((int)curwin->w_cursor.col > col)
3751 { 3846 {
3752 if (stop_arrow() == FAIL) 3847 if (stop_arrow() == FAIL)
3753 return; 3848 return;
3754 backspace_until_column(col); 3849 backspace_until_column(col);
3768 * "in_compl_func" is TRUE when called from complete_check(). 3863 * "in_compl_func" is TRUE when called from complete_check().
3769 */ 3864 */
3770 void 3865 void
3771 ins_compl_insert(int in_compl_func) 3866 ins_compl_insert(int in_compl_func)
3772 { 3867 {
3773 int compl_len = ins_compl_len(); 3868 int compl_len = get_compl_len();
3774 3869
3775 // Make sure we don't go over the end of the string, this can happen with 3870 // Make sure we don't go over the end of the string, this can happen with
3776 // illegal bytes. 3871 // illegal bytes.
3777 if (compl_len < (int)STRLEN(compl_shown_match->cp_str)) 3872 if (compl_len < (int)STRLEN(compl_shown_match->cp_str))
3778 ins_bytes(compl_shown_match->cp_str + compl_len); 3873 ins_bytes(compl_shown_match->cp_str + compl_len);
3779 if (ins_compl_at_original_text(compl_shown_match)) 3874 if (match_at_original_text(compl_shown_match))
3780 compl_used_match = FALSE; 3875 compl_used_match = FALSE;
3781 else 3876 else
3782 compl_used_match = TRUE; 3877 compl_used_match = TRUE;
3783 #ifdef FEAT_EVAL 3878 #ifdef FEAT_EVAL
3784 { 3879 {
3825 msg_hist_off = FALSE; 3920 msg_hist_off = FALSE;
3826 redraw_cmdline = FALSE; // don't overwrite! 3921 redraw_cmdline = FALSE; // don't overwrite!
3827 } 3922 }
3828 3923
3829 /* 3924 /*
3830 * Find the next set of matches for completion. Repeat the completion 'todo' 3925 * Find the next set of matches for completion. Repeat the completion "todo"
3831 * times. The number of matches found is returned in 'num_matches'. 3926 * times. The number of matches found is returned in 'num_matches'.
3832 * 3927 *
3833 * If "allow_get_expansion" is TRUE, then ins_compl_get_exp() may be called to 3928 * If "allow_get_expansion" is TRUE, then ins_compl_get_exp() may be called to
3834 * get more completions. If it is FALSE, then do nothing when there are no more 3929 * get more completions. If it is FALSE, then do nothing when there are no more
3835 * completions in the given direction. 3930 * completions in the given direction.
3849 int found_end = FALSE; 3944 int found_end = FALSE;
3850 compl_T *found_compl = NULL; 3945 compl_T *found_compl = NULL;
3851 3946
3852 while (--todo >= 0) 3947 while (--todo >= 0)
3853 { 3948 {
3854 if (compl_shows_dir == FORWARD && compl_shown_match->cp_next != NULL) 3949 if (compl_shows_dir_forward() && compl_shown_match->cp_next != NULL)
3855 { 3950 {
3856 compl_shown_match = compl_shown_match->cp_next; 3951 compl_shown_match = compl_shown_match->cp_next;
3857 found_end = (compl_first_match != NULL 3952 found_end = (compl_first_match != NULL
3858 && (compl_shown_match->cp_next == compl_first_match 3953 && (is_first_match(compl_shown_match->cp_next)
3859 || compl_shown_match == compl_first_match)); 3954 || is_first_match(compl_shown_match)));
3860 } 3955 }
3861 else if (compl_shows_dir == BACKWARD 3956 else if (compl_shows_dir_backward()
3862 && compl_shown_match->cp_prev != NULL) 3957 && compl_shown_match->cp_prev != NULL)
3863 { 3958 {
3864 found_end = (compl_shown_match == compl_first_match); 3959 found_end = is_first_match(compl_shown_match);
3865 compl_shown_match = compl_shown_match->cp_prev; 3960 compl_shown_match = compl_shown_match->cp_prev;
3866 found_end |= (compl_shown_match == compl_first_match); 3961 found_end |= is_first_match(compl_shown_match);
3867 } 3962 }
3868 else 3963 else
3869 { 3964 {
3870 if (!allow_get_expansion) 3965 if (!allow_get_expansion)
3871 { 3966 {
3872 if (advance) 3967 if (advance)
3873 { 3968 {
3874 if (compl_shows_dir == BACKWARD) 3969 if (compl_shows_dir_backward())
3875 compl_pending -= todo + 1; 3970 compl_pending -= todo + 1;
3876 else 3971 else
3877 compl_pending += todo + 1; 3972 compl_pending += todo + 1;
3878 } 3973 }
3879 return -1; 3974 return -1;
3880 } 3975 }
3881 3976
3882 if (!compl_no_select && advance) 3977 if (!compl_no_select && advance)
3883 { 3978 {
3884 if (compl_shows_dir == BACKWARD) 3979 if (compl_shows_dir_backward())
3885 --compl_pending; 3980 --compl_pending;
3886 else 3981 else
3887 ++compl_pending; 3982 ++compl_pending;
3888 } 3983 }
3889 3984
3907 else 4002 else
3908 break; 4003 break;
3909 } 4004 }
3910 found_end = FALSE; 4005 found_end = FALSE;
3911 } 4006 }
3912 if (!ins_compl_at_original_text(compl_shown_match) 4007 if (!match_at_original_text(compl_shown_match)
3913 && compl_leader != NULL 4008 && compl_leader != NULL
3914 && !ins_compl_equal(compl_shown_match, 4009 && !ins_compl_equal(compl_shown_match,
3915 compl_leader, (int)STRLEN(compl_leader))) 4010 compl_leader, (int)STRLEN(compl_leader)))
3916 ++todo; 4011 ++todo;
3917 else 4012 else
3965 // When user complete function return -1 for findstart which is next 4060 // When user complete function return -1 for findstart which is next
3966 // time of 'always', compl_shown_match become NULL. 4061 // time of 'always', compl_shown_match become NULL.
3967 if (compl_shown_match == NULL) 4062 if (compl_shown_match == NULL)
3968 return -1; 4063 return -1;
3969 4064
3970 if (compl_leader != NULL 4065 if (compl_leader != NULL && !match_at_original_text(compl_shown_match))
3971 && !ins_compl_at_original_text(compl_shown_match))
3972 // Update "compl_shown_match" to the actually shown match 4066 // Update "compl_shown_match" to the actually shown match
3973 ins_compl_update_shown_match(); 4067 ins_compl_update_shown_match();
3974 4068
3975 if (allow_get_expansion && insert_match 4069 if (allow_get_expansion && insert_match
3976 && (!(compl_get_longest || compl_restarting) || compl_used_match)) 4070 && (!(compl_get_longest || compl_restarting) || compl_used_match))
3995 return -1; 4089 return -1;
3996 4090
3997 // Insert the text of the new completion, or the compl_leader. 4091 // Insert the text of the new completion, or the compl_leader.
3998 if (compl_no_insert && !started) 4092 if (compl_no_insert && !started)
3999 { 4093 {
4000 ins_bytes(compl_orig_text + ins_compl_len()); 4094 ins_bytes(compl_orig_text + get_compl_len());
4001 compl_used_match = FALSE; 4095 compl_used_match = FALSE;
4002 } 4096 }
4003 else if (insert_match) 4097 else if (insert_match)
4004 { 4098 {
4005 if (!compl_get_longest || compl_used_match) 4099 if (!compl_get_longest || compl_used_match)
4006 ins_compl_insert(in_compl_func); 4100 ins_compl_insert(in_compl_func);
4007 else 4101 else
4008 ins_bytes(compl_leader + ins_compl_len()); 4102 ins_bytes(compl_leader + get_compl_len());
4009 } 4103 }
4010 else 4104 else
4011 compl_used_match = FALSE; 4105 compl_used_match = FALSE;
4012 4106
4013 if (!allow_get_expansion) 4107 if (!allow_get_expansion)
4189 * Uses the global variables: compl_cont_status and ctrl_x_mode 4283 * Uses the global variables: compl_cont_status and ctrl_x_mode
4190 */ 4284 */
4191 static int 4285 static int
4192 get_normal_compl_info(char_u *line, int startcol, colnr_T curs_col) 4286 get_normal_compl_info(char_u *line, int startcol, colnr_T curs_col)
4193 { 4287 {
4194 if ((compl_cont_status & CONT_SOL) || ctrl_x_mode == CTRL_X_PATH_DEFINES) 4288 if ((compl_cont_status & CONT_SOL) || ctrl_x_mode_path_defines())
4195 { 4289 {
4196 if (!(compl_cont_status & CONT_ADDING)) 4290 if (!compl_status_adding())
4197 { 4291 {
4198 while (--startcol >= 0 && vim_isIDc(line[startcol])) 4292 while (--startcol >= 0 && vim_isIDc(line[startcol]))
4199 ; 4293 ;
4200 compl_col += ++startcol; 4294 compl_col += ++startcol;
4201 compl_length = curs_col - startcol; 4295 compl_length = curs_col - startcol;
4206 else 4300 else
4207 compl_pattern = vim_strnsave(line + compl_col, compl_length); 4301 compl_pattern = vim_strnsave(line + compl_col, compl_length);
4208 if (compl_pattern == NULL) 4302 if (compl_pattern == NULL)
4209 return FAIL; 4303 return FAIL;
4210 } 4304 }
4211 else if (compl_cont_status & CONT_ADDING) 4305 else if (compl_status_adding())
4212 { 4306 {
4213 char_u *prefix = (char_u *)"\\<"; 4307 char_u *prefix = (char_u *)"\\<";
4214 4308
4215 // we need up to 2 extra chars for the prefix 4309 // we need up to 2 extra chars for the prefix
4216 compl_pattern = alloc(quote_meta(NULL, line + compl_col, 4310 compl_pattern = alloc(quote_meta(NULL, line + compl_col,
4389 // Call 'completefunc' or 'omnifunc' or 'thesaurusfunc' and get pattern 4483 // Call 'completefunc' or 'omnifunc' or 'thesaurusfunc' and get pattern
4390 // length as a string 4484 // length as a string
4391 funcname = get_complete_funcname(ctrl_x_mode); 4485 funcname = get_complete_funcname(ctrl_x_mode);
4392 if (*funcname == NUL) 4486 if (*funcname == NUL)
4393 { 4487 {
4394 semsg(_(e_option_str_is_not_set), ctrl_x_mode == CTRL_X_FUNCTION 4488 semsg(_(e_option_str_is_not_set), ctrl_x_mode_function()
4395 ? "completefunc" : "omnifunc"); 4489 ? "completefunc" : "omnifunc");
4396 return FAIL; 4490 return FAIL;
4397 } 4491 }
4398 4492
4399 args[0].v_type = VAR_NUMBER; 4493 args[0].v_type = VAR_NUMBER;
4493 return ret; 4587 return ret;
4494 } 4588 }
4495 4589
4496 /* 4590 /*
4497 * Get the completion pattern, column and length. 4591 * Get the completion pattern, column and length.
4592 * "startcol" - start column number of the completion pattern/text
4593 * "cur_col" - current cursor column
4594 * On return, "line_invalid" is set to TRUE, if the current line may have
4595 * become invalid and needs to be fetched again.
4596 * Returns OK on success.
4498 */ 4597 */
4499 static int 4598 static int
4500 compl_get_info(char_u *line, int startcol, colnr_T curs_col, int *line_invalid) 4599 compl_get_info(char_u *line, int startcol, colnr_T curs_col, int *line_invalid)
4501 { 4600 {
4502 if (ctrl_x_mode == CTRL_X_NORMAL 4601 if (ctrl_x_mode_normal()
4503 || (ctrl_x_mode & CTRL_X_WANT_IDENT 4602 || (ctrl_x_mode & CTRL_X_WANT_IDENT
4504 && !thesaurus_func_complete(ctrl_x_mode))) 4603 && !thesaurus_func_complete(ctrl_x_mode)))
4505 { 4604 {
4506 return get_normal_compl_info(line, startcol, curs_col); 4605 return get_normal_compl_info(line, startcol, curs_col);
4507 } 4606 }
4508 else if (ctrl_x_mode_line_or_eval()) 4607 else if (ctrl_x_mode_line_or_eval())
4509 { 4608 {
4510 return get_wholeline_compl_info(line, curs_col); 4609 return get_wholeline_compl_info(line, curs_col);
4511 } 4610 }
4512 else if (ctrl_x_mode == CTRL_X_FILES) 4611 else if (ctrl_x_mode_files())
4513 { 4612 {
4514 return get_filename_compl_info(line, startcol, curs_col); 4613 return get_filename_compl_info(line, startcol, curs_col);
4515 } 4614 }
4516 else if (ctrl_x_mode == CTRL_X_CMDLINE) 4615 else if (ctrl_x_mode == CTRL_X_CMDLINE)
4517 { 4616 {
4518 return get_cmdline_compl_info(line, curs_col); 4617 return get_cmdline_compl_info(line, curs_col);
4519 } 4618 }
4520 else if (ctrl_x_mode == CTRL_X_FUNCTION || ctrl_x_mode == CTRL_X_OMNI 4619 else if (ctrl_x_mode_function() || ctrl_x_mode_omni()
4521 || thesaurus_func_complete(ctrl_x_mode)) 4620 || thesaurus_func_complete(ctrl_x_mode))
4522 { 4621 {
4523 if (get_userdefined_compl_info(curs_col) == FAIL) 4622 if (get_userdefined_compl_info(curs_col) == FAIL)
4524 return FAIL; 4623 return FAIL;
4525 *line_invalid = TRUE; // 'line' may have become invalid 4624 *line_invalid = TRUE; // "line" may have become invalid
4526 } 4625 }
4527 else if (ctrl_x_mode == CTRL_X_SPELL) 4626 else if (ctrl_x_mode_spell())
4528 { 4627 {
4529 if (get_spell_compl_info(startcol, curs_col) == FAIL) 4628 if (get_spell_compl_info(startcol, curs_col) == FAIL)
4530 return FAIL; 4629 return FAIL;
4531 *line_invalid = TRUE; // 'line' may have become invalid 4630 *line_invalid = TRUE; // "line" may have become invalid
4532 } 4631 }
4533 else 4632 else
4534 { 4633 {
4535 internal_error("ins_complete()"); 4634 internal_error("ins_complete()");
4536 return FAIL; 4635 return FAIL;
4552 static void 4651 static void
4553 ins_compl_continue_search(char_u *line) 4652 ins_compl_continue_search(char_u *line)
4554 { 4653 {
4555 // it is a continued search 4654 // it is a continued search
4556 compl_cont_status &= ~CONT_INTRPT; // remove INTRPT 4655 compl_cont_status &= ~CONT_INTRPT; // remove INTRPT
4557 if (ctrl_x_mode == CTRL_X_NORMAL 4656 if (ctrl_x_mode_normal() || ctrl_x_mode_path_patterns()
4558 || ctrl_x_mode == CTRL_X_PATH_PATTERNS 4657 || ctrl_x_mode_path_defines())
4559 || ctrl_x_mode == CTRL_X_PATH_DEFINES)
4560 { 4658 {
4561 if (compl_startpos.lnum != curwin->w_cursor.lnum) 4659 if (compl_startpos.lnum != curwin->w_cursor.lnum)
4562 { 4660 {
4563 // line (probably) wrapped, set compl_startpos to the 4661 // line (probably) wrapped, set compl_startpos to the
4564 // first non_blank in the line, if it is not a wordchar 4662 // first non_blank in the line, if it is not a wordchar
4637 // completion. 4735 // completion.
4638 ins_compl_continue_search(line); 4736 ins_compl_continue_search(line);
4639 else 4737 else
4640 compl_cont_status &= CONT_LOCAL; 4738 compl_cont_status &= CONT_LOCAL;
4641 4739
4642 if (!(compl_cont_status & CONT_ADDING)) // normal expansion 4740 if (!compl_status_adding()) // normal expansion
4643 { 4741 {
4644 compl_cont_mode = ctrl_x_mode; 4742 compl_cont_mode = ctrl_x_mode;
4645 if (ctrl_x_mode != CTRL_X_NORMAL) 4743 if (ctrl_x_mode_not_default())
4646 // Remove LOCAL if ctrl_x_mode != CTRL_X_NORMAL 4744 // Remove LOCAL if ctrl_x_mode != CTRL_X_NORMAL
4647 compl_cont_status = 0; 4745 compl_cont_status = 0;
4648 compl_cont_status |= CONT_N_ADDS; 4746 compl_cont_status |= CONT_N_ADDS;
4649 compl_startpos = curwin->w_cursor; 4747 compl_startpos = curwin->w_cursor;
4650 startcol = (int)curs_col; 4748 startcol = (int)curs_col;
4652 } 4750 }
4653 4751
4654 // Work out completion pattern and original text -- webb 4752 // Work out completion pattern and original text -- webb
4655 if (compl_get_info(line, startcol, curs_col, &line_invalid) == FAIL) 4753 if (compl_get_info(line, startcol, curs_col, &line_invalid) == FAIL)
4656 { 4754 {
4657 if (ctrl_x_mode == CTRL_X_FUNCTION || ctrl_x_mode == CTRL_X_OMNI 4755 if (ctrl_x_mode_function() || ctrl_x_mode_omni()
4658 || thesaurus_func_complete(ctrl_x_mode)) 4756 || thesaurus_func_complete(ctrl_x_mode))
4659 // restore did_ai, so that adding comment leader works 4757 // restore did_ai, so that adding comment leader works
4660 did_ai = save_did_ai; 4758 did_ai = save_did_ai;
4661 return FAIL; 4759 return FAIL;
4662 } 4760 }
4663 // If "line" was changed while getting completion info get it again. 4761 // If "line" was changed while getting completion info get it again.
4664 if (line_invalid) 4762 if (line_invalid)
4665 line = ml_get(curwin->w_cursor.lnum); 4763 line = ml_get(curwin->w_cursor.lnum);
4666 4764
4667 if (compl_cont_status & CONT_ADDING) 4765 if (compl_status_adding())
4668 { 4766 {
4669 edit_submode_pre = (char_u *)_(" Adding"); 4767 edit_submode_pre = (char_u *)_(" Adding");
4670 if (ctrl_x_mode_line_or_eval()) 4768 if (ctrl_x_mode_line_or_eval())
4671 { 4769 {
4672 // Insert a new line, keep indentation but ignore 'comments'. 4770 // Insert a new line, keep indentation but ignore 'comments'.
4726 */ 4824 */
4727 static void 4825 static void
4728 ins_compl_show_statusmsg(void) 4826 ins_compl_show_statusmsg(void)
4729 { 4827 {
4730 // we found no match if the list has only the "compl_orig_text"-entry 4828 // we found no match if the list has only the "compl_orig_text"-entry
4731 if (compl_first_match == compl_first_match->cp_next) 4829 if (is_first_match(compl_first_match->cp_next))
4732 { 4830 {
4733 edit_submode_extra = (compl_cont_status & CONT_ADDING) 4831 edit_submode_extra = compl_status_adding() && compl_length > 1
4734 && compl_length > 1
4735 ? (char_u *)_(e_hitend) 4832 ? (char_u *)_(e_hitend)
4736 : (char_u *)_(e_pattern_not_found); 4833 : (char_u *)_(e_pattern_not_found);
4737 edit_submode_highl = HLF_E; 4834 edit_submode_highl = HLF_E;
4738 } 4835 }
4739 4836
4740 if (edit_submode_extra == NULL) 4837 if (edit_submode_extra == NULL)
4741 { 4838 {
4742 if (ins_compl_at_original_text(compl_curr_match)) 4839 if (match_at_original_text(compl_curr_match))
4743 { 4840 {
4744 edit_submode_extra = (char_u *)_("Back at original"); 4841 edit_submode_extra = (char_u *)_("Back at original");
4745 edit_submode_highl = HLF_W; 4842 edit_submode_highl = HLF_W;
4746 } 4843 }
4747 else if (compl_cont_status & CONT_S_IPOS) 4844 else if (compl_cont_status & CONT_S_IPOS)
4856 (void)vgetc(); 4953 (void)vgetc();
4857 got_int = FALSE; 4954 got_int = FALSE;
4858 } 4955 }
4859 4956
4860 // we found no match if the list has only the "compl_orig_text"-entry 4957 // we found no match if the list has only the "compl_orig_text"-entry
4861 if (compl_first_match == compl_first_match->cp_next) 4958 if (is_first_match(compl_first_match->cp_next))
4862 { 4959 {
4863 // remove N_ADDS flag, so next ^X<> won't try to go to ADDING mode, 4960 // remove N_ADDS flag, so next ^X<> won't try to go to ADDING mode,
4864 // because we couldn't expand anything at first place, but if we used 4961 // because we couldn't expand anything at first place, but if we used
4865 // ^P, ^N, ^X^I or ^X^D we might want to add-expand a single-char-word 4962 // ^P, ^N, ^X^I or ^X^D we might want to add-expand a single-char-word
4866 // (such as M in M'exico) if not tried already. -- Acevedo 4963 // (such as M in M'exico) if not tried already. -- Acevedo
4867 if (compl_length > 1 4964 if (compl_length > 1
4868 || (compl_cont_status & CONT_ADDING) 4965 || compl_status_adding()
4869 || (ctrl_x_mode != CTRL_X_NORMAL 4966 || (ctrl_x_mode_not_default()
4870 && ctrl_x_mode != CTRL_X_PATH_PATTERNS 4967 && !ctrl_x_mode_path_patterns()
4871 && ctrl_x_mode != CTRL_X_PATH_DEFINES)) 4968 && !ctrl_x_mode_path_defines()))
4872 compl_cont_status &= ~CONT_N_ADDS; 4969 compl_cont_status &= ~CONT_N_ADDS;
4873 } 4970 }
4874 4971
4875 if (compl_curr_match->cp_flags & CP_CONT_S_IPOS) 4972 if (compl_curr_match->cp_flags & CP_CONT_S_IPOS)
4876 compl_cont_status |= CONT_S_IPOS; 4973 compl_cont_status |= CONT_S_IPOS;
4927 switch (*src) 5024 switch (*src)
4928 { 5025 {
4929 case '.': 5026 case '.':
4930 case '*': 5027 case '*':
4931 case '[': 5028 case '[':
4932 if (ctrl_x_mode == CTRL_X_DICTIONARY 5029 if (ctrl_x_mode_dictionary() || ctrl_x_mode_thesaurus())
4933 || ctrl_x_mode == CTRL_X_THESAURUS)
4934 break; 5030 break;
4935 // FALLTHROUGH 5031 // FALLTHROUGH
4936 case '~': 5032 case '~':
4937 if (!magic_isset()) // quote these only if magic is set 5033 if (!magic_isset()) // quote these only if magic is set
4938 break; 5034 break;
4939 // FALLTHROUGH 5035 // FALLTHROUGH
4940 case '\\': 5036 case '\\':
4941 if (ctrl_x_mode == CTRL_X_DICTIONARY 5037 if (ctrl_x_mode_dictionary() || ctrl_x_mode_thesaurus())
4942 || ctrl_x_mode == CTRL_X_THESAURUS)
4943 break; 5038 break;
4944 // FALLTHROUGH 5039 // FALLTHROUGH
4945 case '^': // currently it's not needed. 5040 case '^': // currently it's not needed.
4946 case '$': 5041 case '$':
4947 m++; 5042 m++;