annotate src/insexpand.c @ 32669:448aef880252

normalize line endings
author Christian Brabandt <cb@256bit.org>
date Mon, 26 Jun 2023 09:54:34 +0200
parents 87f59a64efab
children 695b50472e85
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32669
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
7 * See README.txt for an overview of the Vim source code.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
8 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
9
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
10 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
11 * insexpand.c: functions for Insert mode completion
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
12 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
13
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
14 #include "vim.h"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
15
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
16 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
17 * Definitions used for CTRL-X submode.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
18 * Note: If you change CTRL-X submode, you must also maintain ctrl_x_msgs[] and
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
19 * ctrl_x_mode_names[] below.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
20 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
21 # define CTRL_X_WANT_IDENT 0x100
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
22
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
23 # define CTRL_X_NORMAL 0 // CTRL-N CTRL-P completion, default
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
24 # define CTRL_X_NOT_DEFINED_YET 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
25 # define CTRL_X_SCROLL 2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
26 # define CTRL_X_WHOLE_LINE 3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
27 # define CTRL_X_FILES 4
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
28 # define CTRL_X_TAGS (5 + CTRL_X_WANT_IDENT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
29 # define CTRL_X_PATH_PATTERNS (6 + CTRL_X_WANT_IDENT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
30 # define CTRL_X_PATH_DEFINES (7 + CTRL_X_WANT_IDENT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
31 # define CTRL_X_FINISHED 8
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
32 # define CTRL_X_DICTIONARY (9 + CTRL_X_WANT_IDENT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
33 # define CTRL_X_THESAURUS (10 + CTRL_X_WANT_IDENT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
34 # define CTRL_X_CMDLINE 11
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
35 # define CTRL_X_FUNCTION 12
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
36 # define CTRL_X_OMNI 13
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
37 # define CTRL_X_SPELL 14
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
38 # define CTRL_X_LOCAL_MSG 15 // only used in "ctrl_x_msgs"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
39 # define CTRL_X_EVAL 16 // for builtin function complete()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
40 # define CTRL_X_CMDLINE_CTRL_X 17 // CTRL-X typed in CTRL_X_CMDLINE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
41
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
42 # define CTRL_X_MSG(i) ctrl_x_msgs[(i) & ~CTRL_X_WANT_IDENT]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
43
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
44 // Message for CTRL-X mode, index is ctrl_x_mode.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
45 static char *ctrl_x_msgs[] =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
46 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
47 N_(" Keyword completion (^N^P)"), // CTRL_X_NORMAL, ^P/^N compl.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
48 N_(" ^X mode (^]^D^E^F^I^K^L^N^O^Ps^U^V^Y)"),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
49 NULL, // CTRL_X_SCROLL: depends on state
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
50 N_(" Whole line completion (^L^N^P)"),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
51 N_(" File name completion (^F^N^P)"),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
52 N_(" Tag completion (^]^N^P)"),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
53 N_(" Path pattern completion (^N^P)"),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
54 N_(" Definition completion (^D^N^P)"),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
55 NULL, // CTRL_X_FINISHED
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
56 N_(" Dictionary completion (^K^N^P)"),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
57 N_(" Thesaurus completion (^T^N^P)"),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
58 N_(" Command-line completion (^V^N^P)"),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
59 N_(" User defined completion (^U^N^P)"),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
60 N_(" Omni completion (^O^N^P)"),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
61 N_(" Spelling suggestion (s^N^P)"),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
62 N_(" Keyword Local completion (^N^P)"),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
63 NULL, // CTRL_X_EVAL doesn't use msg.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
64 N_(" Command-line completion (^V^N^P)"),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
65 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
66
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
67 #if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
68 static char *ctrl_x_mode_names[] = {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
69 "keyword",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
70 "ctrl_x",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
71 "scroll",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
72 "whole_line",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
73 "files",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
74 "tags",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
75 "path_patterns",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
76 "path_defines",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
77 "unknown", // CTRL_X_FINISHED
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
78 "dictionary",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
79 "thesaurus",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
80 "cmdline",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
81 "function",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
82 "omni",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
83 "spell",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
84 NULL, // CTRL_X_LOCAL_MSG only used in "ctrl_x_msgs"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
85 "eval",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
86 "cmdline",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
87 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
88 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
89
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
90 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
91 * Array indexes used for cp_text[].
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
92 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
93 #define CPT_ABBR 0 // "abbr"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
94 #define CPT_MENU 1 // "menu"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
95 #define CPT_KIND 2 // "kind"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
96 #define CPT_INFO 3 // "info"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
97 #define CPT_COUNT 4 // Number of entries
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
98
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
99 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
100 * Structure used to store one match for insert completion.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
101 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
102 typedef struct compl_S compl_T;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
103 struct compl_S
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
104 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
105 compl_T *cp_next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
106 compl_T *cp_prev;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
107 char_u *cp_str; // matched text
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
108 char_u *(cp_text[CPT_COUNT]); // text for the menu
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
109 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
110 typval_T cp_user_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
111 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
112 char_u *cp_fname; // file containing the match, allocated when
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
113 // cp_flags has CP_FREE_FNAME
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
114 int cp_flags; // CP_ values
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
115 int cp_number; // sequence number
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
116 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
117
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
118 // values for cp_flags
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
119 # define CP_ORIGINAL_TEXT 1 // the original text when the expansion begun
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
120 # define CP_FREE_FNAME 2 // cp_fname is allocated
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
121 # define CP_CONT_S_IPOS 4 // use CONT_S_IPOS for compl_cont_status
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
122 # define CP_EQUAL 8 // ins_compl_equal() always returns TRUE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
123 # define CP_ICASE 16 // ins_compl_equal() ignores case
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
124 # define CP_FAST 32 // use fast_breakcheck instead of ui_breakcheck
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
125
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
126 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
127 * All the current matches are stored in a list.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
128 * "compl_first_match" points to the start of the list.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
129 * "compl_curr_match" points to the currently selected entry.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
130 * "compl_shown_match" is different from compl_curr_match during
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
131 * ins_compl_get_exp().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
132 * "compl_old_match" points to previous "compl_curr_match".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
133 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
134 static compl_T *compl_first_match = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
135 static compl_T *compl_curr_match = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
136 static compl_T *compl_shown_match = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
137 static compl_T *compl_old_match = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
138
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
139 // After using a cursor key <Enter> selects a match in the popup menu,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
140 // otherwise it inserts a line break.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
141 static int compl_enter_selects = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
142
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
143 // When "compl_leader" is not NULL only matches that start with this string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
144 // are used.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
145 static char_u *compl_leader = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
146
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
147 static int compl_get_longest = FALSE; // put longest common string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
148 // in compl_leader
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
149
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
150 static int compl_no_insert = FALSE; // FALSE: select & insert
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
151 // TRUE: noinsert
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
152 static int compl_no_select = FALSE; // FALSE: select & insert
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
153 // TRUE: noselect
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
154 static int compl_longest = FALSE; // FALSE: insert full match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
155 // TRUE: insert longest prefix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
156
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
157 // Selected one of the matches. When FALSE the match was edited or using the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
158 // longest common string.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
159 static int compl_used_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
160
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
161 // didn't finish finding completions.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
162 static int compl_was_interrupted = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
163
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
164 // Set when character typed while looking for matches and it means we should
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
165 // stop looking for matches.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
166 static int compl_interrupted = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
167
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
168 static int compl_restarting = FALSE; // don't insert match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
169
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
170 // When the first completion is done "compl_started" is set. When it's
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
171 // FALSE the word to be completed must be located.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
172 static int compl_started = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
173
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
174 // Which Ctrl-X mode are we in?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
175 static int ctrl_x_mode = CTRL_X_NORMAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
176
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
177 static int compl_matches = 0; // number of completion matches
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
178 static char_u *compl_pattern = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
179 static int compl_direction = FORWARD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
180 static int compl_shows_dir = FORWARD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
181 static int compl_pending = 0; // > 1 for postponed CTRL-N
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
182 static pos_T compl_startpos;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
183 // Length in bytes of the text being completed (this is deleted to be replaced
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
184 // by the match.)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
185 static int compl_length = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
186 static colnr_T compl_col = 0; // column where the text starts
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
187 // that is being completed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
188 static char_u *compl_orig_text = NULL; // text as it was before
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
189 // completion started
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
190 static int compl_cont_mode = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
191 static expand_T compl_xp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
192
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
193 // List of flags for method of completion.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
194 static int compl_cont_status = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
195 # define CONT_ADDING 1 // "normal" or "adding" expansion
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
196 # define CONT_INTRPT (2 + 4) // a ^X interrupted the current expansion
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
197 // it's set only iff N_ADDS is set
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
198 # define CONT_N_ADDS 4 // next ^X<> will add-new or expand-current
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
199 # define CONT_S_IPOS 8 // next ^X<> will set initial_pos?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
200 // if so, word-wise-expansion will set SOL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
201 # define CONT_SOL 16 // pattern includes start of line, just for
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
202 // word-wise expansion, not set for ^X^L
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
203 # define CONT_LOCAL 32 // for ctrl_x_mode 0, ^X^P/^X^N do a local
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
204 // expansion, (eg use complete=.)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
205
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
206 static int compl_opt_refresh_always = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
207 static int compl_opt_suppress_empty = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
208
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
209 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);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
210 static void ins_compl_longest_match(compl_T *match);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
211 static void ins_compl_del_pum(void);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
212 static void ins_compl_files(int count, char_u **files, int thesaurus, int flags, regmatch_T *regmatch, char_u *buf, int *dir);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
213 static char_u *find_line_end(char_u *ptr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
214 static void ins_compl_free(void);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
215 static int ins_compl_need_restart(void);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
216 static void ins_compl_new_leader(void);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
217 static int get_compl_len(void);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
218 static void ins_compl_restart(void);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
219 static void ins_compl_set_original_text(char_u *str);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
220 static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
221 # if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
222 static void ins_compl_add_list(list_T *list);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
223 static void ins_compl_add_dict(dict_T *dict);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
224 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
225 static int ins_compl_key2dir(int c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
226 static int ins_compl_pum_key(int c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
227 static int ins_compl_key2count(int c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
228 static void show_pum(int prev_w_wrow, int prev_w_leftcol);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
229 static unsigned quote_meta(char_u *dest, char_u *str, int len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
230
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
231 #ifdef FEAT_SPELL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
232 static void spell_back_to_badword(void);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
233 static int spell_bad_len = 0; // length of located bad word
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
234 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
235
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
236 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
237 * CTRL-X pressed in Insert mode.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
238 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
239 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
240 ins_ctrl_x(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
241 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
242 if (!ctrl_x_mode_cmdline())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
243 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
244 // if the next ^X<> won't ADD nothing, then reset compl_cont_status
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
245 if (compl_cont_status & CONT_N_ADDS)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
246 compl_cont_status |= CONT_INTRPT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
247 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
248 compl_cont_status = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
249 // We're not sure which CTRL-X mode it will be yet
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
250 ctrl_x_mode = CTRL_X_NOT_DEFINED_YET;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
251 edit_submode = (char_u *)_(CTRL_X_MSG(ctrl_x_mode));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
252 edit_submode_pre = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
253 showmode();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
254 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
255 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
256 // CTRL-X in CTRL-X CTRL-V mode behaves differently to make CTRL-X
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
257 // CTRL-V look like CTRL-N
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
258 ctrl_x_mode = CTRL_X_CMDLINE_CTRL_X;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
259
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
260 may_trigger_modechanged();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
261 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
262
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
263 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
264 * Functions to check the current CTRL-X mode.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
265 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
266 int ctrl_x_mode_none(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
267 { return ctrl_x_mode == 0; }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
268 int ctrl_x_mode_normal(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
269 { return ctrl_x_mode == CTRL_X_NORMAL; }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
270 int ctrl_x_mode_scroll(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
271 { return ctrl_x_mode == CTRL_X_SCROLL; }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
272 int ctrl_x_mode_whole_line(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
273 { return ctrl_x_mode == CTRL_X_WHOLE_LINE; }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
274 int ctrl_x_mode_files(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
275 { return ctrl_x_mode == CTRL_X_FILES; }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
276 int ctrl_x_mode_tags(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
277 { return ctrl_x_mode == CTRL_X_TAGS; }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
278 int ctrl_x_mode_path_patterns(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
279 { return ctrl_x_mode == CTRL_X_PATH_PATTERNS; }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
280 int ctrl_x_mode_path_defines(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
281 { return ctrl_x_mode == CTRL_X_PATH_DEFINES; }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
282 int ctrl_x_mode_dictionary(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
283 { return ctrl_x_mode == CTRL_X_DICTIONARY; }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
284 int ctrl_x_mode_thesaurus(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
285 { return ctrl_x_mode == CTRL_X_THESAURUS; }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
286 int ctrl_x_mode_cmdline(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
287 { return ctrl_x_mode == CTRL_X_CMDLINE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
288 || ctrl_x_mode == CTRL_X_CMDLINE_CTRL_X; }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
289 int ctrl_x_mode_function(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
290 { return ctrl_x_mode == CTRL_X_FUNCTION; }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
291 int ctrl_x_mode_omni(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
292 { return ctrl_x_mode == CTRL_X_OMNI; }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
293 int ctrl_x_mode_spell(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
294 { return ctrl_x_mode == CTRL_X_SPELL; }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
295 static int ctrl_x_mode_eval(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
296 { return ctrl_x_mode == CTRL_X_EVAL; }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
297 int ctrl_x_mode_line_or_eval(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
298 { return ctrl_x_mode == CTRL_X_WHOLE_LINE || ctrl_x_mode == CTRL_X_EVAL; }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
299
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
300 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
301 * Whether other than default completion has been selected.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
302 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
303 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
304 ctrl_x_mode_not_default(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
305 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
306 return ctrl_x_mode != CTRL_X_NORMAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
307 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
308
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
309 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
310 * Whether CTRL-X was typed without a following character,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
311 * not including when in CTRL-X CTRL-V mode.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
312 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
313 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
314 ctrl_x_mode_not_defined_yet(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
315 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
316 return ctrl_x_mode == CTRL_X_NOT_DEFINED_YET;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
317 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
318
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
319 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
320 * Return TRUE if currently in "normal" or "adding" insert completion matches
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
321 * state
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
322 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
323 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
324 compl_status_adding(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
325 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
326 return compl_cont_status & CONT_ADDING;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
327 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
328
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
329 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
330 * Return TRUE if the completion pattern includes start of line, just for
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
331 * word-wise expansion.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
332 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
333 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
334 compl_status_sol(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
335 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
336 return compl_cont_status & CONT_SOL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
337 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
338
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
339 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
340 * Return TRUE if ^X^P/^X^N will do a local completion (i.e. use complete=.)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
341 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
342 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
343 compl_status_local(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
344 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
345 return compl_cont_status & CONT_LOCAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
346 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
347
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
348 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
349 * Clear the completion status flags
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
350 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
351 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
352 compl_status_clear(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
353 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
354 compl_cont_status = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
355 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
356
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
357 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
358 * Return TRUE if completion is using the forward direction matches
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
359 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
360 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
361 compl_dir_forward(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
362 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
363 return compl_direction == FORWARD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
364 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
365
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
366 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
367 * Return TRUE if currently showing forward completion matches
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
368 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
369 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
370 compl_shows_dir_forward(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
371 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
372 return compl_shows_dir == FORWARD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
373 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
374
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
375 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
376 * Return TRUE if currently showing backward completion matches
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
377 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
378 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
379 compl_shows_dir_backward(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
380 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
381 return compl_shows_dir == BACKWARD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
382 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
383
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
384 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
385 * Return TRUE if the 'dictionary' or 'thesaurus' option can be used.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
386 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
387 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
388 has_compl_option(int dict_opt)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
389 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
390 if (dict_opt ? (*curbuf->b_p_dict == NUL && *p_dict == NUL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
391 #ifdef FEAT_SPELL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
392 && !curwin->w_p_spell
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
393 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
394 )
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
395 : (*curbuf->b_p_tsr == NUL && *p_tsr == NUL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
396 #ifdef FEAT_COMPL_FUNC
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
397 && *curbuf->b_p_tsrfu == NUL && *p_tsrfu == NUL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
398 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
399 ))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
400 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
401 ctrl_x_mode = CTRL_X_NORMAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
402 edit_submode = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
403 msg_attr(dict_opt ? _("'dictionary' option is empty")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
404 : _("'thesaurus' option is empty"),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
405 HL_ATTR(HLF_E));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
406 if (emsg_silent == 0 && !in_assert_fails)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
407 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
408 vim_beep(BO_COMPL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
409 setcursor();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
410 out_flush();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
411 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
412 if (!get_vim_var_nr(VV_TESTING))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
413 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
414 ui_delay(2004L, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
415 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
416 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
417 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
418 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
419 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
420
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
421 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
422 * Is the character "c" a valid key to go to or keep us in CTRL-X mode?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
423 * This depends on the current mode.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
424 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
425 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
426 vim_is_ctrl_x_key(int c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
427 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
428 // Always allow ^R - let its results then be checked
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
429 if (c == Ctrl_R)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
430 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
431
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
432 // Accept <PageUp> and <PageDown> if the popup menu is visible.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
433 if (ins_compl_pum_key(c))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
434 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
435
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
436 switch (ctrl_x_mode)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
437 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
438 case 0: // Not in any CTRL-X mode
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
439 return (c == Ctrl_N || c == Ctrl_P || c == Ctrl_X);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
440 case CTRL_X_NOT_DEFINED_YET:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
441 case CTRL_X_CMDLINE_CTRL_X:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
442 return ( c == Ctrl_X || c == Ctrl_Y || c == Ctrl_E
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
443 || c == Ctrl_L || c == Ctrl_F || c == Ctrl_RSB
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
444 || c == Ctrl_I || c == Ctrl_D || c == Ctrl_P
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
445 || c == Ctrl_N || c == Ctrl_T || c == Ctrl_V
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
446 || c == Ctrl_Q || c == Ctrl_U || c == Ctrl_O
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
447 || c == Ctrl_S || c == Ctrl_K || c == 's'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
448 || c == Ctrl_Z);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
449 case CTRL_X_SCROLL:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
450 return (c == Ctrl_Y || c == Ctrl_E);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
451 case CTRL_X_WHOLE_LINE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
452 return (c == Ctrl_L || c == Ctrl_P || c == Ctrl_N);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
453 case CTRL_X_FILES:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
454 return (c == Ctrl_F || c == Ctrl_P || c == Ctrl_N);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
455 case CTRL_X_DICTIONARY:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
456 return (c == Ctrl_K || c == Ctrl_P || c == Ctrl_N);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
457 case CTRL_X_THESAURUS:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
458 return (c == Ctrl_T || c == Ctrl_P || c == Ctrl_N);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
459 case CTRL_X_TAGS:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
460 return (c == Ctrl_RSB || c == Ctrl_P || c == Ctrl_N);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
461 #ifdef FEAT_FIND_ID
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
462 case CTRL_X_PATH_PATTERNS:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
463 return (c == Ctrl_P || c == Ctrl_N);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
464 case CTRL_X_PATH_DEFINES:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
465 return (c == Ctrl_D || c == Ctrl_P || c == Ctrl_N);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
466 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
467 case CTRL_X_CMDLINE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
468 return (c == Ctrl_V || c == Ctrl_Q || c == Ctrl_P || c == Ctrl_N
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
469 || c == Ctrl_X);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
470 #ifdef FEAT_COMPL_FUNC
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
471 case CTRL_X_FUNCTION:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
472 return (c == Ctrl_U || c == Ctrl_P || c == Ctrl_N);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
473 case CTRL_X_OMNI:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
474 return (c == Ctrl_O || c == Ctrl_P || c == Ctrl_N);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
475 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
476 case CTRL_X_SPELL:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
477 return (c == Ctrl_S || c == Ctrl_P || c == Ctrl_N);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
478 case CTRL_X_EVAL:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
479 return (c == Ctrl_P || c == Ctrl_N);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
480 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
481 internal_error("vim_is_ctrl_x_key()");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
482 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
483 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
484
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
485 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
486 * Return TRUE if "match" is the original text when the completion began.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
487 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
488 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
489 match_at_original_text(compl_T *match)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
490 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
491 return match->cp_flags & CP_ORIGINAL_TEXT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
492 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
493
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
494 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
495 * Returns TRUE if "match" is the first match in the completion list.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
496 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
497 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
498 is_first_match(compl_T *match)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
499 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
500 return match == compl_first_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
501 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
502
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
503 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
504 * Return TRUE when character "c" is part of the item currently being
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
505 * completed. Used to decide whether to abandon complete mode when the menu
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
506 * is visible.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
507 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
508 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
509 ins_compl_accept_char(int c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
510 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
511 if (ctrl_x_mode & CTRL_X_WANT_IDENT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
512 // When expanding an identifier only accept identifier chars.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
513 return vim_isIDc(c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
514
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
515 switch (ctrl_x_mode)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
516 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
517 case CTRL_X_FILES:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
518 // When expanding file name only accept file name chars. But not
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
519 // path separators, so that "proto/<Tab>" expands files in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
520 // "proto", not "proto/" as a whole
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
521 return vim_isfilec(c) && !vim_ispathsep(c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
522
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
523 case CTRL_X_CMDLINE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
524 case CTRL_X_CMDLINE_CTRL_X:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
525 case CTRL_X_OMNI:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
526 // Command line and Omni completion can work with just about any
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
527 // printable character, but do stop at white space.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
528 return vim_isprintc(c) && !VIM_ISWHITE(c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
529
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
530 case CTRL_X_WHOLE_LINE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
531 // For while line completion a space can be part of the line.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
532 return vim_isprintc(c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
533 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
534 return vim_iswordc(c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
535 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
536
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
537 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
538 * Get the completed text by inferring the case of the originally typed text.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
539 * If the result is in allocated memory "tofree" is set to it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
540 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
541 static char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
542 ins_compl_infercase_gettext(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
543 char_u *str,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
544 int char_len,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
545 int compl_char_len,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
546 int min_len,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
547 char_u **tofree)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
548 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
549 int *wca; // Wide character array.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
550 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
551 int i, c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
552 int has_lower = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
553 int was_letter = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
554 garray_T gap;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
555
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
556 IObuff[0] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
557
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
558 // Allocate wide character array for the completion and fill it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
559 wca = ALLOC_MULT(int, char_len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
560 if (wca == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
561 return IObuff;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
562
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
563 p = str;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
564 for (i = 0; i < char_len; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
565 if (has_mbyte)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
566 wca[i] = mb_ptr2char_adv(&p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
567 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
568 wca[i] = *(p++);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
569
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
570 // Rule 1: Were any chars converted to lower?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
571 p = compl_orig_text;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
572 for (i = 0; i < min_len; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
573 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
574 if (has_mbyte)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
575 c = mb_ptr2char_adv(&p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
576 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
577 c = *(p++);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
578 if (MB_ISLOWER(c))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
579 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
580 has_lower = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
581 if (MB_ISUPPER(wca[i]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
582 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
583 // Rule 1 is satisfied.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
584 for (i = compl_char_len; i < char_len; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
585 wca[i] = MB_TOLOWER(wca[i]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
586 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
587 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
588 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
589 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
590
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
591 // Rule 2: No lower case, 2nd consecutive letter converted to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
592 // upper case.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
593 if (!has_lower)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
594 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
595 p = compl_orig_text;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
596 for (i = 0; i < min_len; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
597 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
598 if (has_mbyte)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
599 c = mb_ptr2char_adv(&p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
600 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
601 c = *(p++);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
602 if (was_letter && MB_ISUPPER(c) && MB_ISLOWER(wca[i]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
603 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
604 // Rule 2 is satisfied.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
605 for (i = compl_char_len; i < char_len; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
606 wca[i] = MB_TOUPPER(wca[i]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
607 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
608 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
609 was_letter = MB_ISLOWER(c) || MB_ISUPPER(c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
610 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
611 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
612
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
613 // Copy the original case of the part we typed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
614 p = compl_orig_text;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
615 for (i = 0; i < min_len; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
616 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
617 if (has_mbyte)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
618 c = mb_ptr2char_adv(&p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
619 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
620 c = *(p++);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
621 if (MB_ISLOWER(c))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
622 wca[i] = MB_TOLOWER(wca[i]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
623 else if (MB_ISUPPER(c))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
624 wca[i] = MB_TOUPPER(wca[i]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
625 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
626
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
627 // Generate encoding specific output from wide character array.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
628 p = IObuff;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
629 i = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
630 ga_init2(&gap, 1, 500);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
631 while (i < char_len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
632 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
633 if (gap.ga_data != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
634 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
635 if (ga_grow(&gap, 10) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
636 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
637 ga_clear(&gap);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
638 return (char_u *)"[failed]";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
639 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
640 p = (char_u *)gap.ga_data + gap.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
641 if (has_mbyte)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
642 gap.ga_len += (*mb_char2bytes)(wca[i++], p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
643 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
644 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
645 *p = wca[i++];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
646 ++gap.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
647 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
648 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
649 else if ((p - IObuff) + 6 >= IOSIZE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
650 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
651 // Multi-byte characters can occupy up to five bytes more than
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
652 // ASCII characters, and we also need one byte for NUL, so when
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
653 // getting to six bytes from the edge of IObuff switch to using a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
654 // growarray. Add the character in the next round.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
655 if (ga_grow(&gap, IOSIZE) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
656 return (char_u *)"[failed]";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
657 *p = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
658 STRCPY(gap.ga_data, IObuff);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
659 gap.ga_len = (int)STRLEN(IObuff);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
660 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
661 else if (has_mbyte)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
662 p += (*mb_char2bytes)(wca[i++], p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
663 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
664 *(p++) = wca[i++];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
665 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
666 vim_free(wca);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
667
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
668 if (gap.ga_data != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
669 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
670 *tofree = gap.ga_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
671 return gap.ga_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
672 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
673
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
674 *p = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
675 return IObuff;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
676 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
677
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
678 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
679 * This is like ins_compl_add(), but if 'ic' and 'inf' are set, then the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
680 * case of the originally typed text is used, and the case of the completed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
681 * text is inferred, ie this tries to work out what case you probably wanted
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
682 * the rest of the word to be in -- webb
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
683 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
684 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
685 ins_compl_add_infercase(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
686 char_u *str_arg,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
687 int len,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
688 int icase,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
689 char_u *fname,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
690 int dir,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
691 int cont_s_ipos) // next ^X<> will set initial_pos
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
692 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
693 char_u *str = str_arg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
694 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
695 int char_len; // count multi-byte characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
696 int compl_char_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
697 int min_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
698 int flags = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
699 int res;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
700 char_u *tofree = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
701
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
702 if (p_ic && curbuf->b_p_inf && len > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
703 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
704 // Infer case of completed part.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
705
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
706 // Find actual length of completion.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
707 if (has_mbyte)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
708 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
709 p = str;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
710 char_len = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
711 while (*p != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
712 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
713 MB_PTR_ADV(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
714 ++char_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
715 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
716 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
717 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
718 char_len = len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
719
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
720 // Find actual length of original text.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
721 if (has_mbyte)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
722 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
723 p = compl_orig_text;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
724 compl_char_len = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
725 while (*p != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
726 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
727 MB_PTR_ADV(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
728 ++compl_char_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
729 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
730 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
731 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
732 compl_char_len = compl_length;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
733
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
734 // "char_len" may be smaller than "compl_char_len" when using
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
735 // thesaurus, only use the minimum when comparing.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
736 min_len = char_len < compl_char_len ? char_len : compl_char_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
737
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
738 str = ins_compl_infercase_gettext(str, char_len,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
739 compl_char_len, min_len, &tofree);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
740 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
741 if (cont_s_ipos)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
742 flags |= CP_CONT_S_IPOS;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
743 if (icase)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
744 flags |= CP_ICASE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
745
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
746 res = ins_compl_add(str, len, fname, NULL, NULL, dir, flags, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
747 vim_free(tofree);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
748 return res;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
749 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
750
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
751 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
752 * Add a match to the list of matches. The arguments are:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
753 * str - text of the match to add
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
754 * len - length of "str". If -1, then the length of "str" is
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
755 * computed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
756 * fname - file name to associate with this match.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
757 * cptext - list of strings to use with this match (for abbr, menu, info
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
758 * and kind)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
759 * user_data - user supplied data (any vim type) for this match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
760 * cdir - match direction. If 0, use "compl_direction".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
761 * flags_arg - match flags (cp_flags)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
762 * adup - accept this match even if it is already present.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
763 * If "cdir" is FORWARD, then the match is added after the current match.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
764 * Otherwise, it is added before the current match.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
765 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
766 * If the given string is already in the list of completions, then return
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
767 * NOTDONE, otherwise add it to the list and return OK. If there is an error,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
768 * maybe because alloc() returns NULL, then FAIL is returned.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
769 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
770 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
771 ins_compl_add(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
772 char_u *str,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
773 int len,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
774 char_u *fname,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
775 char_u **cptext, // extra text for popup menu or NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
776 typval_T *user_data UNUSED, // "user_data" entry or NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
777 int cdir,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
778 int flags_arg,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
779 int adup) // accept duplicate match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
780 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
781 compl_T *match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
782 int dir = (cdir == 0 ? compl_direction : cdir);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
783 int flags = flags_arg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
784
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
785 if (flags & CP_FAST)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
786 fast_breakcheck();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
787 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
788 ui_breakcheck();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
789 if (got_int)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
790 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
791 if (len < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
792 len = (int)STRLEN(str);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
793
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
794 // If the same match is already present, don't add it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
795 if (compl_first_match != NULL && !adup)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
796 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
797 match = compl_first_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
798 do
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
799 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
800 if (!match_at_original_text(match)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
801 && STRNCMP(match->cp_str, str, len) == 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
802 && ((int)STRLEN(match->cp_str) <= len
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
803 || match->cp_str[len] == NUL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
804 return NOTDONE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
805 match = match->cp_next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
806 } while (match != NULL && !is_first_match(match));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
807 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
808
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
809 // Remove any popup menu before changing the list of matches.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
810 ins_compl_del_pum();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
811
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
812 // Allocate a new match structure.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
813 // Copy the values to the new match structure.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
814 match = ALLOC_CLEAR_ONE(compl_T);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
815 if (match == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
816 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
817 match->cp_number = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
818 if (flags & CP_ORIGINAL_TEXT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
819 match->cp_number = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
820 if ((match->cp_str = vim_strnsave(str, len)) == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
821 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
822 vim_free(match);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
823 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
824 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
825
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
826 // match-fname is:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
827 // - compl_curr_match->cp_fname if it is a string equal to fname.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
828 // - a copy of fname, CP_FREE_FNAME is set to free later THE allocated mem.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
829 // - NULL otherwise. --Acevedo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
830 if (fname != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
831 && compl_curr_match != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
832 && compl_curr_match->cp_fname != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
833 && STRCMP(fname, compl_curr_match->cp_fname) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
834 match->cp_fname = compl_curr_match->cp_fname;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
835 else if (fname != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
836 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
837 match->cp_fname = vim_strsave(fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
838 flags |= CP_FREE_FNAME;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
839 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
840 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
841 match->cp_fname = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
842 match->cp_flags = flags;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
843
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
844 if (cptext != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
845 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
846 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
847
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
848 for (i = 0; i < CPT_COUNT; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
849 if (cptext[i] != NULL && *cptext[i] != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
850 match->cp_text[i] = vim_strsave(cptext[i]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
851 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
852 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
853 if (user_data != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
854 match->cp_user_data = *user_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
855 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
856
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
857 // Link the new match structure after (FORWARD) or before (BACKWARD) the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
858 // current match in the list of matches .
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
859 if (compl_first_match == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
860 match->cp_next = match->cp_prev = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
861 else if (dir == FORWARD)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
862 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
863 match->cp_next = compl_curr_match->cp_next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
864 match->cp_prev = compl_curr_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
865 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
866 else // BACKWARD
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
867 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
868 match->cp_next = compl_curr_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
869 match->cp_prev = compl_curr_match->cp_prev;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
870 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
871 if (match->cp_next)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
872 match->cp_next->cp_prev = match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
873 if (match->cp_prev)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
874 match->cp_prev->cp_next = match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
875 else // if there's nothing before, it is the first match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
876 compl_first_match = match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
877 compl_curr_match = match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
878
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
879 // Find the longest common string if still doing that.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
880 if (compl_get_longest && (flags & CP_ORIGINAL_TEXT) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
881 ins_compl_longest_match(match);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
882
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
883 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
884 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
885
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
886 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
887 * Return TRUE if "str[len]" matches with match->cp_str, considering
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
888 * match->cp_flags.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
889 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
890 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
891 ins_compl_equal(compl_T *match, char_u *str, int len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
892 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
893 if (match->cp_flags & CP_EQUAL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
894 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
895 if (match->cp_flags & CP_ICASE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
896 return STRNICMP(match->cp_str, str, (size_t)len) == 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
897 return STRNCMP(match->cp_str, str, (size_t)len) == 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
898 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
899
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
900 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
901 * Reduce the longest common string for match "match".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
902 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
903 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
904 ins_compl_longest_match(compl_T *match)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
905 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
906 char_u *p, *s;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
907 int c1, c2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
908 int had_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
909
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
910 if (compl_leader == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
911 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
912 // First match, use it as a whole.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
913 compl_leader = vim_strsave(match->cp_str);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
914 if (compl_leader == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
915 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
916
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
917 had_match = (curwin->w_cursor.col > compl_col);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
918 ins_compl_delete();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
919 ins_bytes(compl_leader + get_compl_len());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
920 ins_redraw(FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
921
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
922 // When the match isn't there (to avoid matching itself) remove it
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
923 // again after redrawing.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
924 if (!had_match)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
925 ins_compl_delete();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
926 compl_used_match = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
927
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
928 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
929 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
930
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
931 // Reduce the text if this match differs from compl_leader.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
932 p = compl_leader;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
933 s = match->cp_str;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
934 while (*p != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
935 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
936 if (has_mbyte)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
937 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
938 c1 = mb_ptr2char(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
939 c2 = mb_ptr2char(s);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
940 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
941 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
942 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
943 c1 = *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
944 c2 = *s;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
945 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
946 if ((match->cp_flags & CP_ICASE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
947 ? (MB_TOLOWER(c1) != MB_TOLOWER(c2)) : (c1 != c2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
948 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
949 if (has_mbyte)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
950 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
951 MB_PTR_ADV(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
952 MB_PTR_ADV(s);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
953 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
954 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
955 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
956 ++p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
957 ++s;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
958 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
959 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
960
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
961 if (*p != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
962 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
963 // Leader was shortened, need to change the inserted text.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
964 *p = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
965 had_match = (curwin->w_cursor.col > compl_col);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
966 ins_compl_delete();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
967 ins_bytes(compl_leader + get_compl_len());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
968 ins_redraw(FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
969
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
970 // When the match isn't there (to avoid matching itself) remove it
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
971 // again after redrawing.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
972 if (!had_match)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
973 ins_compl_delete();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
974 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
975
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
976 compl_used_match = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
977 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
978
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
979 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
980 * Add an array of matches to the list of matches.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
981 * Frees matches[].
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
982 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
983 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
984 ins_compl_add_matches(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
985 int num_matches,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
986 char_u **matches,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
987 int icase)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
988 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
989 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
990 int add_r = OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
991 int dir = compl_direction;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
992
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
993 for (i = 0; i < num_matches && add_r != FAIL; i++)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
994 if ((add_r = ins_compl_add(matches[i], -1, NULL, NULL, NULL, dir,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
995 CP_FAST | (icase ? CP_ICASE : 0), FALSE)) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
996 // if dir was BACKWARD then honor it just once
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
997 dir = FORWARD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
998 FreeWild(num_matches, matches);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
999 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1001 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1002 * Make the completion list cyclic.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1003 * Return the number of matches (excluding the original).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1004 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1005 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1006 ins_compl_make_cyclic(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1007 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1008 compl_T *match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1009 int count = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1010
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1011 if (compl_first_match == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1012 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1013
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1014 // Find the end of the list.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1015 match = compl_first_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1016 // there's always an entry for the compl_orig_text, it doesn't count.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1017 while (match->cp_next != NULL && !is_first_match(match->cp_next))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1018 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1019 match = match->cp_next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1020 ++count;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1021 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1022 match->cp_next = compl_first_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1023 compl_first_match->cp_prev = match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1024
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1025 return count;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1026 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1027
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1028 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1029 * Return whether there currently is a shown match.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1030 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1031 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1032 ins_compl_has_shown_match(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1033 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1034 return compl_shown_match == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1035 || compl_shown_match != compl_shown_match->cp_next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1036 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1037
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1038 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1039 * Return whether the shown match is long enough.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1040 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1041 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1042 ins_compl_long_shown_match(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1043 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1044 return (int)STRLEN(compl_shown_match->cp_str)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1045 > curwin->w_cursor.col - compl_col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1046 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1047
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1048 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1049 * Set variables that store noselect and noinsert behavior from the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1050 * 'completeopt' value.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1051 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1052 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1053 completeopt_was_set(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1054 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1055 compl_no_insert = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1056 compl_no_select = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1057 compl_longest = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1058 if (strstr((char *)p_cot, "noselect") != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1059 compl_no_select = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1060 if (strstr((char *)p_cot, "noinsert") != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1061 compl_no_insert = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1062 if (strstr((char *)p_cot, "longest") != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1063 compl_longest = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1064 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1065
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1066
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1067 // "compl_match_array" points the currently displayed list of entries in the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1068 // popup menu. It is NULL when there is no popup menu.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1069 static pumitem_T *compl_match_array = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1070 static int compl_match_arraysize;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1071
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1072 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1073 * Update the screen and when there is any scrolling remove the popup menu.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1074 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1075 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1076 ins_compl_upd_pum(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1077 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1078 int h;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1079
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1080 if (compl_match_array == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1081 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1082
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1083 h = curwin->w_cline_height;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1084 // Update the screen later, before drawing the popup menu over it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1085 pum_call_update_screen();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1086 if (h != curwin->w_cline_height)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1087 ins_compl_del_pum();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1088 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1089
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1090 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1091 * Remove any popup menu.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1092 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1093 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1094 ins_compl_del_pum(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1095 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1096 if (compl_match_array == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1097 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1098
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1099 pum_undisplay();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1100 VIM_CLEAR(compl_match_array);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1101 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1102
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1103 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1104 * Return TRUE if the popup menu should be displayed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1105 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1106 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1107 pum_wanted(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1108 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1109 // 'completeopt' must contain "menu" or "menuone"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1110 if (vim_strchr(p_cot, 'm') == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1111 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1112
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1113 // The display looks bad on a B&W display.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1114 if (t_colors < 8
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1115 #ifdef FEAT_GUI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1116 && !gui.in_use
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1117 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1118 )
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1119 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1120 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1121 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1122
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1123 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1124 * Return TRUE if there are two or more matches to be shown in the popup menu.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1125 * One if 'completopt' contains "menuone".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1126 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1127 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1128 pum_enough_matches(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1129 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1130 compl_T *compl;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1131 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1132
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1133 // Don't display the popup menu if there are no matches or there is only
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1134 // one (ignoring the original text).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1135 compl = compl_first_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1136 i = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1137 do
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1138 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1139 if (compl == NULL || (!match_at_original_text(compl) && ++i == 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1140 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1141 compl = compl->cp_next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1142 } while (!is_first_match(compl));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1143
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1144 if (strstr((char *)p_cot, "menuone") != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1145 return (i >= 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1146 return (i >= 2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1147 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1148
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1149 #if defined(FEAT_EVAL) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1150 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1151 * Allocate Dict for the completed item.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1152 * { word, abbr, menu, kind, info }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1153 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1154 static dict_T *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1155 ins_compl_dict_alloc(compl_T *match)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1156 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1157 dict_T *dict = dict_alloc_lock(VAR_FIXED);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1158
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1159 if (dict == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1160 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1161
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1162 dict_add_string(dict, "word", match->cp_str);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1163 dict_add_string(dict, "abbr", match->cp_text[CPT_ABBR]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1164 dict_add_string(dict, "menu", match->cp_text[CPT_MENU]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1165 dict_add_string(dict, "kind", match->cp_text[CPT_KIND]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1166 dict_add_string(dict, "info", match->cp_text[CPT_INFO]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1167 if (match->cp_user_data.v_type == VAR_UNKNOWN)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1168 dict_add_string(dict, "user_data", (char_u *)"");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1169 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1170 dict_add_tv(dict, "user_data", &match->cp_user_data);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1171
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1172 return dict;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1173 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1174
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1175 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1176 * Trigger the CompleteChanged autocmd event. Invoked each time the Insert mode
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1177 * completion menu is changed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1178 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1179 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1180 trigger_complete_changed_event(int cur)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1181 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1182 dict_T *v_event;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1183 dict_T *item;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1184 static int recursive = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1185 save_v_event_T save_v_event;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1186
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1187 if (recursive)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1188 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1189
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1190 if (cur < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1191 item = dict_alloc();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1192 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1193 item = ins_compl_dict_alloc(compl_curr_match);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1194 if (item == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1195 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1196 v_event = get_v_event(&save_v_event);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1197 dict_add_dict(v_event, "completed_item", item);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1198 pum_set_event_info(v_event);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1199 dict_set_items_ro(v_event);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1200
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1201 recursive = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1202 textlock++;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1203 apply_autocmds(EVENT_COMPLETECHANGED, NULL, NULL, FALSE, curbuf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1204 textlock--;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1205 recursive = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1206
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1207 restore_v_event(v_event, &save_v_event);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1208 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1209 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1210
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1211 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1212 * Build a popup menu to show the completion matches.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1213 * Returns the popup menu entry that should be selected. Returns -1 if nothing
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1214 * should be selected.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1215 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1216 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1217 ins_compl_build_pum(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1218 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1219 compl_T *compl;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1220 compl_T *shown_compl = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1221 int did_find_shown_match = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1222 int shown_match_ok = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1223 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1224 int cur = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1225 int lead_len = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1226
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1227 // Need to build the popup menu list.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1228 compl_match_arraysize = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1229 compl = compl_first_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1230 if (compl_leader != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1231 lead_len = (int)STRLEN(compl_leader);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1232
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1233 do
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1234 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1235 if (!match_at_original_text(compl)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1236 && (compl_leader == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1237 || ins_compl_equal(compl, compl_leader, lead_len)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1238 ++compl_match_arraysize;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1239 compl = compl->cp_next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1240 } while (compl != NULL && !is_first_match(compl));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1241
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1242 if (compl_match_arraysize == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1243 return -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1244
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1245 compl_match_array = ALLOC_CLEAR_MULT(pumitem_T, compl_match_arraysize);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1246 if (compl_match_array == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1247 return -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1248
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1249 // If the current match is the original text don't find the first
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1250 // match after it, don't highlight anything.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1251 if (match_at_original_text(compl_shown_match))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1252 shown_match_ok = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1253
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1254 i = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1255 compl = compl_first_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1256 do
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1257 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1258 if (!match_at_original_text(compl)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1259 && (compl_leader == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1260 || ins_compl_equal(compl, compl_leader, lead_len)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1261 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1262 if (!shown_match_ok)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1263 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1264 if (compl == compl_shown_match || did_find_shown_match)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1265 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1266 // This item is the shown match or this is the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1267 // first displayed item after the shown match.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1268 compl_shown_match = compl;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1269 did_find_shown_match = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1270 shown_match_ok = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1271 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1272 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1273 // Remember this displayed match for when the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1274 // shown match is just below it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1275 shown_compl = compl;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1276 cur = i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1277 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1278
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1279 if (compl->cp_text[CPT_ABBR] != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1280 compl_match_array[i].pum_text =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1281 compl->cp_text[CPT_ABBR];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1282 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1283 compl_match_array[i].pum_text = compl->cp_str;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1284 compl_match_array[i].pum_kind = compl->cp_text[CPT_KIND];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1285 compl_match_array[i].pum_info = compl->cp_text[CPT_INFO];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1286 if (compl->cp_text[CPT_MENU] != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1287 compl_match_array[i++].pum_extra =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1288 compl->cp_text[CPT_MENU];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1289 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1290 compl_match_array[i++].pum_extra = compl->cp_fname;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1291 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1292
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1293 if (compl == compl_shown_match)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1294 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1295 did_find_shown_match = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1296
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1297 // When the original text is the shown match don't set
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1298 // compl_shown_match.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1299 if (match_at_original_text(compl))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1300 shown_match_ok = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1301
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1302 if (!shown_match_ok && shown_compl != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1303 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1304 // The shown match isn't displayed, set it to the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1305 // previously displayed match.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1306 compl_shown_match = shown_compl;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1307 shown_match_ok = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1308 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1309 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1310 compl = compl->cp_next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1311 } while (compl != NULL && !is_first_match(compl));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1312
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1313 if (!shown_match_ok) // no displayed match at all
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1314 cur = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1315
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1316 return cur;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1317 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1318
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1319 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1320 * Show the popup menu for the list of matches.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1321 * Also adjusts "compl_shown_match" to an entry that is actually displayed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1322 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1323 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1324 ins_compl_show_pum(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1325 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1326 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1327 int cur = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1328 colnr_T col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1329
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1330 if (!pum_wanted() || !pum_enough_matches())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1331 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1332
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1333 #if defined(FEAT_EVAL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1334 // Dirty hard-coded hack: remove any matchparen highlighting.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1335 do_cmdline_cmd((char_u *)"if exists('g:loaded_matchparen')|:3match none|endif");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1336 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1337
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1338 // Update the screen later, before drawing the popup menu over it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1339 pum_call_update_screen();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1340
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1341 if (compl_match_array == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1342 // Need to build the popup menu list.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1343 cur = ins_compl_build_pum();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1344 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1345 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1346 // popup menu already exists, only need to find the current item.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1347 for (i = 0; i < compl_match_arraysize; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1348 if (compl_match_array[i].pum_text == compl_shown_match->cp_str
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1349 || compl_match_array[i].pum_text
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1350 == compl_shown_match->cp_text[CPT_ABBR])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1351 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1352 cur = i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1353 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1354 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1355 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1356
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1357 if (compl_match_array == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1358 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1359
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1360 // In Replace mode when a $ is displayed at the end of the line only
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1361 // part of the screen would be updated. We do need to redraw here.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1362 dollar_vcol = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1363
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1364 // Compute the screen column of the start of the completed text.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1365 // Use the cursor to get all wrapping and other settings right.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1366 col = curwin->w_cursor.col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1367 curwin->w_cursor.col = compl_col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1368 pum_display(compl_match_array, compl_match_arraysize, cur);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1369 curwin->w_cursor.col = col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1370
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1371 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1372 if (has_completechanged())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1373 trigger_complete_changed_event(cur);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1374 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1375 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1376
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1377 #define DICT_FIRST (1) // use just first element in "dict"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1378 #define DICT_EXACT (2) // "dict" is the exact name of a file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1379
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1380 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1381 * Add any identifiers that match the given pattern "pat" in the list of
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1382 * dictionary files "dict_start" to the list of completions.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1383 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1384 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1385 ins_compl_dictionaries(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1386 char_u *dict_start,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1387 char_u *pat,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1388 int flags, // DICT_FIRST and/or DICT_EXACT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1389 int thesaurus) // Thesaurus completion
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1390 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1391 char_u *dict = dict_start;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1392 char_u *ptr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1393 char_u *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1394 regmatch_T regmatch;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1395 char_u **files;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1396 int count;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1397 int save_p_scs;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1398 int dir = compl_direction;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1399
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1400 if (*dict == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1401 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1402 #ifdef FEAT_SPELL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1403 // When 'dictionary' is empty and spell checking is enabled use
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1404 // "spell".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1405 if (!thesaurus && curwin->w_p_spell)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1406 dict = (char_u *)"spell";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1407 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1408 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1409 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1410 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1411
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1412 buf = alloc(LSIZE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1413 if (buf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1414 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1415 regmatch.regprog = NULL; // so that we can goto theend
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1416
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1417 // If 'infercase' is set, don't use 'smartcase' here
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1418 save_p_scs = p_scs;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1419 if (curbuf->b_p_inf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1420 p_scs = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1421
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1422 // When invoked to match whole lines for CTRL-X CTRL-L adjust the pattern
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1423 // to only match at the start of a line. Otherwise just match the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1424 // pattern. Also need to double backslashes.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1425 if (ctrl_x_mode_line_or_eval())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1426 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1427 char_u *pat_esc = vim_strsave_escaped(pat, (char_u *)"\\");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1428 size_t len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1429
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1430 if (pat_esc == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1431 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1432 len = STRLEN(pat_esc) + 10;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1433 ptr = alloc(len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1434 if (ptr == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1435 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1436 vim_free(pat_esc);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1437 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1438 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1439 vim_snprintf((char *)ptr, len, "^\\s*\\zs\\V%s", pat_esc);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1440 regmatch.regprog = vim_regcomp(ptr, RE_MAGIC);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1441 vim_free(pat_esc);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1442 vim_free(ptr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1443 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1444 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1445 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1446 regmatch.regprog = vim_regcomp(pat, magic_isset() ? RE_MAGIC : 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1447 if (regmatch.regprog == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1448 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1449 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1450
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1451 // ignore case depends on 'ignorecase', 'smartcase' and "pat"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1452 regmatch.rm_ic = ignorecase(pat);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1453 while (*dict != NUL && !got_int && !compl_interrupted)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1454 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1455 // copy one dictionary file name into buf
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1456 if (flags == DICT_EXACT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1457 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1458 count = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1459 files = &dict;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1460 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1461 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1462 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1463 // Expand wildcards in the dictionary name, but do not allow
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1464 // backticks (for security, the 'dict' option may have been set in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1465 // a modeline).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1466 copy_option_part(&dict, buf, LSIZE, ",");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1467 # ifdef FEAT_SPELL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1468 if (!thesaurus && STRCMP(buf, "spell") == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1469 count = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1470 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1471 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1472 if (vim_strchr(buf, '`') != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1473 || expand_wildcards(1, &buf, &count, &files,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1474 EW_FILE|EW_SILENT) != OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1475 count = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1476 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1477
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1478 # ifdef FEAT_SPELL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1479 if (count == -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1480 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1481 // Complete from active spelling. Skip "\<" in the pattern, we
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1482 // don't use it as a RE.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1483 if (pat[0] == '\\' && pat[1] == '<')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1484 ptr = pat + 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1485 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1486 ptr = pat;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1487 spell_dump_compl(ptr, regmatch.rm_ic, &dir, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1488 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1489 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1490 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1491 if (count > 0) // avoid warning for using "files" uninit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1492 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1493 ins_compl_files(count, files, thesaurus, flags,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1494 &regmatch, buf, &dir);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1495 if (flags != DICT_EXACT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1496 FreeWild(count, files);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1497 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1498 if (flags != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1499 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1500 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1501
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1502 theend:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1503 p_scs = save_p_scs;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1504 vim_regfree(regmatch.regprog);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1505 vim_free(buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1506 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1507
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1508 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1509 * Add all the words in the line "*buf_arg" from the thesaurus file "fname"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1510 * skipping the word at 'skip_word'. Returns OK on success.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1511 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1512 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1513 thesaurus_add_words_in_line(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1514 char_u *fname,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1515 char_u **buf_arg,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1516 int dir,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1517 char_u *skip_word)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1518 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1519 int status = OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1520 char_u *ptr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1521 char_u *wstart;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1522
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1523 // Add the other matches on the line
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1524 ptr = *buf_arg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1525 while (!got_int)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1526 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1527 // Find start of the next word. Skip white
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1528 // space and punctuation.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1529 ptr = find_word_start(ptr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1530 if (*ptr == NUL || *ptr == NL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1531 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1532 wstart = ptr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1533
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1534 // Find end of the word.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1535 if (has_mbyte)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1536 // Japanese words may have characters in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1537 // different classes, only separate words
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1538 // with single-byte non-word characters.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1539 while (*ptr != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1540 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1541 int l = (*mb_ptr2len)(ptr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1542
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1543 if (l < 2 && !vim_iswordc(*ptr))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1544 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1545 ptr += l;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1546 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1547 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1548 ptr = find_word_end(ptr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1549
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1550 // Add the word. Skip the regexp match.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1551 if (wstart != skip_word)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1552 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1553 status = ins_compl_add_infercase(wstart, (int)(ptr - wstart), p_ic,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1554 fname, dir, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1555 if (status == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1556 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1557 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1558 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1559
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1560 *buf_arg = ptr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1561 return status;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1562 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1563
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1564 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1565 * Process "count" dictionary/thesaurus "files" and add the text matching
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1566 * "regmatch".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1567 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1568 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1569 ins_compl_files(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1570 int count,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1571 char_u **files,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1572 int thesaurus,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1573 int flags,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1574 regmatch_T *regmatch,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1575 char_u *buf,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1576 int *dir)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1577 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1578 char_u *ptr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1579 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1580 FILE *fp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1581 int add_r;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1582
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1583 for (i = 0; i < count && !got_int && !compl_interrupted; i++)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1584 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1585 fp = mch_fopen((char *)files[i], "r"); // open dictionary file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1586 if (flags != DICT_EXACT && !shortmess(SHM_COMPLETIONSCAN))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1587 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1588 msg_hist_off = TRUE; // reset in msg_trunc_attr()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1589 vim_snprintf((char *)IObuff, IOSIZE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1590 _("Scanning dictionary: %s"), (char *)files[i]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1591 (void)msg_trunc_attr((char *)IObuff, TRUE, HL_ATTR(HLF_R));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1592 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1593
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1594 if (fp == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1595 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1596
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1597 // Read dictionary file line by line.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1598 // Check each line for a match.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1599 while (!got_int && !compl_interrupted && !vim_fgets(buf, LSIZE, fp))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1600 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1601 ptr = buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1602 while (vim_regexec(regmatch, buf, (colnr_T)(ptr - buf)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1603 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1604 ptr = regmatch->startp[0];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1605 if (ctrl_x_mode_line_or_eval())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1606 ptr = find_line_end(ptr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1607 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1608 ptr = find_word_end(ptr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1609 add_r = ins_compl_add_infercase(regmatch->startp[0],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1610 (int)(ptr - regmatch->startp[0]),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1611 p_ic, files[i], *dir, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1612 if (thesaurus)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1613 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1614 // For a thesaurus, add all the words in the line
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1615 ptr = buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1616 add_r = thesaurus_add_words_in_line(files[i], &ptr, *dir,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1617 regmatch->startp[0]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1618 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1619 if (add_r == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1620 // if dir was BACKWARD then honor it just once
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1621 *dir = FORWARD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1622 else if (add_r == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1623 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1624 // avoid expensive call to vim_regexec() when at end
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1625 // of line
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1626 if (*ptr == '\n' || got_int)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1627 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1628 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1629 line_breakcheck();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1630 ins_compl_check_keys(50, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1631 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1632 fclose(fp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1633 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1634 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1635
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1636 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1637 * Find the start of the next word.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1638 * Returns a pointer to the first char of the word. Also stops at a NUL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1639 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1640 char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1641 find_word_start(char_u *ptr)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1642 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1643 if (has_mbyte)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1644 while (*ptr != NUL && *ptr != '\n' && mb_get_class(ptr) <= 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1645 ptr += (*mb_ptr2len)(ptr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1646 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1647 while (*ptr != NUL && *ptr != '\n' && !vim_iswordc(*ptr))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1648 ++ptr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1649 return ptr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1650 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1651
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1652 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1653 * Find the end of the word. Assumes it starts inside a word.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1654 * Returns a pointer to just after the word.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1655 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1656 char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1657 find_word_end(char_u *ptr)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1658 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1659 int start_class;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1660
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1661 if (has_mbyte)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1662 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1663 start_class = mb_get_class(ptr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1664 if (start_class > 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1665 while (*ptr != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1666 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1667 ptr += (*mb_ptr2len)(ptr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1668 if (mb_get_class(ptr) != start_class)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1669 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1670 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1671 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1672 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1673 while (vim_iswordc(*ptr))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1674 ++ptr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1675 return ptr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1676 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1677
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1678 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1679 * Find the end of the line, omitting CR and NL at the end.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1680 * Returns a pointer to just after the line.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1681 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1682 static char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1683 find_line_end(char_u *ptr)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1684 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1685 char_u *s;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1686
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1687 s = ptr + STRLEN(ptr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1688 while (s > ptr && (s[-1] == CAR || s[-1] == NL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1689 --s;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1690 return s;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1691 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1692
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1693 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1694 * Free the list of completions
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1695 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1696 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1697 ins_compl_free(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1698 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1699 compl_T *match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1700 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1701
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1702 VIM_CLEAR(compl_pattern);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1703 VIM_CLEAR(compl_leader);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1704
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1705 if (compl_first_match == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1706 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1707
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1708 ins_compl_del_pum();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1709 pum_clear();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1710
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1711 compl_curr_match = compl_first_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1712 do
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1713 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1714 match = compl_curr_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1715 compl_curr_match = compl_curr_match->cp_next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1716 vim_free(match->cp_str);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1717 // several entries may use the same fname, free it just once.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1718 if (match->cp_flags & CP_FREE_FNAME)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1719 vim_free(match->cp_fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1720 for (i = 0; i < CPT_COUNT; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1721 vim_free(match->cp_text[i]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1722 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1723 clear_tv(&match->cp_user_data);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1724 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1725 vim_free(match);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1726 } while (compl_curr_match != NULL && !is_first_match(compl_curr_match));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1727 compl_first_match = compl_curr_match = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1728 compl_shown_match = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1729 compl_old_match = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1730 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1731
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1732 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1733 * Reset/clear the completion state.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1734 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1735 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1736 ins_compl_clear(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1737 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1738 compl_cont_status = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1739 compl_started = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1740 compl_matches = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1741 VIM_CLEAR(compl_pattern);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1742 VIM_CLEAR(compl_leader);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1743 edit_submode_extra = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1744 VIM_CLEAR(compl_orig_text);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1745 compl_enter_selects = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1746 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1747 // clear v:completed_item
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1748 set_vim_var_dict(VV_COMPLETED_ITEM, dict_alloc_lock(VAR_FIXED));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1749 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1750 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1751
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1752 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1753 * Return TRUE when Insert completion is active.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1754 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1755 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1756 ins_compl_active(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1757 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1758 return compl_started;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1759 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1760
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1761 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1762 * Selected one of the matches. When FALSE the match was edited or using the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1763 * longest common string.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1764 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1765 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1766 ins_compl_used_match(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1767 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1768 return compl_used_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1769 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1770
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1771 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1772 * Initialize get longest common string.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1773 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1774 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1775 ins_compl_init_get_longest(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1776 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1777 compl_get_longest = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1778 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1779
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1780 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1781 * Returns TRUE when insert completion is interrupted.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1782 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1783 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1784 ins_compl_interrupted(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1785 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1786 return compl_interrupted;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1787 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1788
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1789 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1790 * Returns TRUE if the <Enter> key selects a match in the completion popup
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1791 * menu.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1792 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1793 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1794 ins_compl_enter_selects(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1795 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1796 return compl_enter_selects;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1797 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1798
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1799 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1800 * Return the column where the text starts that is being completed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1801 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1802 colnr_T
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1803 ins_compl_col(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1804 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1805 return compl_col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1806 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1807
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1808 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1809 * Return the length in bytes of the text being completed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1810 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1811 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1812 ins_compl_len(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1813 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1814 return compl_length;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1815 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1816
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1817 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1818 * Delete one character before the cursor and show the subset of the matches
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1819 * that match the word that is now before the cursor.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1820 * Returns the character to be used, NUL if the work is done and another char
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1821 * to be got from the user.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1822 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1823 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1824 ins_compl_bs(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1825 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1826 char_u *line;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1827 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1828
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1829 line = ml_get_curline();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1830 p = line + curwin->w_cursor.col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1831 MB_PTR_BACK(line, p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1832
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1833 // Stop completion when the whole word was deleted. For Omni completion
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1834 // allow the word to be deleted, we won't match everything.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1835 // Respect the 'backspace' option.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1836 if ((int)(p - line) - (int)compl_col < 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1837 || ((int)(p - line) - (int)compl_col == 0 && !ctrl_x_mode_omni())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1838 || ctrl_x_mode_eval()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1839 || (!can_bs(BS_START) && (int)(p - line) - (int)compl_col
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1840 - compl_length < 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1841 return K_BS;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1842
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1843 // Deleted more than what was used to find matches or didn't finish
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1844 // finding all matches: need to look for matches all over again.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1845 if (curwin->w_cursor.col <= compl_col + compl_length
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1846 || ins_compl_need_restart())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1847 ins_compl_restart();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1848
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1849 vim_free(compl_leader);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1850 compl_leader = vim_strnsave(line + compl_col, (p - line) - compl_col);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1851 if (compl_leader == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1852 return K_BS;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1853
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1854 ins_compl_new_leader();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1855 if (compl_shown_match != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1856 // Make sure current match is not a hidden item.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1857 compl_curr_match = compl_shown_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1858 return NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1859 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1860
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1861 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1862 * Return TRUE when we need to find matches again, ins_compl_restart() is to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1863 * be called.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1864 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1865 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1866 ins_compl_need_restart(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1867 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1868 // Return TRUE if we didn't complete finding matches or when the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1869 // 'completefunc' returned "always" in the "refresh" dictionary item.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1870 return compl_was_interrupted
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1871 || ((ctrl_x_mode_function() || ctrl_x_mode_omni())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1872 && compl_opt_refresh_always);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1873 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1874
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1875 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1876 * Called after changing "compl_leader".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1877 * Show the popup menu with a different set of matches.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1878 * May also search for matches again if the previous search was interrupted.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1879 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1880 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1881 ins_compl_new_leader(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1882 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1883 ins_compl_del_pum();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1884 ins_compl_delete();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1885 ins_bytes(compl_leader + get_compl_len());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1886 compl_used_match = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1887
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1888 if (compl_started)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1889 ins_compl_set_original_text(compl_leader);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1890 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1891 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1892 #ifdef FEAT_SPELL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1893 spell_bad_len = 0; // need to redetect bad word
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1894 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1895 // Matches were cleared, need to search for them now. Before drawing
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1896 // the popup menu display the changed text before the cursor. Set
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1897 // "compl_restarting" to avoid that the first match is inserted.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1898 pum_call_update_screen();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1899 #ifdef FEAT_GUI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1900 if (gui.in_use)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1901 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1902 // Show the cursor after the match, not after the redrawn text.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1903 setcursor();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1904 out_flush_cursor(FALSE, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1905 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1906 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1907 compl_restarting = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1908 if (ins_complete(Ctrl_N, TRUE) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1909 compl_cont_status = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1910 compl_restarting = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1911 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1912
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1913 compl_enter_selects = !compl_used_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1914
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1915 // Show the popup menu with a different set of matches.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1916 ins_compl_show_pum();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1917
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1918 // Don't let Enter select the original text when there is no popup menu.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1919 if (compl_match_array == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1920 compl_enter_selects = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1921 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1922
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1923 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1924 * Return the length of the completion, from the completion start column to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1925 * the cursor column. Making sure it never goes below zero.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1926 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1927 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1928 get_compl_len(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1929 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1930 int off = (int)curwin->w_cursor.col - (int)compl_col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1931
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1932 if (off < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1933 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1934 return off;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1935 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1936
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1937 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1938 * Append one character to the match leader. May reduce the number of
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1939 * matches.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1940 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1941 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1942 ins_compl_addleader(int c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1943 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1944 int cc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1945
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1946 if (stop_arrow() == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1947 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1948 if (has_mbyte && (cc = (*mb_char2len)(c)) > 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1949 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1950 char_u buf[MB_MAXBYTES + 1];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1951
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1952 (*mb_char2bytes)(c, buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1953 buf[cc] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1954 ins_char_bytes(buf, cc);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1955 if (compl_opt_refresh_always)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1956 AppendToRedobuff(buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1957 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1958 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1959 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1960 ins_char(c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1961 if (compl_opt_refresh_always)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1962 AppendCharToRedobuff(c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1963 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1964
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1965 // If we didn't complete finding matches we must search again.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1966 if (ins_compl_need_restart())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1967 ins_compl_restart();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1968
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1969 // When 'always' is set, don't reset compl_leader. While completing,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1970 // cursor doesn't point original position, changing compl_leader would
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1971 // break redo.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1972 if (!compl_opt_refresh_always)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1973 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1974 vim_free(compl_leader);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1975 compl_leader = vim_strnsave(ml_get_curline() + compl_col,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1976 curwin->w_cursor.col - compl_col);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1977 if (compl_leader != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1978 ins_compl_new_leader();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1979 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1980 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1981
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1982 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1983 * Setup for finding completions again without leaving CTRL-X mode. Used when
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1984 * BS or a key was typed while still searching for matches.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1985 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1986 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1987 ins_compl_restart(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1988 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1989 ins_compl_free();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1990 compl_started = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1991 compl_matches = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1992 compl_cont_status = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1993 compl_cont_mode = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1994 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1995
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1996 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1997 * Set the first match, the original text.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1998 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
1999 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2000 ins_compl_set_original_text(char_u *str)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2001 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2002 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2003
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2004 // Replace the original text entry.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2005 // The CP_ORIGINAL_TEXT flag is either at the first item or might possibly
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2006 // be at the last item for backward completion
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2007 if (match_at_original_text(compl_first_match)) // safety check
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2008 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2009 p = vim_strsave(str);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2010 if (p != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2011 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2012 vim_free(compl_first_match->cp_str);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2013 compl_first_match->cp_str = p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2014 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2015 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2016 else if (compl_first_match->cp_prev != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2017 && match_at_original_text(compl_first_match->cp_prev))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2018 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2019 p = vim_strsave(str);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2020 if (p != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2021 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2022 vim_free(compl_first_match->cp_prev->cp_str);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2023 compl_first_match->cp_prev->cp_str = p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2024 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2025 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2026 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2027
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2028 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2029 * Append one character to the match leader. May reduce the number of
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2030 * matches.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2031 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2032 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2033 ins_compl_addfrommatch(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2034 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2035 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2036 int len = (int)curwin->w_cursor.col - (int)compl_col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2037 int c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2038 compl_T *cp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2039
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2040 p = compl_shown_match->cp_str;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2041 if ((int)STRLEN(p) <= len) // the match is too short
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2042 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2043 // When still at the original match use the first entry that matches
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2044 // the leader.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2045 if (!match_at_original_text(compl_shown_match))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2046 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2047
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2048 p = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2049 for (cp = compl_shown_match->cp_next; cp != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2050 && !is_first_match(cp); cp = cp->cp_next)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2051 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2052 if (compl_leader == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2053 || ins_compl_equal(cp, compl_leader,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2054 (int)STRLEN(compl_leader)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2055 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2056 p = cp->cp_str;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2057 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2058 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2059 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2060 if (p == NULL || (int)STRLEN(p) <= len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2061 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2062 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2063 p += len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2064 c = PTR2CHAR(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2065 ins_compl_addleader(c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2066 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2067
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2068 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2069 * Set the CTRL-X completion mode based on the key "c" typed after a CTRL-X.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2070 * Uses the global variables: ctrl_x_mode, edit_submode, edit_submode_pre,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2071 * compl_cont_mode and compl_cont_status.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2072 * Returns TRUE when the character is not to be inserted.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2073 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2074 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2075 set_ctrl_x_mode(int c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2076 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2077 int retval = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2078
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2079 switch (c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2080 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2081 case Ctrl_E:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2082 case Ctrl_Y:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2083 // scroll the window one line up or down
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2084 ctrl_x_mode = CTRL_X_SCROLL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2085 if (!(State & REPLACE_FLAG))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2086 edit_submode = (char_u *)_(" (insert) Scroll (^E/^Y)");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2087 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2088 edit_submode = (char_u *)_(" (replace) Scroll (^E/^Y)");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2089 edit_submode_pre = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2090 showmode();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2091 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2092 case Ctrl_L:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2093 // complete whole line
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2094 ctrl_x_mode = CTRL_X_WHOLE_LINE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2095 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2096 case Ctrl_F:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2097 // complete filenames
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2098 ctrl_x_mode = CTRL_X_FILES;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2099 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2100 case Ctrl_K:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2101 // complete words from a dictionary
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2102 ctrl_x_mode = CTRL_X_DICTIONARY;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2103 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2104 case Ctrl_R:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2105 // Register insertion without exiting CTRL-X mode
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2106 // Simply allow ^R to happen without affecting ^X mode
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2107 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2108 case Ctrl_T:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2109 // complete words from a thesaurus
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2110 ctrl_x_mode = CTRL_X_THESAURUS;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2111 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2112 #ifdef FEAT_COMPL_FUNC
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2113 case Ctrl_U:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2114 // user defined completion
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2115 ctrl_x_mode = CTRL_X_FUNCTION;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2116 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2117 case Ctrl_O:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2118 // omni completion
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2119 ctrl_x_mode = CTRL_X_OMNI;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2120 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2121 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2122 case 's':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2123 case Ctrl_S:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2124 // complete spelling suggestions
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2125 ctrl_x_mode = CTRL_X_SPELL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2126 #ifdef FEAT_SPELL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2127 ++emsg_off; // Avoid getting the E756 error twice.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2128 spell_back_to_badword();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2129 --emsg_off;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2130 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2131 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2132 case Ctrl_RSB:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2133 // complete tag names
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2134 ctrl_x_mode = CTRL_X_TAGS;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2135 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2136 #ifdef FEAT_FIND_ID
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2137 case Ctrl_I:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2138 case K_S_TAB:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2139 // complete keywords from included files
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2140 ctrl_x_mode = CTRL_X_PATH_PATTERNS;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2141 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2142 case Ctrl_D:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2143 // complete definitions from included files
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2144 ctrl_x_mode = CTRL_X_PATH_DEFINES;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2145 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2146 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2147 case Ctrl_V:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2148 case Ctrl_Q:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2149 // complete vim commands
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2150 ctrl_x_mode = CTRL_X_CMDLINE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2151 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2152 case Ctrl_Z:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2153 // stop completion
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2154 ctrl_x_mode = CTRL_X_NORMAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2155 edit_submode = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2156 showmode();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2157 retval = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2158 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2159 case Ctrl_P:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2160 case Ctrl_N:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2161 // ^X^P means LOCAL expansion if nothing interrupted (eg we
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2162 // just started ^X mode, or there were enough ^X's to cancel
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2163 // the previous mode, say ^X^F^X^X^P or ^P^X^X^X^P, see below)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2164 // do normal expansion when interrupting a different mode (say
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2165 // ^X^F^X^P or ^P^X^X^P, see below)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2166 // nothing changes if interrupting mode 0, (eg, the flag
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2167 // doesn't change when going to ADDING mode -- Acevedo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2168 if (!(compl_cont_status & CONT_INTRPT))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2169 compl_cont_status |= CONT_LOCAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2170 else if (compl_cont_mode != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2171 compl_cont_status &= ~CONT_LOCAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2172 // FALLTHROUGH
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2173 default:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2174 // If we have typed at least 2 ^X's... for modes != 0, we set
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2175 // compl_cont_status = 0 (eg, as if we had just started ^X
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2176 // mode).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2177 // For mode 0, we set "compl_cont_mode" to an impossible
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2178 // value, in both cases ^X^X can be used to restart the same
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2179 // mode (avoiding ADDING mode).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2180 // Undocumented feature: In a mode != 0 ^X^P and ^X^X^P start
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2181 // 'complete' and local ^P expansions respectively.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2182 // In mode 0 an extra ^X is needed since ^X^P goes to ADDING
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2183 // mode -- Acevedo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2184 if (c == Ctrl_X)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2185 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2186 if (compl_cont_mode != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2187 compl_cont_status = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2188 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2189 compl_cont_mode = CTRL_X_NOT_DEFINED_YET;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2190 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2191 ctrl_x_mode = CTRL_X_NORMAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2192 edit_submode = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2193 showmode();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2194 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2195 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2196
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2197 return retval;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2198 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2199
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2200 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2201 * Stop insert completion mode
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2202 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2203 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2204 ins_compl_stop(int c, int prev_mode, int retval)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2205 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2206 char_u *ptr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2207 int want_cindent;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2208
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2209 // Get here when we have finished typing a sequence of ^N and
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2210 // ^P or other completion characters in CTRL-X mode. Free up
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2211 // memory that was used, and make sure we can redo the insert.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2212 if (compl_curr_match != NULL || compl_leader != NULL || c == Ctrl_E)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2213 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2214 // If any of the original typed text has been changed, eg when
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2215 // ignorecase is set, we must add back-spaces to the redo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2216 // buffer. We add as few as necessary to delete just the part
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2217 // of the original text that has changed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2218 // When using the longest match, edited the match or used
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2219 // CTRL-E then don't use the current match.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2220 if (compl_curr_match != NULL && compl_used_match && c != Ctrl_E)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2221 ptr = compl_curr_match->cp_str;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2222 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2223 ptr = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2224 ins_compl_fixRedoBufForLeader(ptr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2225 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2226
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2227 want_cindent = (get_can_cindent() && cindent_on());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2228
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2229 // When completing whole lines: fix indent for 'cindent'.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2230 // Otherwise, break line if it's too long.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2231 if (compl_cont_mode == CTRL_X_WHOLE_LINE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2232 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2233 // re-indent the current line
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2234 if (want_cindent)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2235 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2236 do_c_expr_indent();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2237 want_cindent = FALSE; // don't do it again
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2238 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2239 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2240 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2241 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2242 int prev_col = curwin->w_cursor.col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2243
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2244 // put the cursor on the last char, for 'tw' formatting
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2245 if (prev_col > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2246 dec_cursor();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2247 // only format when something was inserted
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2248 if (!arrow_used && !ins_need_undo_get() && c != Ctrl_E)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2249 insertchar(NUL, 0, -1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2250 if (prev_col > 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2251 && ml_get_curline()[curwin->w_cursor.col] != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2252 inc_cursor();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2253 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2254
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2255 // If the popup menu is displayed pressing CTRL-Y means accepting
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2256 // the selection without inserting anything. When
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2257 // compl_enter_selects is set the Enter key does the same.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2258 if ((c == Ctrl_Y || (compl_enter_selects
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2259 && (c == CAR || c == K_KENTER || c == NL)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2260 && pum_visible())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2261 retval = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2262
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2263 // CTRL-E means completion is Ended, go back to the typed text.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2264 // but only do this, if the Popup is still visible
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2265 if (c == Ctrl_E)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2266 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2267 char_u *p = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2268
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2269 ins_compl_delete();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2270 if (compl_leader != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2271 p = compl_leader;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2272 else if (compl_first_match != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2273 p = compl_orig_text;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2274 if (p != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2275 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2276 int compl_len = get_compl_len();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2277 int len = (int)STRLEN(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2278
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2279 if (len > compl_len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2280 ins_bytes_len(p + compl_len, len - compl_len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2281 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2282 retval = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2283 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2284
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2285 auto_format(FALSE, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2286
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2287 // Trigger the CompleteDonePre event to give scripts a chance to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2288 // act upon the completion before clearing the info, and restore
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2289 // ctrl_x_mode, so that complete_info() can be used.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2290 ctrl_x_mode = prev_mode;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2291 ins_apply_autocmds(EVENT_COMPLETEDONEPRE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2292
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2293 ins_compl_free();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2294 compl_started = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2295 compl_matches = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2296 if (!shortmess(SHM_COMPLETIONMENU))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2297 msg_clr_cmdline(); // necessary for "noshowmode"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2298 ctrl_x_mode = CTRL_X_NORMAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2299 compl_enter_selects = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2300 if (edit_submode != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2301 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2302 edit_submode = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2303 showmode();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2304 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2305
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2306 if (c == Ctrl_C && cmdwin_type != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2307 // Avoid the popup menu remains displayed when leaving the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2308 // command line window.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2309 update_screen(0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2310 // Indent now if a key was typed that is in 'cinkeys'.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2311 if (want_cindent && in_cinkeys(KEY_COMPLETE, ' ', inindent(0)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2312 do_c_expr_indent();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2313 // Trigger the CompleteDone event to give scripts a chance to act
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2314 // upon the end of completion.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2315 ins_apply_autocmds(EVENT_COMPLETEDONE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2316
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2317 return retval;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2318 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2319
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2320 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2321 * Prepare for Insert mode completion, or stop it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2322 * Called just after typing a character in Insert mode.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2323 * Returns TRUE when the character is not to be inserted;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2324 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2325 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2326 ins_compl_prep(int c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2327 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2328 int retval = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2329 int prev_mode = ctrl_x_mode;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2330
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2331 // Forget any previous 'special' messages if this is actually
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2332 // a ^X mode key - bar ^R, in which case we wait to see what it gives us.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2333 if (c != Ctrl_R && vim_is_ctrl_x_key(c))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2334 edit_submode_extra = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2335
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2336 // Ignore end of Select mode mapping and mouse scroll/movement.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2337 if (c == K_SELECT || c == K_MOUSEDOWN || c == K_MOUSEUP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2338 || c == K_MOUSELEFT || c == K_MOUSERIGHT || c == K_MOUSEMOVE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2339 || c == K_COMMAND || c == K_SCRIPT_COMMAND)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2340 return retval;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2341
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2342 #ifdef FEAT_PROP_POPUP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2343 // Ignore mouse events in a popup window
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2344 if (is_mouse_key(c))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2345 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2346 // Ignore drag and release events, the position does not need to be in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2347 // the popup and it may have just closed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2348 if (c == K_LEFTRELEASE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2349 || c == K_LEFTRELEASE_NM
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2350 || c == K_MIDDLERELEASE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2351 || c == K_RIGHTRELEASE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2352 || c == K_X1RELEASE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2353 || c == K_X2RELEASE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2354 || c == K_LEFTDRAG
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2355 || c == K_MIDDLEDRAG
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2356 || c == K_RIGHTDRAG
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2357 || c == K_X1DRAG
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2358 || c == K_X2DRAG)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2359 return retval;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2360 if (popup_visible)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2361 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2362 int row = mouse_row;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2363 int col = mouse_col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2364 win_T *wp = mouse_find_win(&row, &col, FIND_POPUP);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2365
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2366 if (wp != NULL && WIN_IS_POPUP(wp))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2367 return retval;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2368 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2369 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2370 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2371
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2372 if (ctrl_x_mode == CTRL_X_CMDLINE_CTRL_X && c != Ctrl_X)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2373 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2374 if (c == Ctrl_V || c == Ctrl_Q || c == Ctrl_Z || ins_compl_pum_key(c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2375 || !vim_is_ctrl_x_key(c))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2376 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2377 // Not starting another completion mode.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2378 ctrl_x_mode = CTRL_X_CMDLINE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2379
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2380 // CTRL-X CTRL-Z should stop completion without inserting anything
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2381 if (c == Ctrl_Z)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2382 retval = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2383 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2384 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2385 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2386 ctrl_x_mode = CTRL_X_CMDLINE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2387
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2388 // Other CTRL-X keys first stop completion, then start another
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2389 // completion mode.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2390 ins_compl_prep(' ');
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2391 ctrl_x_mode = CTRL_X_NOT_DEFINED_YET;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2392 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2393 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2394
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2395 // Set "compl_get_longest" when finding the first matches.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2396 if (ctrl_x_mode_not_defined_yet()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2397 || (ctrl_x_mode_normal() && !compl_started))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2398 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2399 compl_get_longest = compl_longest;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2400 compl_used_match = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2401
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2402 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2403
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2404 if (ctrl_x_mode_not_defined_yet())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2405 // We have just typed CTRL-X and aren't quite sure which CTRL-X mode
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2406 // it will be yet. Now we decide.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2407 retval = set_ctrl_x_mode(c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2408 else if (ctrl_x_mode_not_default())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2409 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2410 // We're already in CTRL-X mode, do we stay in it?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2411 if (!vim_is_ctrl_x_key(c))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2412 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2413 if (ctrl_x_mode_scroll())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2414 ctrl_x_mode = CTRL_X_NORMAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2415 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2416 ctrl_x_mode = CTRL_X_FINISHED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2417 edit_submode = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2418 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2419 showmode();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2420 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2421
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2422 if (compl_started || ctrl_x_mode == CTRL_X_FINISHED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2423 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2424 // Show error message from attempted keyword completion (probably
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2425 // 'Pattern not found') until another key is hit, then go back to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2426 // showing what mode we are in.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2427 showmode();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2428 if ((ctrl_x_mode_normal() && c != Ctrl_N && c != Ctrl_P
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2429 && c != Ctrl_R && !ins_compl_pum_key(c))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2430 || ctrl_x_mode == CTRL_X_FINISHED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2431 retval = ins_compl_stop(c, prev_mode, retval);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2432 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2433 else if (ctrl_x_mode == CTRL_X_LOCAL_MSG)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2434 // Trigger the CompleteDone event to give scripts a chance to act
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2435 // upon the (possibly failed) completion.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2436 ins_apply_autocmds(EVENT_COMPLETEDONE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2437
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2438 may_trigger_modechanged();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2439
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2440 // reset continue_* if we left expansion-mode, if we stay they'll be
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2441 // (re)set properly in ins_complete()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2442 if (!vim_is_ctrl_x_key(c))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2443 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2444 compl_cont_status = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2445 compl_cont_mode = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2446 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2447
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2448 return retval;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2449 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2450
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2451 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2452 * Fix the redo buffer for the completion leader replacing some of the typed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2453 * text. This inserts backspaces and appends the changed text.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2454 * "ptr" is the known leader text or NUL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2455 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2456 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2457 ins_compl_fixRedoBufForLeader(char_u *ptr_arg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2458 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2459 int len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2460 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2461 char_u *ptr = ptr_arg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2462
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2463 if (ptr == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2464 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2465 if (compl_leader != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2466 ptr = compl_leader;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2467 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2468 return; // nothing to do
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2469 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2470 if (compl_orig_text != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2471 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2472 p = compl_orig_text;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2473 for (len = 0; p[len] != NUL && p[len] == ptr[len]; ++len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2474 ;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2475 if (len > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2476 len -= (*mb_head_off)(p, p + len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2477 for (p += len; *p != NUL; MB_PTR_ADV(p))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2478 AppendCharToRedobuff(K_BS);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2479 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2480 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2481 len = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2482 if (ptr != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2483 AppendToRedobuffLit(ptr + len, -1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2484 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2485
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2486 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2487 * Loops through the list of windows, loaded-buffers or non-loaded-buffers
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2488 * (depending on flag) starting from buf and looking for a non-scanned
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2489 * buffer (other than curbuf). curbuf is special, if it is called with
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2490 * buf=curbuf then it has to be the first call for a given flag/expansion.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2491 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2492 * Returns the buffer to scan, if any, otherwise returns curbuf -- Acevedo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2493 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2494 static buf_T *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2495 ins_compl_next_buf(buf_T *buf, int flag)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2496 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2497 static win_T *wp = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2498
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2499 if (flag == 'w') // just windows
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2500 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2501 if (buf == curbuf || !win_valid(wp))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2502 // first call for this flag/expansion or window was closed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2503 wp = curwin;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2504 while ((wp = (wp->w_next != NULL ? wp->w_next : firstwin)) != curwin
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2505 && wp->w_buffer->b_scanned)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2506 ;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2507 buf = wp->w_buffer;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2508 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2509 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2510 // 'b' (just loaded buffers), 'u' (just non-loaded buffers) or 'U'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2511 // (unlisted buffers)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2512 // When completing whole lines skip unloaded buffers.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2513 while ((buf = (buf->b_next != NULL ? buf->b_next : firstbuf)) != curbuf
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2514 && ((flag == 'U'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2515 ? buf->b_p_bl
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2516 : (!buf->b_p_bl
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2517 || (buf->b_ml.ml_mfp == NULL) != (flag == 'u')))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2518 || buf->b_scanned))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2519 ;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2520 return buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2521 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2522
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2523 #ifdef FEAT_COMPL_FUNC
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2524
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2525 # ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2526 static callback_T cfu_cb; // 'completefunc' callback function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2527 static callback_T ofu_cb; // 'omnifunc' callback function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2528 static callback_T tsrfu_cb; // 'thesaurusfunc' callback function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2529 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2530
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2531 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2532 * Copy a global callback function to a buffer local callback.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2533 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2534 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2535 copy_global_to_buflocal_cb(callback_T *globcb, callback_T *bufcb)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2536 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2537 free_callback(bufcb);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2538 if (globcb->cb_name != NULL && *globcb->cb_name != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2539 copy_callback(bufcb, globcb);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2540 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2541
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2542 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2543 * Parse the 'completefunc' option value and set the callback function.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2544 * Invoked when the 'completefunc' option is set. The option value can be a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2545 * name of a function (string), or function(<name>) or funcref(<name>) or a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2546 * lambda expression.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2547 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2548 char *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2549 did_set_completefunc(optset_T *args UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2550 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2551 if (option_set_callback_func(curbuf->b_p_cfu, &cfu_cb) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2552 return e_invalid_argument;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2553
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2554 set_buflocal_cfu_callback(curbuf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2555
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2556 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2557 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2558
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2559 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2560 * Copy the global 'completefunc' callback function to the buffer-local
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2561 * 'completefunc' callback for "buf".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2562 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2563 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2564 set_buflocal_cfu_callback(buf_T *buf UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2565 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2566 # ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2567 copy_global_to_buflocal_cb(&cfu_cb, &buf->b_cfu_cb);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2568 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2569 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2570
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2571 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2572 * Parse the 'omnifunc' option value and set the callback function.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2573 * Invoked when the 'omnifunc' option is set. The option value can be a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2574 * name of a function (string), or function(<name>) or funcref(<name>) or a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2575 * lambda expression.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2576 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2577 char *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2578 did_set_omnifunc(optset_T *args UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2579 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2580 if (option_set_callback_func(curbuf->b_p_ofu, &ofu_cb) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2581 return e_invalid_argument;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2582
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2583 set_buflocal_ofu_callback(curbuf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2584 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2585 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2586
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2587 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2588 * Copy the global 'omnifunc' callback function to the buffer-local 'omnifunc'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2589 * callback for "buf".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2590 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2591 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2592 set_buflocal_ofu_callback(buf_T *buf UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2593 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2594 # ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2595 copy_global_to_buflocal_cb(&ofu_cb, &buf->b_ofu_cb);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2596 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2597 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2598
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2599 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2600 * Parse the 'thesaurusfunc' option value and set the callback function.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2601 * Invoked when the 'thesaurusfunc' option is set. The option value can be a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2602 * name of a function (string), or function(<name>) or funcref(<name>) or a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2603 * lambda expression.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2604 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2605 char *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2606 did_set_thesaurusfunc(optset_T *args UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2607 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2608 int retval;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2609
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2610 if (*curbuf->b_p_tsrfu != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2611 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2612 // buffer-local option set
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2613 retval = option_set_callback_func(curbuf->b_p_tsrfu,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2614 &curbuf->b_tsrfu_cb);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2615 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2616 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2617 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2618 // global option set
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2619 retval = option_set_callback_func(p_tsrfu, &tsrfu_cb);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2620 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2621
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2622 return retval == FAIL ? e_invalid_argument : NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2623 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2624
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2625 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2626 * Mark the global 'completefunc' 'omnifunc' and 'thesaurusfunc' callbacks with
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2627 * "copyID" so that they are not garbage collected.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2628 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2629 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2630 set_ref_in_insexpand_funcs(int copyID)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2631 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2632 int abort = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2633
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2634 abort = set_ref_in_callback(&cfu_cb, copyID);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2635 abort = abort || set_ref_in_callback(&ofu_cb, copyID);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2636 abort = abort || set_ref_in_callback(&tsrfu_cb, copyID);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2637
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2638 return abort;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2639 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2640
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2641 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2642 * Get the user-defined completion function name for completion "type"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2643 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2644 static char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2645 get_complete_funcname(int type)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2646 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2647 switch (type)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2648 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2649 case CTRL_X_FUNCTION:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2650 return curbuf->b_p_cfu;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2651 case CTRL_X_OMNI:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2652 return curbuf->b_p_ofu;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2653 case CTRL_X_THESAURUS:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2654 return *curbuf->b_p_tsrfu == NUL ? p_tsrfu : curbuf->b_p_tsrfu;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2655 default:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2656 return (char_u *)"";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2657 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2658 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2659
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2660 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2661 * Get the callback to use for insert mode completion.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2662 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2663 static callback_T *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2664 get_insert_callback(int type)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2665 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2666 if (type == CTRL_X_FUNCTION)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2667 return &curbuf->b_cfu_cb;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2668 if (type == CTRL_X_OMNI)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2669 return &curbuf->b_ofu_cb;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2670 // CTRL_X_THESAURUS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2671 return (*curbuf->b_p_tsrfu != NUL) ? &curbuf->b_tsrfu_cb : &tsrfu_cb;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2672 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2673
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2674 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2675 * Execute user defined complete function 'completefunc', 'omnifunc' or
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2676 * 'thesaurusfunc', and get matches in "matches".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2677 * "type" is either CTRL_X_OMNI or CTRL_X_FUNCTION or CTRL_X_THESAURUS.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2678 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2679 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2680 expand_by_function(int type, char_u *base)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2681 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2682 list_T *matchlist = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2683 dict_T *matchdict = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2684 typval_T args[3];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2685 char_u *funcname;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2686 pos_T pos;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2687 callback_T *cb;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2688 typval_T rettv;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2689 int save_State = State;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2690 int retval;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2691
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2692 funcname = get_complete_funcname(type);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2693 if (*funcname == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2694 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2695
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2696 // Call 'completefunc' to obtain the list of matches.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2697 args[0].v_type = VAR_NUMBER;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2698 args[0].vval.v_number = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2699 args[1].v_type = VAR_STRING;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2700 args[1].vval.v_string = base != NULL ? base : (char_u *)"";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2701 args[2].v_type = VAR_UNKNOWN;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2702
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2703 pos = curwin->w_cursor;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2704 // Lock the text to avoid weird things from happening. Also disallow
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2705 // switching to another window, it should not be needed and may end up in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2706 // Insert mode in another buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2707 ++textlock;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2708
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2709 cb = get_insert_callback(type);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2710 retval = call_callback(cb, 0, &rettv, 2, args);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2711
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2712 // Call a function, which returns a list or dict.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2713 if (retval == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2714 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2715 switch (rettv.v_type)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2716 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2717 case VAR_LIST:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2718 matchlist = rettv.vval.v_list;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2719 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2720 case VAR_DICT:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2721 matchdict = rettv.vval.v_dict;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2722 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2723 case VAR_SPECIAL:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2724 if (rettv.vval.v_number == VVAL_NONE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2725 compl_opt_suppress_empty = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2726 // FALLTHROUGH
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2727 default:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2728 // TODO: Give error message?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2729 clear_tv(&rettv);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2730 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2731 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2732 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2733 --textlock;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2734
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2735 curwin->w_cursor = pos; // restore the cursor position
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2736 validate_cursor();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2737 if (!EQUAL_POS(curwin->w_cursor, pos))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2738 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2739 emsg(_(e_complete_function_deleted_text));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2740 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2741 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2742
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2743 if (matchlist != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2744 ins_compl_add_list(matchlist);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2745 else if (matchdict != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2746 ins_compl_add_dict(matchdict);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2747
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2748 theend:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2749 // Restore State, it might have been changed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2750 State = save_State;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2751
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2752 if (matchdict != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2753 dict_unref(matchdict);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2754 if (matchlist != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2755 list_unref(matchlist);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2756 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2757 #endif // FEAT_COMPL_FUNC
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2758
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2759 #if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2760 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2761 * Add a match to the list of matches from a typeval_T.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2762 * If the given string is already in the list of completions, then return
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2763 * NOTDONE, otherwise add it to the list and return OK. If there is an error,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2764 * maybe because alloc() returns NULL, then FAIL is returned.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2765 * When "fast" is TRUE use fast_breakcheck() instead of ui_breakcheck().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2766 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2767 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2768 ins_compl_add_tv(typval_T *tv, int dir, int fast)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2769 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2770 char_u *word;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2771 int dup = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2772 int empty = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2773 int flags = fast ? CP_FAST : 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2774 char_u *(cptext[CPT_COUNT]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2775 typval_T user_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2776 int status;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2777
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2778 user_data.v_type = VAR_UNKNOWN;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2779 if (tv->v_type == VAR_DICT && tv->vval.v_dict != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2780 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2781 word = dict_get_string(tv->vval.v_dict, "word", FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2782 cptext[CPT_ABBR] = dict_get_string(tv->vval.v_dict, "abbr", FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2783 cptext[CPT_MENU] = dict_get_string(tv->vval.v_dict, "menu", FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2784 cptext[CPT_KIND] = dict_get_string(tv->vval.v_dict, "kind", FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2785 cptext[CPT_INFO] = dict_get_string(tv->vval.v_dict, "info", FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2786 dict_get_tv(tv->vval.v_dict, "user_data", &user_data);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2787 if (dict_get_string(tv->vval.v_dict, "icase", FALSE) != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2788 && dict_get_number(tv->vval.v_dict, "icase"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2789 flags |= CP_ICASE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2790 if (dict_get_string(tv->vval.v_dict, "dup", FALSE) != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2791 dup = dict_get_number(tv->vval.v_dict, "dup");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2792 if (dict_get_string(tv->vval.v_dict, "empty", FALSE) != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2793 empty = dict_get_number(tv->vval.v_dict, "empty");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2794 if (dict_get_string(tv->vval.v_dict, "equal", FALSE) != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2795 && dict_get_number(tv->vval.v_dict, "equal"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2796 flags |= CP_EQUAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2797 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2798 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2799 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2800 word = tv_get_string_chk(tv);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2801 CLEAR_FIELD(cptext);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2802 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2803 if (word == NULL || (!empty && *word == NUL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2804 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2805 clear_tv(&user_data);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2806 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2807 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2808 status = ins_compl_add(word, -1, NULL, cptext, &user_data, dir, flags, dup);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2809 if (status != OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2810 clear_tv(&user_data);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2811 return status;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2812 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2813
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2814 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2815 * Add completions from a list.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2816 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2817 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2818 ins_compl_add_list(list_T *list)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2819 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2820 listitem_T *li;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2821 int dir = compl_direction;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2822
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2823 // Go through the List with matches and add each of them.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2824 CHECK_LIST_MATERIALIZE(list);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2825 FOR_ALL_LIST_ITEMS(list, li)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2826 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2827 if (ins_compl_add_tv(&li->li_tv, dir, TRUE) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2828 // if dir was BACKWARD then honor it just once
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2829 dir = FORWARD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2830 else if (did_emsg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2831 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2832 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2833 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2834
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2835 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2836 * Add completions from a dict.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2837 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2838 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2839 ins_compl_add_dict(dict_T *dict)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2840 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2841 dictitem_T *di_refresh;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2842 dictitem_T *di_words;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2843
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2844 // Check for optional "refresh" item.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2845 compl_opt_refresh_always = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2846 di_refresh = dict_find(dict, (char_u *)"refresh", 7);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2847 if (di_refresh != NULL && di_refresh->di_tv.v_type == VAR_STRING)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2848 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2849 char_u *v = di_refresh->di_tv.vval.v_string;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2850
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2851 if (v != NULL && STRCMP(v, (char_u *)"always") == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2852 compl_opt_refresh_always = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2853 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2854
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2855 // Add completions from a "words" list.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2856 di_words = dict_find(dict, (char_u *)"words", 5);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2857 if (di_words != NULL && di_words->di_tv.v_type == VAR_LIST)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2858 ins_compl_add_list(di_words->di_tv.vval.v_list);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2859 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2860
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2861 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2862 * Start completion for the complete() function.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2863 * "startcol" is where the matched text starts (1 is first column).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2864 * "list" is the list of matches.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2865 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2866 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2867 set_completion(colnr_T startcol, list_T *list)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2868 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2869 int save_w_wrow = curwin->w_wrow;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2870 int save_w_leftcol = curwin->w_leftcol;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2871 int flags = CP_ORIGINAL_TEXT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2872
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2873 // If already doing completions stop it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2874 if (ctrl_x_mode_not_default())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2875 ins_compl_prep(' ');
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2876 ins_compl_clear();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2877 ins_compl_free();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2878 compl_get_longest = compl_longest;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2879
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2880 compl_direction = FORWARD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2881 if (startcol > curwin->w_cursor.col)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2882 startcol = curwin->w_cursor.col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2883 compl_col = startcol;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2884 compl_length = (int)curwin->w_cursor.col - (int)startcol;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2885 // compl_pattern doesn't need to be set
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2886 compl_orig_text = vim_strnsave(ml_get_curline() + compl_col, compl_length);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2887 if (p_ic)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2888 flags |= CP_ICASE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2889 if (compl_orig_text == NULL || ins_compl_add(compl_orig_text,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2890 -1, NULL, NULL, NULL, 0,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2891 flags | CP_FAST, FALSE) != OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2892 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2893
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2894 ctrl_x_mode = CTRL_X_EVAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2895
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2896 ins_compl_add_list(list);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2897 compl_matches = ins_compl_make_cyclic();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2898 compl_started = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2899 compl_used_match = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2900 compl_cont_status = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2901
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2902 compl_curr_match = compl_first_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2903 int no_select = compl_no_select || compl_longest;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2904 if (compl_no_insert || no_select)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2905 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2906 ins_complete(K_DOWN, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2907 if (no_select)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2908 // Down/Up has no real effect.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2909 ins_complete(K_UP, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2910 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2911 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2912 ins_complete(Ctrl_N, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2913 compl_enter_selects = compl_no_insert;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2914
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2915 // Lazily show the popup menu, unless we got interrupted.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2916 if (!compl_interrupted)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2917 show_pum(save_w_wrow, save_w_leftcol);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2918 may_trigger_modechanged();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2919 out_flush();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2920 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2921
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2922 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2923 * "complete()" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2924 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2925 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2926 f_complete(typval_T *argvars, typval_T *rettv UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2927 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2928 int startcol;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2929
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2930 if (in_vim9script()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2931 && (check_for_number_arg(argvars, 0) == FAIL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2932 || check_for_list_arg(argvars, 1) == FAIL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2933 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2934
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2935 if ((State & MODE_INSERT) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2936 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2937 emsg(_(e_complete_can_only_be_used_in_insert_mode));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2938 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2939 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2940
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2941 // Check for undo allowed here, because if something was already inserted
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2942 // the line was already saved for undo and this check isn't done.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2943 if (!undo_allowed())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2944 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2945
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2946 if (check_for_nonnull_list_arg(argvars, 1) != FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2947 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2948 startcol = (int)tv_get_number_chk(&argvars[0], NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2949 if (startcol > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2950 set_completion(startcol - 1, argvars[1].vval.v_list);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2951 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2952 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2953
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2954 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2955 * "complete_add()" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2956 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2957 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2958 f_complete_add(typval_T *argvars, typval_T *rettv)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2959 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2960 if (in_vim9script() && check_for_string_or_dict_arg(argvars, 0) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2961 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2962
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2963 rettv->vval.v_number = ins_compl_add_tv(&argvars[0], 0, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2964 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2965
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2966 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2967 * "complete_check()" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2968 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2969 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2970 f_complete_check(typval_T *argvars UNUSED, typval_T *rettv)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2971 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2972 int save_RedrawingDisabled = RedrawingDisabled;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2973 RedrawingDisabled = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2974
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2975 ins_compl_check_keys(0, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2976 rettv->vval.v_number = ins_compl_interrupted();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2977
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2978 RedrawingDisabled = save_RedrawingDisabled;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2979 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2980
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2981 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2982 * Return Insert completion mode name string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2983 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2984 static char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2985 ins_compl_mode(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2986 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2987 if (ctrl_x_mode_not_defined_yet() || ctrl_x_mode_scroll() || compl_started)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2988 return (char_u *)ctrl_x_mode_names[ctrl_x_mode & ~CTRL_X_WANT_IDENT];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2989
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2990 return (char_u *)"";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2991 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2992
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2993 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2994 * Assign the sequence number to all the completion matches which don't have
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2995 * one assigned yet.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2996 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2997 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2998 ins_compl_update_sequence_numbers(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
2999 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3000 int number = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3001 compl_T *match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3002
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3003 if (compl_dir_forward())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3004 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3005 // Search backwards for the first valid (!= -1) number.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3006 // This should normally succeed already at the first loop
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3007 // cycle, so it's fast!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3008 for (match = compl_curr_match->cp_prev; match != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3009 && !is_first_match(match); match = match->cp_prev)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3010 if (match->cp_number != -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3011 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3012 number = match->cp_number;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3013 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3014 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3015 if (match != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3016 // go up and assign all numbers which are not assigned yet
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3017 for (match = match->cp_next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3018 match != NULL && match->cp_number == -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3019 match = match->cp_next)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3020 match->cp_number = ++number;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3021 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3022 else // BACKWARD
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3023 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3024 // Search forwards (upwards) for the first valid (!= -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3025 // number. This should normally succeed already at the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3026 // first loop cycle, so it's fast!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3027 for (match = compl_curr_match->cp_next; match != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3028 && !is_first_match(match); match = match->cp_next)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3029 if (match->cp_number != -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3030 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3031 number = match->cp_number;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3032 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3033 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3034 if (match != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3035 // go down and assign all numbers which are not assigned yet
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3036 for (match = match->cp_prev; match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3037 && match->cp_number == -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3038 match = match->cp_prev)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3039 match->cp_number = ++number;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3040 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3041 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3042
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3043 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3044 * Get complete information
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3045 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3046 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3047 get_complete_info(list_T *what_list, dict_T *retdict)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3048 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3049 int ret = OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3050 listitem_T *item;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3051 #define CI_WHAT_MODE 0x01
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3052 #define CI_WHAT_PUM_VISIBLE 0x02
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3053 #define CI_WHAT_ITEMS 0x04
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3054 #define CI_WHAT_SELECTED 0x08
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3055 #define CI_WHAT_INSERTED 0x10
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3056 #define CI_WHAT_ALL 0xff
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3057 int what_flag;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3058
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3059 if (what_list == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3060 what_flag = CI_WHAT_ALL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3061 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3062 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3063 what_flag = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3064 CHECK_LIST_MATERIALIZE(what_list);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3065 FOR_ALL_LIST_ITEMS(what_list, item)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3066 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3067 char_u *what = tv_get_string(&item->li_tv);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3068
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3069 if (STRCMP(what, "mode") == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3070 what_flag |= CI_WHAT_MODE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3071 else if (STRCMP(what, "pum_visible") == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3072 what_flag |= CI_WHAT_PUM_VISIBLE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3073 else if (STRCMP(what, "items") == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3074 what_flag |= CI_WHAT_ITEMS;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3075 else if (STRCMP(what, "selected") == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3076 what_flag |= CI_WHAT_SELECTED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3077 else if (STRCMP(what, "inserted") == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3078 what_flag |= CI_WHAT_INSERTED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3079 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3080 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3081
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3082 if (ret == OK && (what_flag & CI_WHAT_MODE))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3083 ret = dict_add_string(retdict, "mode", ins_compl_mode());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3084
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3085 if (ret == OK && (what_flag & CI_WHAT_PUM_VISIBLE))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3086 ret = dict_add_number(retdict, "pum_visible", pum_visible());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3087
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3088 if (ret == OK && (what_flag & CI_WHAT_ITEMS))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3089 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3090 list_T *li;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3091 dict_T *di;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3092 compl_T *match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3093
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3094 li = list_alloc();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3095 if (li == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3096 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3097 ret = dict_add_list(retdict, "items", li);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3098 if (ret == OK && compl_first_match != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3099 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3100 match = compl_first_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3101 do
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3102 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3103 if (!match_at_original_text(match))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3104 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3105 di = dict_alloc();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3106 if (di == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3107 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3108 ret = list_append_dict(li, di);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3109 if (ret != OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3110 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3111 dict_add_string(di, "word", match->cp_str);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3112 dict_add_string(di, "abbr", match->cp_text[CPT_ABBR]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3113 dict_add_string(di, "menu", match->cp_text[CPT_MENU]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3114 dict_add_string(di, "kind", match->cp_text[CPT_KIND]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3115 dict_add_string(di, "info", match->cp_text[CPT_INFO]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3116 if (match->cp_user_data.v_type == VAR_UNKNOWN)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3117 // Add an empty string for backwards compatibility
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3118 dict_add_string(di, "user_data", (char_u *)"");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3119 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3120 dict_add_tv(di, "user_data", &match->cp_user_data);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3121 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3122 match = match->cp_next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3123 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3124 while (match != NULL && !is_first_match(match));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3125 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3126 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3127
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3128 if (ret == OK && (what_flag & CI_WHAT_SELECTED))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3129 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3130 if (compl_curr_match != NULL && compl_curr_match->cp_number == -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3131 ins_compl_update_sequence_numbers();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3132 ret = dict_add_number(retdict, "selected", compl_curr_match != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3133 ? compl_curr_match->cp_number - 1 : -1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3134 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3135
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3136 if (ret == OK && (what_flag & CI_WHAT_INSERTED))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3137 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3138 // TODO
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3139 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3140 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3141
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3142 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3143 * "complete_info()" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3144 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3145 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3146 f_complete_info(typval_T *argvars, typval_T *rettv)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3147 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3148 list_T *what_list = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3149
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3150 if (rettv_dict_alloc(rettv) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3151 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3152
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3153 if (in_vim9script() && check_for_opt_list_arg(argvars, 0) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3154 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3155
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3156 if (argvars[0].v_type != VAR_UNKNOWN)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3157 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3158 if (check_for_list_arg(argvars, 0) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3159 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3160 what_list = argvars[0].vval.v_list;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3161 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3162 get_complete_info(what_list, rettv->vval.v_dict);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3163 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3164 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3165
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3166 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3167 * Returns TRUE when using a user-defined function for thesaurus completion.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3168 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3169 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3170 thesaurus_func_complete(int type UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3171 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3172 #ifdef FEAT_COMPL_FUNC
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3173 return type == CTRL_X_THESAURUS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3174 && (*curbuf->b_p_tsrfu != NUL || *p_tsrfu != NUL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3175 #else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3176 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3177 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3178 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3179
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3180 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3181 * Return value of process_next_cpt_value()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3182 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3183 enum
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3184 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3185 INS_COMPL_CPT_OK = 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3186 INS_COMPL_CPT_CONT,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3187 INS_COMPL_CPT_END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3188 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3189
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3190 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3191 * state information used for getting the next set of insert completion
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3192 * matches.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3193 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3194 typedef struct
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3195 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3196 char_u *e_cpt_copy; // copy of 'complete'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3197 char_u *e_cpt; // current entry in "e_cpt_copy"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3198 buf_T *ins_buf; // buffer being scanned
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3199 pos_T *cur_match_pos; // current match position
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3200 pos_T prev_match_pos; // previous match position
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3201 int set_match_pos; // save first_match_pos/last_match_pos
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3202 pos_T first_match_pos; // first match position
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3203 pos_T last_match_pos; // last match position
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3204 int found_all; // found all matches of a certain type.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3205 char_u *dict; // dictionary file to search
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3206 int dict_f; // "dict" is an exact file name or not
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3207 } ins_compl_next_state_T;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3208
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3209 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3210 * Process the next 'complete' option value in st->e_cpt.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3211 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3212 * If successful, the arguments are set as below:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3213 * st->cpt - pointer to the next option value in "st->cpt"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3214 * compl_type_arg - type of insert mode completion to use
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3215 * st->found_all - all matches of this type are found
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3216 * st->ins_buf - search for completions in this buffer
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3217 * st->first_match_pos - position of the first completion match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3218 * st->last_match_pos - position of the last completion match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3219 * st->set_match_pos - TRUE if the first match position should be saved to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3220 * avoid loops after the search wraps around.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3221 * st->dict - name of the dictionary or thesaurus file to search
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3222 * st->dict_f - flag specifying whether "dict" is an exact file name or not
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3223 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3224 * Returns INS_COMPL_CPT_OK if the next value is processed successfully.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3225 * Returns INS_COMPL_CPT_CONT to skip the current completion source matching
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3226 * the "st->e_cpt" option value and process the next matching source.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3227 * Returns INS_COMPL_CPT_END if all the values in "st->e_cpt" are processed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3228 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3229 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3230 process_next_cpt_value(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3231 ins_compl_next_state_T *st,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3232 int *compl_type_arg,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3233 pos_T *start_match_pos)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3234 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3235 int compl_type = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3236 int status = INS_COMPL_CPT_OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3237
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3238 st->found_all = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3239
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3240 while (*st->e_cpt == ',' || *st->e_cpt == ' ')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3241 st->e_cpt++;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3242
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3243 if (*st->e_cpt == '.' && !curbuf->b_scanned)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3244 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3245 st->ins_buf = curbuf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3246 st->first_match_pos = *start_match_pos;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3247 // Move the cursor back one character so that ^N can match the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3248 // word immediately after the cursor.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3249 if (ctrl_x_mode_normal() && dec(&st->first_match_pos) < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3250 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3251 // Move the cursor to after the last character in the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3252 // buffer, so that word at start of buffer is found
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3253 // correctly.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3254 st->first_match_pos.lnum = st->ins_buf->b_ml.ml_line_count;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3255 st->first_match_pos.col =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3256 (colnr_T)STRLEN(ml_get(st->first_match_pos.lnum));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3257 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3258 st->last_match_pos = st->first_match_pos;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3259 compl_type = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3260
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3261 // Remember the first match so that the loop stops when we
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3262 // wrap and come back there a second time.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3263 st->set_match_pos = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3264 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3265 else if (vim_strchr((char_u *)"buwU", *st->e_cpt) != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3266 && (st->ins_buf = ins_compl_next_buf(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3267 st->ins_buf, *st->e_cpt)) != curbuf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3268 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3269 // Scan a buffer, but not the current one.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3270 if (st->ins_buf->b_ml.ml_mfp != NULL) // loaded buffer
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3271 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3272 compl_started = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3273 st->first_match_pos.col = st->last_match_pos.col = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3274 st->first_match_pos.lnum = st->ins_buf->b_ml.ml_line_count + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3275 st->last_match_pos.lnum = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3276 compl_type = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3277 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3278 else // unloaded buffer, scan like dictionary
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3279 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3280 st->found_all = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3281 if (st->ins_buf->b_fname == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3282 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3283 status = INS_COMPL_CPT_CONT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3284 goto done;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3285 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3286 compl_type = CTRL_X_DICTIONARY;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3287 st->dict = st->ins_buf->b_fname;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3288 st->dict_f = DICT_EXACT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3289 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3290 if (!shortmess(SHM_COMPLETIONSCAN))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3291 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3292 msg_hist_off = TRUE; // reset in msg_trunc_attr()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3293 vim_snprintf((char *)IObuff, IOSIZE, _("Scanning: %s"),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3294 st->ins_buf->b_fname == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3295 ? buf_spname(st->ins_buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3296 : st->ins_buf->b_sfname == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3297 ? st->ins_buf->b_fname
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3298 : st->ins_buf->b_sfname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3299 (void)msg_trunc_attr((char *)IObuff, TRUE, HL_ATTR(HLF_R));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3300 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3301 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3302 else if (*st->e_cpt == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3303 status = INS_COMPL_CPT_END;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3304 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3305 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3306 if (ctrl_x_mode_line_or_eval())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3307 compl_type = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3308 else if (*st->e_cpt == 'k' || *st->e_cpt == 's')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3309 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3310 if (*st->e_cpt == 'k')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3311 compl_type = CTRL_X_DICTIONARY;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3312 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3313 compl_type = CTRL_X_THESAURUS;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3314 if (*++st->e_cpt != ',' && *st->e_cpt != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3315 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3316 st->dict = st->e_cpt;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3317 st->dict_f = DICT_FIRST;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3318 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3319 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3320 #ifdef FEAT_FIND_ID
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3321 else if (*st->e_cpt == 'i')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3322 compl_type = CTRL_X_PATH_PATTERNS;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3323 else if (*st->e_cpt == 'd')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3324 compl_type = CTRL_X_PATH_DEFINES;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3325 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3326 else if (*st->e_cpt == ']' || *st->e_cpt == 't')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3327 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3328 compl_type = CTRL_X_TAGS;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3329 if (!shortmess(SHM_COMPLETIONSCAN))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3330 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3331 msg_hist_off = TRUE; // reset in msg_trunc_attr()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3332 vim_snprintf((char *)IObuff, IOSIZE, _("Scanning tags."));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3333 (void)msg_trunc_attr((char *)IObuff, TRUE, HL_ATTR(HLF_R));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3334 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3335 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3336 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3337 compl_type = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3338
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3339 // in any case e_cpt is advanced to the next entry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3340 (void)copy_option_part(&st->e_cpt, IObuff, IOSIZE, ",");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3341
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3342 st->found_all = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3343 if (compl_type == -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3344 status = INS_COMPL_CPT_CONT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3345 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3346
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3347 done:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3348 *compl_type_arg = compl_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3349 return status;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3350 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3351
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3352 #ifdef FEAT_FIND_ID
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3353 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3354 * Get the next set of identifiers or defines matching "compl_pattern" in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3355 * included files.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3356 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3357 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3358 get_next_include_file_completion(int compl_type)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3359 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3360 find_pattern_in_path(compl_pattern, compl_direction,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3361 (int)STRLEN(compl_pattern), FALSE, FALSE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3362 (compl_type == CTRL_X_PATH_DEFINES
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3363 && !(compl_cont_status & CONT_SOL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3364 ? FIND_DEFINE : FIND_ANY, 1L, ACTION_EXPAND,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3365 (linenr_T)1, (linenr_T)MAXLNUM);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3366 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3367 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3368
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3369 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3370 * Get the next set of words matching "compl_pattern" in dictionary or
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3371 * thesaurus files.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3372 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3373 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3374 get_next_dict_tsr_completion(int compl_type, char_u *dict, int dict_f)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3375 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3376 #ifdef FEAT_COMPL_FUNC
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3377 if (thesaurus_func_complete(compl_type))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3378 expand_by_function(compl_type, compl_pattern);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3379 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3380 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3381 ins_compl_dictionaries(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3382 dict != NULL ? dict
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3383 : (compl_type == CTRL_X_THESAURUS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3384 ? (*curbuf->b_p_tsr == NUL ? p_tsr : curbuf->b_p_tsr)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3385 : (*curbuf->b_p_dict == NUL ? p_dict : curbuf->b_p_dict)),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3386 compl_pattern,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3387 dict != NULL ? dict_f : 0,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3388 compl_type == CTRL_X_THESAURUS);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3389 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3390
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3391 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3392 * Get the next set of tag names matching "compl_pattern".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3393 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3394 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3395 get_next_tag_completion(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3396 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3397 int save_p_ic;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3398 char_u **matches;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3399 int num_matches;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3400
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3401 // set p_ic according to p_ic, p_scs and pat for find_tags().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3402 save_p_ic = p_ic;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3403 p_ic = ignorecase(compl_pattern);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3404
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3405 // Find up to TAG_MANY matches. Avoids that an enormous number
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3406 // of matches is found when compl_pattern is empty
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3407 g_tag_at_cursor = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3408 if (find_tags(compl_pattern, &num_matches, &matches,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3409 TAG_REGEXP | TAG_NAMES | TAG_NOIC | TAG_INS_COMP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3410 | (ctrl_x_mode_not_default() ? TAG_VERBOSE : 0),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3411 TAG_MANY, curbuf->b_ffname) == OK && num_matches > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3412 ins_compl_add_matches(num_matches, matches, p_ic);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3413 g_tag_at_cursor = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3414 p_ic = save_p_ic;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3415 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3416
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3417 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3418 * Get the next set of filename matching "compl_pattern".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3419 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3420 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3421 get_next_filename_completion(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3422 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3423 char_u **matches;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3424 int num_matches;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3425
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3426 if (expand_wildcards(1, &compl_pattern, &num_matches, &matches,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3427 EW_FILE|EW_DIR|EW_ADDSLASH|EW_SILENT) != OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3428 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3429
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3430 // May change home directory back to "~".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3431 tilde_replace(compl_pattern, num_matches, matches);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3432 #ifdef BACKSLASH_IN_FILENAME
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3433 if (curbuf->b_p_csl[0] != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3434 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3435 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3436
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3437 for (i = 0; i < num_matches; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3438 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3439 char_u *ptr = matches[i];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3440
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3441 while (*ptr != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3442 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3443 if (curbuf->b_p_csl[0] == 's' && *ptr == '\\')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3444 *ptr = '/';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3445 else if (curbuf->b_p_csl[0] == 'b' && *ptr == '/')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3446 *ptr = '\\';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3447 ptr += (*mb_ptr2len)(ptr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3448 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3449 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3450 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3451 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3452 ins_compl_add_matches(num_matches, matches, p_fic || p_wic);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3453 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3454
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3455 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3456 * Get the next set of command-line completions matching "compl_pattern".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3457 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3458 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3459 get_next_cmdline_completion(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3460 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3461 char_u **matches;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3462 int num_matches;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3463
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3464 if (expand_cmdline(&compl_xp, compl_pattern,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3465 (int)STRLEN(compl_pattern),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3466 &num_matches, &matches) == EXPAND_OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3467 ins_compl_add_matches(num_matches, matches, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3468 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3469
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3470 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3471 * Get the next set of spell suggestions matching "compl_pattern".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3472 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3473 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3474 get_next_spell_completion(linenr_T lnum UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3475 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3476 #ifdef FEAT_SPELL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3477 char_u **matches;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3478 int num_matches;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3479
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3480 num_matches = expand_spelling(lnum, compl_pattern, &matches);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3481 if (num_matches > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3482 ins_compl_add_matches(num_matches, matches, p_ic);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3483 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3484 vim_free(matches);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3485 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3486 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3487
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3488 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3489 * Return the next word or line from buffer "ins_buf" at position
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3490 * "cur_match_pos" for completion. The length of the match is set in "len".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3491 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3492 static char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3493 ins_compl_get_next_word_or_line(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3494 buf_T *ins_buf, // buffer being scanned
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3495 pos_T *cur_match_pos, // current match position
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3496 int *match_len,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3497 int *cont_s_ipos) // next ^X<> will set initial_pos
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3498 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3499 char_u *ptr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3500 int len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3501
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3502 *match_len = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3503 ptr = ml_get_buf(ins_buf, cur_match_pos->lnum, FALSE) +
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3504 cur_match_pos->col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3505 if (ctrl_x_mode_line_or_eval())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3506 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3507 if (compl_status_adding())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3508 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3509 if (cur_match_pos->lnum >= ins_buf->b_ml.ml_line_count)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3510 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3511 ptr = ml_get_buf(ins_buf, cur_match_pos->lnum + 1, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3512 if (!p_paste)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3513 ptr = skipwhite(ptr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3514 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3515 len = (int)STRLEN(ptr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3516 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3517 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3518 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3519 char_u *tmp_ptr = ptr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3520
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3521 if (compl_status_adding() && compl_length <= (int)STRLEN(tmp_ptr))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3522 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3523 tmp_ptr += compl_length;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3524 // Skip if already inside a word.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3525 if (vim_iswordp(tmp_ptr))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3526 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3527 // Find start of next word.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3528 tmp_ptr = find_word_start(tmp_ptr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3529 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3530 // Find end of this word.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3531 tmp_ptr = find_word_end(tmp_ptr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3532 len = (int)(tmp_ptr - ptr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3533
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3534 if (compl_status_adding() && len == compl_length)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3535 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3536 if (cur_match_pos->lnum < ins_buf->b_ml.ml_line_count)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3537 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3538 // Try next line, if any. the new word will be
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3539 // "join" as if the normal command "J" was used.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3540 // IOSIZE is always greater than
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3541 // compl_length, so the next STRNCPY always
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3542 // works -- Acevedo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3543 STRNCPY(IObuff, ptr, len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3544 ptr = ml_get_buf(ins_buf, cur_match_pos->lnum + 1, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3545 tmp_ptr = ptr = skipwhite(ptr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3546 // Find start of next word.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3547 tmp_ptr = find_word_start(tmp_ptr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3548 // Find end of next word.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3549 tmp_ptr = find_word_end(tmp_ptr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3550 if (tmp_ptr > ptr)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3551 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3552 if (*ptr != ')' && IObuff[len - 1] != TAB)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3553 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3554 if (IObuff[len - 1] != ' ')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3555 IObuff[len++] = ' ';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3556 // IObuf =~ "\k.* ", thus len >= 2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3557 if (p_js
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3558 && (IObuff[len - 2] == '.'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3559 || (vim_strchr(p_cpo, CPO_JOINSP)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3560 == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3561 && (IObuff[len - 2] == '?'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3562 || IObuff[len - 2] == '!'))))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3563 IObuff[len++] = ' ';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3564 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3565 // copy as much as possible of the new word
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3566 if (tmp_ptr - ptr >= IOSIZE - len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3567 tmp_ptr = ptr + IOSIZE - len - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3568 STRNCPY(IObuff + len, ptr, tmp_ptr - ptr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3569 len += (int)(tmp_ptr - ptr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3570 *cont_s_ipos = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3571 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3572 IObuff[len] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3573 ptr = IObuff;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3574 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3575 if (len == compl_length)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3576 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3577 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3578 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3579
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3580 *match_len = len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3581 return ptr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3582 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3583
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3584 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3585 * Get the next set of words matching "compl_pattern" for default completion(s)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3586 * (normal ^P/^N and ^X^L).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3587 * Search for "compl_pattern" in the buffer "st->ins_buf" starting from the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3588 * position "st->start_pos" in the "compl_direction" direction. If
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3589 * "st->set_match_pos" is TRUE, then set the "st->first_match_pos" and
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3590 * "st->last_match_pos".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3591 * Returns OK if a new next match is found, otherwise returns FAIL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3592 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3593 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3594 get_next_default_completion(ins_compl_next_state_T *st, pos_T *start_pos)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3595 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3596 int found_new_match = FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3597 int save_p_scs;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3598 int save_p_ws;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3599 int looped_around = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3600 char_u *ptr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3601 int len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3602
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3603 // If 'infercase' is set, don't use 'smartcase' here
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3604 save_p_scs = p_scs;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3605 if (st->ins_buf->b_p_inf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3606 p_scs = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3607
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3608 // Buffers other than curbuf are scanned from the beginning or the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3609 // end but never from the middle, thus setting nowrapscan in this
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3610 // buffer is a good idea, on the other hand, we always set
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3611 // wrapscan for curbuf to avoid missing matches -- Acevedo,Webb
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3612 save_p_ws = p_ws;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3613 if (st->ins_buf != curbuf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3614 p_ws = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3615 else if (*st->e_cpt == '.')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3616 p_ws = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3617 looped_around = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3618 for (;;)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3619 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3620 int cont_s_ipos = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3621
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3622 ++msg_silent; // Don't want messages for wrapscan.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3623
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3624 // ctrl_x_mode_line_or_eval() || word-wise search that
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3625 // has added a word that was at the beginning of the line
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3626 if (ctrl_x_mode_line_or_eval() || (compl_cont_status & CONT_SOL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3627 found_new_match = search_for_exact_line(st->ins_buf,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3628 st->cur_match_pos, compl_direction, compl_pattern);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3629 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3630 found_new_match = searchit(NULL, st->ins_buf, st->cur_match_pos,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3631 NULL, compl_direction, compl_pattern, 1L,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3632 SEARCH_KEEP + SEARCH_NFMSG, RE_LAST, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3633 --msg_silent;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3634 if (!compl_started || st->set_match_pos)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3635 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3636 // set "compl_started" even on fail
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3637 compl_started = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3638 st->first_match_pos = *st->cur_match_pos;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3639 st->last_match_pos = *st->cur_match_pos;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3640 st->set_match_pos = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3641 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3642 else if (st->first_match_pos.lnum == st->last_match_pos.lnum
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3643 && st->first_match_pos.col == st->last_match_pos.col)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3644 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3645 found_new_match = FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3646 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3647 else if (compl_dir_forward()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3648 && (st->prev_match_pos.lnum > st->cur_match_pos->lnum
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3649 || (st->prev_match_pos.lnum == st->cur_match_pos->lnum
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3650 && st->prev_match_pos.col >= st->cur_match_pos->col)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3651 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3652 if (looped_around)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3653 found_new_match = FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3654 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3655 looped_around = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3656 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3657 else if (!compl_dir_forward()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3658 && (st->prev_match_pos.lnum < st->cur_match_pos->lnum
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3659 || (st->prev_match_pos.lnum == st->cur_match_pos->lnum
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3660 && st->prev_match_pos.col <= st->cur_match_pos->col)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3661 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3662 if (looped_around)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3663 found_new_match = FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3664 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3665 looped_around = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3666 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3667 st->prev_match_pos = *st->cur_match_pos;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3668 if (found_new_match == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3669 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3670
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3671 // when ADDING, the text before the cursor matches, skip it
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3672 if (compl_status_adding() && st->ins_buf == curbuf
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3673 && start_pos->lnum == st->cur_match_pos->lnum
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3674 && start_pos->col == st->cur_match_pos->col)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3675 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3676
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3677 ptr = ins_compl_get_next_word_or_line(st->ins_buf, st->cur_match_pos,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3678 &len, &cont_s_ipos);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3679 if (ptr == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3680 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3681
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3682 if (ins_compl_add_infercase(ptr, len, p_ic,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3683 st->ins_buf == curbuf ? NULL : st->ins_buf->b_sfname,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3684 0, cont_s_ipos) != NOTDONE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3685 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3686 found_new_match = OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3687 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3688 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3689 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3690 p_scs = save_p_scs;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3691 p_ws = save_p_ws;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3692
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3693 return found_new_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3694 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3695
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3696 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3697 * get the next set of completion matches for "type".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3698 * Returns TRUE if a new match is found. Otherwise returns FALSE.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3699 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3700 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3701 get_next_completion_match(int type, ins_compl_next_state_T *st, pos_T *ini)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3702 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3703 int found_new_match = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3704
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3705 switch (type)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3706 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3707 case -1:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3708 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3709 #ifdef FEAT_FIND_ID
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3710 case CTRL_X_PATH_PATTERNS:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3711 case CTRL_X_PATH_DEFINES:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3712 get_next_include_file_completion(type);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3713 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3714 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3715
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3716 case CTRL_X_DICTIONARY:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3717 case CTRL_X_THESAURUS:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3718 get_next_dict_tsr_completion(type, st->dict, st->dict_f);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3719 st->dict = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3720 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3721
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3722 case CTRL_X_TAGS:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3723 get_next_tag_completion();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3724 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3725
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3726 case CTRL_X_FILES:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3727 get_next_filename_completion();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3728 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3729
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3730 case CTRL_X_CMDLINE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3731 case CTRL_X_CMDLINE_CTRL_X:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3732 get_next_cmdline_completion();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3733 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3734
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3735 #ifdef FEAT_COMPL_FUNC
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3736 case CTRL_X_FUNCTION:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3737 case CTRL_X_OMNI:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3738 expand_by_function(type, compl_pattern);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3739 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3740 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3741
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3742 case CTRL_X_SPELL:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3743 get_next_spell_completion(st->first_match_pos.lnum);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3744 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3745
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3746 default: // normal ^P/^N and ^X^L
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3747 found_new_match = get_next_default_completion(st, ini);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3748 if (found_new_match == FAIL && st->ins_buf == curbuf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3749 st->found_all = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3750 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3751
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3752 // check if compl_curr_match has changed, (e.g. other type of
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3753 // expansion added something)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3754 if (type != 0 && compl_curr_match != compl_old_match)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3755 found_new_match = OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3756
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3757 return found_new_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3758 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3759
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3760 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3761 * Get the next expansion(s), using "compl_pattern".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3762 * The search starts at position "ini" in curbuf and in the direction
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3763 * compl_direction.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3764 * When "compl_started" is FALSE start at that position, otherwise continue
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3765 * where we stopped searching before.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3766 * This may return before finding all the matches.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3767 * Return the total number of matches or -1 if still unknown -- Acevedo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3768 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3769 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3770 ins_compl_get_exp(pos_T *ini)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3771 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3772 static ins_compl_next_state_T st;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3773 static int st_cleared = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3774 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3775 int found_new_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3776 int type = ctrl_x_mode;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3777
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3778 if (!compl_started)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3779 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3780 buf_T *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3781
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3782 FOR_ALL_BUFFERS(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3783 buf->b_scanned = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3784 if (!st_cleared)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3785 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3786 CLEAR_FIELD(st);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3787 st_cleared = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3788 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3789 st.found_all = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3790 st.ins_buf = curbuf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3791 vim_free(st.e_cpt_copy);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3792 // Make a copy of 'complete', if case the buffer is wiped out.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3793 st.e_cpt_copy = vim_strsave((compl_cont_status & CONT_LOCAL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3794 ? (char_u *)"." : curbuf->b_p_cpt);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3795 st.e_cpt = st.e_cpt_copy == NULL ? (char_u *)"" : st.e_cpt_copy;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3796 st.last_match_pos = st.first_match_pos = *ini;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3797 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3798 else if (st.ins_buf != curbuf && !buf_valid(st.ins_buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3799 st.ins_buf = curbuf; // In case the buffer was wiped out.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3800
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3801 compl_old_match = compl_curr_match; // remember the last current match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3802 st.cur_match_pos = (compl_dir_forward())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3803 ? &st.last_match_pos : &st.first_match_pos;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3804
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3805 // For ^N/^P loop over all the flags/windows/buffers in 'complete'.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3806 for (;;)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3807 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3808 found_new_match = FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3809 st.set_match_pos = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3810
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3811 // For ^N/^P pick a new entry from e_cpt if compl_started is off,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3812 // or if found_all says this entry is done. For ^X^L only use the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3813 // entries from 'complete' that look in loaded buffers.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3814 if ((ctrl_x_mode_normal() || ctrl_x_mode_line_or_eval())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3815 && (!compl_started || st.found_all))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3816 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3817 int status = process_next_cpt_value(&st, &type, ini);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3818
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3819 if (status == INS_COMPL_CPT_END)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3820 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3821 if (status == INS_COMPL_CPT_CONT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3822 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3823 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3824
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3825 // If complete() was called then compl_pattern has been reset. The
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3826 // following won't work then, bail out.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3827 if (compl_pattern == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3828 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3829
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3830 // get the next set of completion matches
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3831 found_new_match = get_next_completion_match(type, &st, ini);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3832
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3833 // break the loop for specialized modes (use 'complete' just for the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3834 // generic ctrl_x_mode == CTRL_X_NORMAL) or when we've found a new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3835 // match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3836 if ((ctrl_x_mode_not_default() && !ctrl_x_mode_line_or_eval())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3837 || found_new_match != FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3838 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3839 if (got_int)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3840 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3841 // Fill the popup menu as soon as possible.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3842 if (type != -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3843 ins_compl_check_keys(0, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3844
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3845 if ((ctrl_x_mode_not_default()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3846 && !ctrl_x_mode_line_or_eval()) || compl_interrupted)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3847 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3848 compl_started = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3849 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3850 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3851 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3852 // Mark a buffer scanned when it has been scanned completely
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3853 if (type == 0 || type == CTRL_X_PATH_PATTERNS)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3854 st.ins_buf->b_scanned = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3855
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3856 compl_started = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3857 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3858 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3859 compl_started = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3860
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3861 if ((ctrl_x_mode_normal() || ctrl_x_mode_line_or_eval())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3862 && *st.e_cpt == NUL) // Got to end of 'complete'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3863 found_new_match = FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3864
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3865 i = -1; // total of matches, unknown
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3866 if (found_new_match == FAIL || (ctrl_x_mode_not_default()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3867 && !ctrl_x_mode_line_or_eval()))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3868 i = ins_compl_make_cyclic();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3869
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3870 if (compl_old_match != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3871 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3872 // If several matches were added (FORWARD) or the search failed and has
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3873 // just been made cyclic then we have to move compl_curr_match to the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3874 // next or previous entry (if any) -- Acevedo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3875 compl_curr_match = compl_dir_forward() ? compl_old_match->cp_next
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3876 : compl_old_match->cp_prev;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3877 if (compl_curr_match == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3878 compl_curr_match = compl_old_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3879 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3880 may_trigger_modechanged();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3881
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3882 return i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3883 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3884
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3885 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3886 * Update "compl_shown_match" to the actually shown match, it may differ when
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3887 * "compl_leader" is used to omit some of the matches.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3888 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3889 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3890 ins_compl_update_shown_match(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3891 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3892 while (!ins_compl_equal(compl_shown_match,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3893 compl_leader, (int)STRLEN(compl_leader))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3894 && compl_shown_match->cp_next != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3895 && !is_first_match(compl_shown_match->cp_next))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3896 compl_shown_match = compl_shown_match->cp_next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3897
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3898 // If we didn't find it searching forward, and compl_shows_dir is
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3899 // backward, find the last match.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3900 if (compl_shows_dir_backward()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3901 && !ins_compl_equal(compl_shown_match,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3902 compl_leader, (int)STRLEN(compl_leader))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3903 && (compl_shown_match->cp_next == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3904 || is_first_match(compl_shown_match->cp_next)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3905 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3906 while (!ins_compl_equal(compl_shown_match,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3907 compl_leader, (int)STRLEN(compl_leader))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3908 && compl_shown_match->cp_prev != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3909 && !is_first_match(compl_shown_match->cp_prev))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3910 compl_shown_match = compl_shown_match->cp_prev;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3911 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3912 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3913
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3914 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3915 * Delete the old text being completed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3916 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3917 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3918 ins_compl_delete(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3919 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3920 int col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3921
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3922 // In insert mode: Delete the typed part.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3923 // In replace mode: Put the old characters back, if any.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3924 col = compl_col + (compl_status_adding() ? compl_length : 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3925 if ((int)curwin->w_cursor.col > col)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3926 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3927 if (stop_arrow() == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3928 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3929 backspace_until_column(col);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3930 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3931
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3932 // TODO: is this sufficient for redrawing? Redrawing everything causes
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3933 // flicker, thus we can't do that.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3934 changed_cline_bef_curs();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3935 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3936 // clear v:completed_item
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3937 set_vim_var_dict(VV_COMPLETED_ITEM, dict_alloc_lock(VAR_FIXED));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3938 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3939 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3940
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3941 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3942 * Insert the new text being completed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3943 * "in_compl_func" is TRUE when called from complete_check().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3944 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3945 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3946 ins_compl_insert(int in_compl_func)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3947 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3948 int compl_len = get_compl_len();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3949
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3950 // Make sure we don't go over the end of the string, this can happen with
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3951 // illegal bytes.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3952 if (compl_len < (int)STRLEN(compl_shown_match->cp_str))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3953 ins_bytes(compl_shown_match->cp_str + compl_len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3954 if (match_at_original_text(compl_shown_match))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3955 compl_used_match = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3956 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3957 compl_used_match = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3958 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3959 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3960 dict_T *dict = ins_compl_dict_alloc(compl_shown_match);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3961
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3962 set_vim_var_dict(VV_COMPLETED_ITEM, dict);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3963 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3964 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3965 if (!in_compl_func)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3966 compl_curr_match = compl_shown_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3967 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3968
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3969 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3970 * show the file name for the completion match (if any). Truncate the file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3971 * name to avoid a wait for return.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3972 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3973 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3974 ins_compl_show_filename(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3975 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3976 char *lead = _("match in file");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3977 int space = sc_col - vim_strsize((char_u *)lead) - 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3978 char_u *s;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3979 char_u *e;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3980
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3981 if (space <= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3982 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3983
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3984 // We need the tail that fits. With double-byte encoding going
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3985 // back from the end is very slow, thus go from the start and keep
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3986 // the text that fits in "space" between "s" and "e".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3987 for (s = e = compl_shown_match->cp_fname; *e != NUL; MB_PTR_ADV(e))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3988 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3989 space -= ptr2cells(e);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3990 while (space < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3991 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3992 space += ptr2cells(s);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3993 MB_PTR_ADV(s);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3994 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3995 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3996 msg_hist_off = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3997 vim_snprintf((char *)IObuff, IOSIZE, "%s %s%s", lead,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3998 s > compl_shown_match->cp_fname ? "<" : "", s);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
3999 msg((char *)IObuff);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4000 msg_hist_off = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4001 redraw_cmdline = FALSE; // don't overwrite!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4002 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4003
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4004 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4005 * Find the next set of matches for completion. Repeat the completion "todo"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4006 * times. The number of matches found is returned in 'num_matches'.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4007 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4008 * If "allow_get_expansion" is TRUE, then ins_compl_get_exp() may be called to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4009 * get more completions. If it is FALSE, then do nothing when there are no more
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4010 * completions in the given direction.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4011 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4012 * If "advance" is TRUE, then completion will move to the first match.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4013 * Otherwise, the original text will be shown.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4014 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4015 * Returns OK on success and -1 if the number of matches are unknown.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4016 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4017 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4018 find_next_completion_match(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4019 int allow_get_expansion,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4020 int todo, // repeat completion this many times
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4021 int advance,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4022 int *num_matches)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4023 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4024 int found_end = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4025 compl_T *found_compl = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4026
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4027 while (--todo >= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4028 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4029 if (compl_shows_dir_forward() && compl_shown_match->cp_next != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4030 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4031 compl_shown_match = compl_shown_match->cp_next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4032 found_end = (compl_first_match != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4033 && (is_first_match(compl_shown_match->cp_next)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4034 || is_first_match(compl_shown_match)));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4035 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4036 else if (compl_shows_dir_backward()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4037 && compl_shown_match->cp_prev != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4038 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4039 found_end = is_first_match(compl_shown_match);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4040 compl_shown_match = compl_shown_match->cp_prev;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4041 found_end |= is_first_match(compl_shown_match);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4042 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4043 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4044 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4045 if (!allow_get_expansion)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4046 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4047 if (advance)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4048 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4049 if (compl_shows_dir_backward())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4050 compl_pending -= todo + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4051 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4052 compl_pending += todo + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4053 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4054 return -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4055 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4056
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4057 if (!compl_no_select && advance)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4058 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4059 if (compl_shows_dir_backward())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4060 --compl_pending;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4061 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4062 ++compl_pending;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4063 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4064
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4065 // Find matches.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4066 *num_matches = ins_compl_get_exp(&compl_startpos);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4067
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4068 // handle any pending completions
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4069 while (compl_pending != 0 && compl_direction == compl_shows_dir
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4070 && advance)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4071 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4072 if (compl_pending > 0 && compl_shown_match->cp_next != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4073 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4074 compl_shown_match = compl_shown_match->cp_next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4075 --compl_pending;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4076 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4077 if (compl_pending < 0 && compl_shown_match->cp_prev != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4078 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4079 compl_shown_match = compl_shown_match->cp_prev;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4080 ++compl_pending;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4081 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4082 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4083 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4084 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4085 found_end = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4086 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4087 if (!match_at_original_text(compl_shown_match)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4088 && compl_leader != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4089 && !ins_compl_equal(compl_shown_match,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4090 compl_leader, (int)STRLEN(compl_leader)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4091 ++todo;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4092 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4093 // Remember a matching item.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4094 found_compl = compl_shown_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4095
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4096 // Stop at the end of the list when we found a usable match.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4097 if (found_end)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4098 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4099 if (found_compl != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4100 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4101 compl_shown_match = found_compl;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4102 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4103 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4104 todo = 1; // use first usable match after wrapping around
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4105 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4106 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4107
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4108 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4109 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4110
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4111 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4112 * Fill in the next completion in the current direction.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4113 * If "allow_get_expansion" is TRUE, then we may call ins_compl_get_exp() to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4114 * get more completions. If it is FALSE, then we just do nothing when there
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4115 * are no more completions in a given direction. The latter case is used when
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4116 * we are still in the middle of finding completions, to allow browsing
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4117 * through the ones found so far.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4118 * Return the total number of matches, or -1 if still unknown -- webb.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4119 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4120 * compl_curr_match is currently being used by ins_compl_get_exp(), so we use
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4121 * compl_shown_match here.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4122 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4123 * Note that this function may be called recursively once only. First with
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4124 * "allow_get_expansion" TRUE, which calls ins_compl_get_exp(), which in turn
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4125 * calls this function with "allow_get_expansion" FALSE.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4126 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4127 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4128 ins_compl_next(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4129 int allow_get_expansion,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4130 int count, // repeat completion this many times; should
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4131 // be at least 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4132 int insert_match, // Insert the newly selected match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4133 int in_compl_func) // called from complete_check()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4134 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4135 int num_matches = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4136 int todo = count;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4137 int advance;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4138 int started = compl_started;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4139 buf_T *orig_curbuf = curbuf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4140
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4141 // When user complete function return -1 for findstart which is next
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4142 // time of 'always', compl_shown_match become NULL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4143 if (compl_shown_match == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4144 return -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4145
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4146 if (compl_leader != NULL && !match_at_original_text(compl_shown_match))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4147 // Update "compl_shown_match" to the actually shown match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4148 ins_compl_update_shown_match();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4149
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4150 if (allow_get_expansion && insert_match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4151 && (!(compl_get_longest || compl_restarting) || compl_used_match))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4152 // Delete old text to be replaced
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4153 ins_compl_delete();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4154
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4155 // When finding the longest common text we stick at the original text,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4156 // don't let CTRL-N or CTRL-P move to the first match.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4157 advance = count != 1 || !allow_get_expansion || !compl_get_longest;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4158
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4159 // When restarting the search don't insert the first match either.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4160 if (compl_restarting)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4161 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4162 advance = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4163 compl_restarting = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4164 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4165
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4166 // Repeat this for when <PageUp> or <PageDown> is typed. But don't wrap
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4167 // around.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4168 if (find_next_completion_match(allow_get_expansion, todo, advance,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4169 &num_matches) == -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4170 return -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4171
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4172 if (curbuf != orig_curbuf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4173 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4174 // In case some completion function switched buffer, don't want to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4175 // insert the completion elsewhere.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4176 return -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4177 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4178
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4179 // Insert the text of the new completion, or the compl_leader.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4180 if (compl_no_insert && !started)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4181 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4182 ins_bytes(compl_orig_text + get_compl_len());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4183 compl_used_match = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4184 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4185 else if (insert_match)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4186 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4187 if (!compl_get_longest || compl_used_match)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4188 ins_compl_insert(in_compl_func);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4189 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4190 ins_bytes(compl_leader + get_compl_len());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4191 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4192 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4193 compl_used_match = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4194
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4195 if (!allow_get_expansion)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4196 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4197 // may undisplay the popup menu first
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4198 ins_compl_upd_pum();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4199
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4200 if (pum_enough_matches())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4201 // Will display the popup menu, don't redraw yet to avoid flicker.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4202 pum_call_update_screen();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4203 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4204 // Not showing the popup menu yet, redraw to show the user what was
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4205 // inserted.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4206 update_screen(0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4207
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4208 // display the updated popup menu
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4209 ins_compl_show_pum();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4210 #ifdef FEAT_GUI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4211 if (gui.in_use)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4212 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4213 // Show the cursor after the match, not after the redrawn text.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4214 setcursor();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4215 out_flush_cursor(FALSE, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4216 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4217 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4218
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4219 // Delete old text to be replaced, since we're still searching and
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4220 // don't want to match ourselves!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4221 ins_compl_delete();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4222 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4223
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4224 // Enter will select a match when the match wasn't inserted and the popup
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4225 // menu is visible.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4226 if (compl_no_insert && !started)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4227 compl_enter_selects = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4228 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4229 compl_enter_selects = !insert_match && compl_match_array != NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4230
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4231 // Show the file name for the match (if any)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4232 if (compl_shown_match->cp_fname != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4233 ins_compl_show_filename();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4234
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4235 return num_matches;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4236 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4237
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4238 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4239 * Call this while finding completions, to check whether the user has hit a key
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4240 * that should change the currently displayed completion, or exit completion
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4241 * mode. Also, when compl_pending is not zero, show a completion as soon as
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4242 * possible. -- webb
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4243 * "frequency" specifies out of how many calls we actually check.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4244 * "in_compl_func" is TRUE when called from complete_check(), don't set
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4245 * compl_curr_match.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4246 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4247 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4248 ins_compl_check_keys(int frequency, int in_compl_func)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4249 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4250 static int count = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4251 int c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4252
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4253 // Don't check when reading keys from a script, :normal or feedkeys().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4254 // That would break the test scripts. But do check for keys when called
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4255 // from complete_check().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4256 if (!in_compl_func && (using_script() || ex_normal_busy))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4257 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4258
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4259 // Only do this at regular intervals
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4260 if (++count < frequency)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4261 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4262 count = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4263
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4264 // Check for a typed key. Do use mappings, otherwise vim_is_ctrl_x_key()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4265 // can't do its work correctly.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4266 c = vpeekc_any();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4267 if (c != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4268 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4269 if (vim_is_ctrl_x_key(c) && c != Ctrl_X && c != Ctrl_R)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4270 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4271 c = safe_vgetc(); // Eat the character
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4272 compl_shows_dir = ins_compl_key2dir(c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4273 (void)ins_compl_next(FALSE, ins_compl_key2count(c),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4274 c != K_UP && c != K_DOWN, in_compl_func);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4275 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4276 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4277 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4278 // Need to get the character to have KeyTyped set. We'll put it
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4279 // back with vungetc() below. But skip K_IGNORE.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4280 c = safe_vgetc();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4281 if (c != K_IGNORE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4282 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4283 // Don't interrupt completion when the character wasn't typed,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4284 // e.g., when doing @q to replay keys.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4285 if (c != Ctrl_R && KeyTyped)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4286 compl_interrupted = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4287
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4288 vungetc(c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4289 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4290 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4291 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4292 if (compl_pending != 0 && !got_int && !compl_no_insert)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4293 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4294 int todo = compl_pending > 0 ? compl_pending : -compl_pending;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4295
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4296 compl_pending = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4297 (void)ins_compl_next(FALSE, todo, TRUE, in_compl_func);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4298 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4299 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4300
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4301 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4302 * Decide the direction of Insert mode complete from the key typed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4303 * Returns BACKWARD or FORWARD.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4304 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4305 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4306 ins_compl_key2dir(int c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4307 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4308 if (c == Ctrl_P || c == Ctrl_L
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4309 || c == K_PAGEUP || c == K_KPAGEUP || c == K_S_UP || c == K_UP)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4310 return BACKWARD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4311 return FORWARD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4312 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4313
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4314 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4315 * Return TRUE for keys that are used for completion only when the popup menu
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4316 * is visible.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4317 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4318 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4319 ins_compl_pum_key(int c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4320 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4321 return pum_visible() && (c == K_PAGEUP || c == K_KPAGEUP || c == K_S_UP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4322 || c == K_PAGEDOWN || c == K_KPAGEDOWN || c == K_S_DOWN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4323 || c == K_UP || c == K_DOWN);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4324 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4325
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4326 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4327 * Decide the number of completions to move forward.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4328 * Returns 1 for most keys, height of the popup menu for page-up/down keys.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4329 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4330 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4331 ins_compl_key2count(int c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4332 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4333 int h;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4334
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4335 if (ins_compl_pum_key(c) && c != K_UP && c != K_DOWN)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4336 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4337 h = pum_get_height();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4338 if (h > 3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4339 h -= 2; // keep some context
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4340 return h;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4341 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4342 return 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4343 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4344
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4345 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4346 * Return TRUE if completion with "c" should insert the match, FALSE if only
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4347 * to change the currently selected completion.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4348 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4349 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4350 ins_compl_use_match(int c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4351 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4352 switch (c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4353 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4354 case K_UP:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4355 case K_DOWN:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4356 case K_PAGEDOWN:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4357 case K_KPAGEDOWN:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4358 case K_S_DOWN:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4359 case K_PAGEUP:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4360 case K_KPAGEUP:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4361 case K_S_UP:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4362 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4363 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4364 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4365 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4366
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4367 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4368 * Get the pattern, column and length for normal completion (CTRL-N CTRL-P
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4369 * completion)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4370 * Sets the global variables: compl_col, compl_length and compl_pattern.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4371 * Uses the global variables: compl_cont_status and ctrl_x_mode
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4372 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4373 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4374 get_normal_compl_info(char_u *line, int startcol, colnr_T curs_col)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4375 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4376 if ((compl_cont_status & CONT_SOL) || ctrl_x_mode_path_defines())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4377 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4378 if (!compl_status_adding())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4379 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4380 while (--startcol >= 0 && vim_isIDc(line[startcol]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4381 ;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4382 compl_col += ++startcol;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4383 compl_length = curs_col - startcol;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4384 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4385 if (p_ic)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4386 compl_pattern = str_foldcase(line + compl_col,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4387 compl_length, NULL, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4388 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4389 compl_pattern = vim_strnsave(line + compl_col, compl_length);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4390 if (compl_pattern == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4391 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4392 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4393 else if (compl_status_adding())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4394 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4395 char_u *prefix = (char_u *)"\\<";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4396
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4397 // we need up to 2 extra chars for the prefix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4398 compl_pattern = alloc(quote_meta(NULL, line + compl_col,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4399 compl_length) + 2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4400 if (compl_pattern == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4401 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4402 if (!vim_iswordp(line + compl_col)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4403 || (compl_col > 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4404 && (vim_iswordp(mb_prevptr(line, line + compl_col)))))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4405 prefix = (char_u *)"";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4406 STRCPY((char *)compl_pattern, prefix);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4407 (void)quote_meta(compl_pattern + STRLEN(prefix),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4408 line + compl_col, compl_length);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4409 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4410 else if (--startcol < 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4411 || !vim_iswordp(mb_prevptr(line, line + startcol + 1)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4412 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4413 // Match any word of at least two chars
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4414 compl_pattern = vim_strsave((char_u *)"\\<\\k\\k");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4415 if (compl_pattern == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4416 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4417 compl_col += curs_col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4418 compl_length = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4419 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4420 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4421 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4422 // Search the point of change class of multibyte character
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4423 // or not a word single byte character backward.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4424 if (has_mbyte)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4425 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4426 int base_class;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4427 int head_off;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4428
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4429 startcol -= (*mb_head_off)(line, line + startcol);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4430 base_class = mb_get_class(line + startcol);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4431 while (--startcol >= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4432 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4433 head_off = (*mb_head_off)(line, line + startcol);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4434 if (base_class != mb_get_class(line + startcol
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4435 - head_off))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4436 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4437 startcol -= head_off;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4438 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4439 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4440 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4441 while (--startcol >= 0 && vim_iswordc(line[startcol]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4442 ;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4443 compl_col += ++startcol;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4444 compl_length = (int)curs_col - startcol;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4445 if (compl_length == 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4446 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4447 // Only match word with at least two chars -- webb
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4448 // there's no need to call quote_meta,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4449 // alloc(7) is enough -- Acevedo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4450 compl_pattern = alloc(7);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4451 if (compl_pattern == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4452 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4453 STRCPY((char *)compl_pattern, "\\<");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4454 (void)quote_meta(compl_pattern + 2, line + compl_col, 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4455 STRCAT((char *)compl_pattern, "\\k");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4456 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4457 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4458 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4459 compl_pattern = alloc(quote_meta(NULL, line + compl_col,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4460 compl_length) + 2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4461 if (compl_pattern == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4462 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4463 STRCPY((char *)compl_pattern, "\\<");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4464 (void)quote_meta(compl_pattern + 2, line + compl_col,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4465 compl_length);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4466 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4467 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4468
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4469 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4470 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4471
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4472 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4473 * Get the pattern, column and length for whole line completion or for the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4474 * complete() function.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4475 * Sets the global variables: compl_col, compl_length and compl_pattern.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4476 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4477 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4478 get_wholeline_compl_info(char_u *line, colnr_T curs_col)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4479 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4480 compl_col = (colnr_T)getwhitecols(line);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4481 compl_length = (int)curs_col - (int)compl_col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4482 if (compl_length < 0) // cursor in indent: empty pattern
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4483 compl_length = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4484 if (p_ic)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4485 compl_pattern = str_foldcase(line + compl_col, compl_length,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4486 NULL, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4487 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4488 compl_pattern = vim_strnsave(line + compl_col, compl_length);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4489 if (compl_pattern == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4490 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4491
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4492 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4493 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4494
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4495 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4496 * Get the pattern, column and length for filename completion.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4497 * Sets the global variables: compl_col, compl_length and compl_pattern.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4498 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4499 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4500 get_filename_compl_info(char_u *line, int startcol, colnr_T curs_col)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4501 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4502 // Go back to just before the first filename character.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4503 if (startcol > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4504 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4505 char_u *p = line + startcol;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4506
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4507 MB_PTR_BACK(line, p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4508 while (p > line && vim_isfilec(PTR2CHAR(p)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4509 MB_PTR_BACK(line, p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4510 if (p == line && vim_isfilec(PTR2CHAR(p)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4511 startcol = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4512 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4513 startcol = (int)(p - line) + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4514 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4515
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4516 compl_col += startcol;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4517 compl_length = (int)curs_col - startcol;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4518 compl_pattern = addstar(line + compl_col, compl_length, EXPAND_FILES);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4519 if (compl_pattern == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4520 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4521
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4522 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4523 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4524
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4525 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4526 * Get the pattern, column and length for command-line completion.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4527 * Sets the global variables: compl_col, compl_length and compl_pattern.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4528 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4529 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4530 get_cmdline_compl_info(char_u *line, colnr_T curs_col)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4531 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4532 compl_pattern = vim_strnsave(line, curs_col);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4533 if (compl_pattern == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4534 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4535 set_cmd_context(&compl_xp, compl_pattern,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4536 (int)STRLEN(compl_pattern), curs_col, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4537 if (compl_xp.xp_context == EXPAND_UNSUCCESSFUL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4538 || compl_xp.xp_context == EXPAND_NOTHING)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4539 // No completion possible, use an empty pattern to get a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4540 // "pattern not found" message.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4541 compl_col = curs_col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4542 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4543 compl_col = (int)(compl_xp.xp_pattern - compl_pattern);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4544 compl_length = curs_col - compl_col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4545
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4546 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4547 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4548
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4549 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4550 * Get the pattern, column and length for user defined completion ('omnifunc',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4551 * 'completefunc' and 'thesaurusfunc')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4552 * Sets the global variables: compl_col, compl_length and compl_pattern.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4553 * Uses the global variable: spell_bad_len
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4554 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4555 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4556 get_userdefined_compl_info(colnr_T curs_col UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4557 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4558 int ret = FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4559
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4560 #ifdef FEAT_COMPL_FUNC
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4561 // Call user defined function 'completefunc' with "a:findstart"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4562 // set to 1 to obtain the length of text to use for completion.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4563 char_u *line;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4564 typval_T args[3];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4565 int col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4566 char_u *funcname;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4567 pos_T pos;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4568 int save_State = State;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4569 callback_T *cb;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4570
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4571 // Call 'completefunc' or 'omnifunc' or 'thesaurusfunc' and get pattern
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4572 // length as a string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4573 funcname = get_complete_funcname(ctrl_x_mode);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4574 if (*funcname == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4575 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4576 semsg(_(e_option_str_is_not_set), ctrl_x_mode_function()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4577 ? "completefunc" : "omnifunc");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4578 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4579 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4580
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4581 args[0].v_type = VAR_NUMBER;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4582 args[0].vval.v_number = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4583 args[1].v_type = VAR_STRING;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4584 args[1].vval.v_string = (char_u *)"";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4585 args[2].v_type = VAR_UNKNOWN;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4586 pos = curwin->w_cursor;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4587 ++textlock;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4588 cb = get_insert_callback(ctrl_x_mode);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4589 col = call_callback_retnr(cb, 2, args);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4590 --textlock;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4591
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4592 State = save_State;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4593 curwin->w_cursor = pos; // restore the cursor position
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4594 validate_cursor();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4595 if (!EQUAL_POS(curwin->w_cursor, pos))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4596 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4597 emsg(_(e_complete_function_deleted_text));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4598 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4599 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4600
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4601 // Return value -2 means the user complete function wants to cancel the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4602 // complete without an error, do the same if the function did not execute
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4603 // successfully.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4604 if (col == -2 || aborting())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4605 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4606 // Return value -3 does the same as -2 and leaves CTRL-X mode.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4607 if (col == -3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4608 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4609 ctrl_x_mode = CTRL_X_NORMAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4610 edit_submode = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4611 if (!shortmess(SHM_COMPLETIONMENU))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4612 msg_clr_cmdline();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4613 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4614 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4615
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4616 // Reset extended parameters of completion, when starting new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4617 // completion.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4618 compl_opt_refresh_always = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4619 compl_opt_suppress_empty = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4620
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4621 if (col < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4622 col = curs_col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4623 compl_col = col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4624 if (compl_col > curs_col)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4625 compl_col = curs_col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4626
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4627 // Setup variables for completion. Need to obtain "line" again,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4628 // it may have become invalid.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4629 line = ml_get(curwin->w_cursor.lnum);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4630 compl_length = curs_col - compl_col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4631 compl_pattern = vim_strnsave(line + compl_col, compl_length);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4632 if (compl_pattern == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4633 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4634
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4635 ret = OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4636 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4637
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4638 return ret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4639 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4640
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4641 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4642 * Get the pattern, column and length for spell completion.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4643 * Sets the global variables: compl_col, compl_length and compl_pattern.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4644 * Uses the global variable: spell_bad_len
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4645 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4646 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4647 get_spell_compl_info(int startcol UNUSED, colnr_T curs_col UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4648 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4649 int ret = FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4650 #ifdef FEAT_SPELL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4651 char_u *line;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4652
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4653 if (spell_bad_len > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4654 compl_col = curs_col - spell_bad_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4655 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4656 compl_col = spell_word_start(startcol);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4657 if (compl_col >= (colnr_T)startcol)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4658 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4659 compl_length = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4660 compl_col = curs_col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4661 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4662 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4663 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4664 spell_expand_check_cap(compl_col);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4665 compl_length = (int)curs_col - compl_col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4666 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4667 // Need to obtain "line" again, it may have become invalid.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4668 line = ml_get(curwin->w_cursor.lnum);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4669 compl_pattern = vim_strnsave(line + compl_col, compl_length);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4670 if (compl_pattern == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4671 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4672
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4673 ret = OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4674 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4675
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4676 return ret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4677 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4678
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4679 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4680 * Get the completion pattern, column and length.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4681 * "startcol" - start column number of the completion pattern/text
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4682 * "cur_col" - current cursor column
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4683 * On return, "line_invalid" is set to TRUE, if the current line may have
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4684 * become invalid and needs to be fetched again.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4685 * Returns OK on success.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4686 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4687 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4688 compl_get_info(char_u *line, int startcol, colnr_T curs_col, int *line_invalid)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4689 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4690 if (ctrl_x_mode_normal()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4691 || (ctrl_x_mode & CTRL_X_WANT_IDENT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4692 && !thesaurus_func_complete(ctrl_x_mode)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4693 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4694 return get_normal_compl_info(line, startcol, curs_col);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4695 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4696 else if (ctrl_x_mode_line_or_eval())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4697 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4698 return get_wholeline_compl_info(line, curs_col);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4699 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4700 else if (ctrl_x_mode_files())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4701 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4702 return get_filename_compl_info(line, startcol, curs_col);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4703 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4704 else if (ctrl_x_mode == CTRL_X_CMDLINE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4705 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4706 return get_cmdline_compl_info(line, curs_col);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4707 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4708 else if (ctrl_x_mode_function() || ctrl_x_mode_omni()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4709 || thesaurus_func_complete(ctrl_x_mode))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4710 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4711 if (get_userdefined_compl_info(curs_col) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4712 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4713 *line_invalid = TRUE; // "line" may have become invalid
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4714 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4715 else if (ctrl_x_mode_spell())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4716 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4717 if (get_spell_compl_info(startcol, curs_col) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4718 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4719 *line_invalid = TRUE; // "line" may have become invalid
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4720 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4721 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4722 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4723 internal_error("ins_complete()");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4724 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4725 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4726
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4727 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4728 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4729
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4730 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4731 * Continue an interrupted completion mode search in "line".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4732 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4733 * If this same ctrl_x_mode has been interrupted use the text from
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4734 * "compl_startpos" to the cursor as a pattern to add a new word instead of
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4735 * expand the one before the cursor, in word-wise if "compl_startpos" is not in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4736 * the same line as the cursor then fix it (the line has been split because it
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4737 * was longer than 'tw'). if SOL is set then skip the previous pattern, a word
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4738 * at the beginning of the line has been inserted, we'll look for that.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4739 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4740 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4741 ins_compl_continue_search(char_u *line)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4742 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4743 // it is a continued search
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4744 compl_cont_status &= ~CONT_INTRPT; // remove INTRPT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4745 if (ctrl_x_mode_normal() || ctrl_x_mode_path_patterns()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4746 || ctrl_x_mode_path_defines())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4747 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4748 if (compl_startpos.lnum != curwin->w_cursor.lnum)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4749 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4750 // line (probably) wrapped, set compl_startpos to the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4751 // first non_blank in the line, if it is not a wordchar
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4752 // include it to get a better pattern, but then we don't
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4753 // want the "\\<" prefix, check it below
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4754 compl_col = (colnr_T)getwhitecols(line);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4755 compl_startpos.col = compl_col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4756 compl_startpos.lnum = curwin->w_cursor.lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4757 compl_cont_status &= ~CONT_SOL; // clear SOL if present
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4758 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4759 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4760 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4761 // S_IPOS was set when we inserted a word that was at the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4762 // beginning of the line, which means that we'll go to SOL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4763 // mode but first we need to redefine compl_startpos
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4764 if (compl_cont_status & CONT_S_IPOS)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4765 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4766 compl_cont_status |= CONT_SOL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4767 compl_startpos.col = (colnr_T)(skipwhite(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4768 line + compl_length
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4769 + compl_startpos.col) - line);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4770 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4771 compl_col = compl_startpos.col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4772 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4773 compl_length = curwin->w_cursor.col - (int)compl_col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4774 // IObuff is used to add a "word from the next line" would we
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4775 // have enough space? just being paranoid
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4776 #define MIN_SPACE 75
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4777 if (compl_length > (IOSIZE - MIN_SPACE))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4778 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4779 compl_cont_status &= ~CONT_SOL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4780 compl_length = (IOSIZE - MIN_SPACE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4781 compl_col = curwin->w_cursor.col - compl_length;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4782 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4783 compl_cont_status |= CONT_ADDING | CONT_N_ADDS;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4784 if (compl_length < 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4785 compl_cont_status &= CONT_LOCAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4786 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4787 else if (ctrl_x_mode_line_or_eval())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4788 compl_cont_status = CONT_ADDING | CONT_N_ADDS;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4789 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4790 compl_cont_status = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4791 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4792
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4793 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4794 * start insert mode completion
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4795 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4796 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4797 ins_compl_start(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4798 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4799 char_u *line;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4800 int startcol = 0; // column where searched text starts
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4801 colnr_T curs_col; // cursor column
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4802 int line_invalid = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4803 int save_did_ai = did_ai;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4804 int flags = CP_ORIGINAL_TEXT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4805
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4806 // First time we hit ^N or ^P (in a row, I mean)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4807
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4808 did_ai = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4809 did_si = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4810 can_si = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4811 can_si_back = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4812 if (stop_arrow() == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4813 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4814
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4815 line = ml_get(curwin->w_cursor.lnum);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4816 curs_col = curwin->w_cursor.col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4817 compl_pending = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4818
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4819 if ((compl_cont_status & CONT_INTRPT) == CONT_INTRPT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4820 && compl_cont_mode == ctrl_x_mode)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4821 // this same ctrl-x_mode was interrupted previously. Continue the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4822 // completion.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4823 ins_compl_continue_search(line);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4824 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4825 compl_cont_status &= CONT_LOCAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4826
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4827 if (!compl_status_adding()) // normal expansion
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4828 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4829 compl_cont_mode = ctrl_x_mode;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4830 if (ctrl_x_mode_not_default())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4831 // Remove LOCAL if ctrl_x_mode != CTRL_X_NORMAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4832 compl_cont_status = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4833 compl_cont_status |= CONT_N_ADDS;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4834 compl_startpos = curwin->w_cursor;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4835 startcol = (int)curs_col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4836 compl_col = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4837 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4838
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4839 // Work out completion pattern and original text -- webb
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4840 if (compl_get_info(line, startcol, curs_col, &line_invalid) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4841 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4842 if (ctrl_x_mode_function() || ctrl_x_mode_omni()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4843 || thesaurus_func_complete(ctrl_x_mode))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4844 // restore did_ai, so that adding comment leader works
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4845 did_ai = save_did_ai;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4846 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4847 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4848 // If "line" was changed while getting completion info get it again.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4849 if (line_invalid)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4850 line = ml_get(curwin->w_cursor.lnum);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4851
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4852 if (compl_status_adding())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4853 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4854 edit_submode_pre = (char_u *)_(" Adding");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4855 if (ctrl_x_mode_line_or_eval())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4856 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4857 // Insert a new line, keep indentation but ignore 'comments'.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4858 char_u *old = curbuf->b_p_com;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4859
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4860 curbuf->b_p_com = (char_u *)"";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4861 compl_startpos.lnum = curwin->w_cursor.lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4862 compl_startpos.col = compl_col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4863 ins_eol('\r');
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4864 curbuf->b_p_com = old;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4865 compl_length = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4866 compl_col = curwin->w_cursor.col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4867 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4868 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4869 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4870 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4871 edit_submode_pre = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4872 compl_startpos.col = compl_col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4873 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4874
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4875 if (compl_cont_status & CONT_LOCAL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4876 edit_submode = (char_u *)_(ctrl_x_msgs[CTRL_X_LOCAL_MSG]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4877 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4878 edit_submode = (char_u *)_(CTRL_X_MSG(ctrl_x_mode));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4879
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4880 // If any of the original typed text has been changed we need to fix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4881 // the redo buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4882 ins_compl_fixRedoBufForLeader(NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4883
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4884 // Always add completion for the original text.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4885 vim_free(compl_orig_text);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4886 compl_orig_text = vim_strnsave(line + compl_col, compl_length);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4887 if (p_ic)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4888 flags |= CP_ICASE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4889 if (compl_orig_text == NULL || ins_compl_add(compl_orig_text,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4890 -1, NULL, NULL, NULL, 0, flags, FALSE) != OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4891 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4892 VIM_CLEAR(compl_pattern);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4893 VIM_CLEAR(compl_orig_text);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4894 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4895 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4896
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4897 // showmode might reset the internal line pointers, so it must
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4898 // be called before line = ml_get(), or when this address is no
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4899 // longer needed. -- Acevedo.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4900 edit_submode_extra = (char_u *)_("-- Searching...");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4901 edit_submode_highl = HLF_COUNT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4902 showmode();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4903 edit_submode_extra = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4904 out_flush();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4905
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4906 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4907 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4908
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4909 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4910 * display the completion status message
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4911 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4912 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4913 ins_compl_show_statusmsg(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4914 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4915 // we found no match if the list has only the "compl_orig_text"-entry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4916 if (is_first_match(compl_first_match->cp_next))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4917 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4918 edit_submode_extra = compl_status_adding() && compl_length > 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4919 ? (char_u *)_("Hit end of paragraph")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4920 : (char_u *)_("Pattern not found");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4921 edit_submode_highl = HLF_E;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4922 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4923
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4924 if (edit_submode_extra == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4925 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4926 if (match_at_original_text(compl_curr_match))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4927 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4928 edit_submode_extra = (char_u *)_("Back at original");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4929 edit_submode_highl = HLF_W;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4930 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4931 else if (compl_cont_status & CONT_S_IPOS)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4932 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4933 edit_submode_extra = (char_u *)_("Word from other line");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4934 edit_submode_highl = HLF_COUNT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4935 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4936 else if (compl_curr_match->cp_next == compl_curr_match->cp_prev)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4937 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4938 edit_submode_extra = (char_u *)_("The only match");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4939 edit_submode_highl = HLF_COUNT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4940 compl_curr_match->cp_number = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4941 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4942 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4943 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4944 #if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4945 // Update completion sequence number when needed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4946 if (compl_curr_match->cp_number == -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4947 ins_compl_update_sequence_numbers();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4948 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4949 // The match should always have a sequence number now, this is
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4950 // just a safety check.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4951 if (compl_curr_match->cp_number != -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4952 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4953 // Space for 10 text chars. + 2x10-digit no.s = 31.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4954 // Translations may need more than twice that.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4955 static char_u match_ref[81];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4956
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4957 if (compl_matches > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4958 vim_snprintf((char *)match_ref, sizeof(match_ref),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4959 _("match %d of %d"),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4960 compl_curr_match->cp_number, compl_matches);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4961 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4962 vim_snprintf((char *)match_ref, sizeof(match_ref),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4963 _("match %d"),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4964 compl_curr_match->cp_number);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4965 edit_submode_extra = match_ref;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4966 edit_submode_highl = HLF_R;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4967 if (dollar_vcol >= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4968 curs_columns(FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4969 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4970 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4971 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4972
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4973 // Show a message about what (completion) mode we're in.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4974 if (!compl_opt_suppress_empty)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4975 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4976 showmode();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4977 if (!shortmess(SHM_COMPLETIONMENU))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4978 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4979 if (edit_submode_extra != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4980 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4981 if (!p_smd)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4982 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4983 msg_hist_off = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4984 msg_attr((char *)edit_submode_extra,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4985 edit_submode_highl < HLF_COUNT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4986 ? HL_ATTR(edit_submode_highl) : 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4987 msg_hist_off = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4988 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4989 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4990 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4991 msg_clr_cmdline(); // necessary for "noshowmode"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4992 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4993 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4994 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4995
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4996 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4997 * Do Insert mode completion.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4998 * Called when character "c" was typed, which has a meaning for completion.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
4999 * Returns OK if completion was done, FAIL if something failed (out of mem).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5000 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5001 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5002 ins_complete(int c, int enable_pum)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5003 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5004 int n;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5005 int save_w_wrow;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5006 int save_w_leftcol;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5007 int insert_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5008
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5009 compl_direction = ins_compl_key2dir(c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5010 insert_match = ins_compl_use_match(c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5011
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5012 if (!compl_started)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5013 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5014 if (ins_compl_start() == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5015 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5016 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5017 else if (insert_match && stop_arrow() == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5018 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5019
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5020 compl_shown_match = compl_curr_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5021 compl_shows_dir = compl_direction;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5022
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5023 // Find next match (and following matches).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5024 save_w_wrow = curwin->w_wrow;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5025 save_w_leftcol = curwin->w_leftcol;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5026 n = ins_compl_next(TRUE, ins_compl_key2count(c), insert_match, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5027
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5028 // may undisplay the popup menu
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5029 ins_compl_upd_pum();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5030
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5031 if (n > 1) // all matches have been found
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5032 compl_matches = n;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5033 compl_curr_match = compl_shown_match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5034 compl_direction = compl_shows_dir;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5035
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5036 // Eat the ESC that vgetc() returns after a CTRL-C to avoid leaving Insert
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5037 // mode.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5038 if (got_int && !global_busy)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5039 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5040 (void)vgetc();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5041 got_int = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5042 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5043
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5044 // we found no match if the list has only the "compl_orig_text"-entry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5045 if (is_first_match(compl_first_match->cp_next))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5046 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5047 // remove N_ADDS flag, so next ^X<> won't try to go to ADDING mode,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5048 // because we couldn't expand anything at first place, but if we used
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5049 // ^P, ^N, ^X^I or ^X^D we might want to add-expand a single-char-word
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5050 // (such as M in M'exico) if not tried already. -- Acevedo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5051 if (compl_length > 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5052 || compl_status_adding()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5053 || (ctrl_x_mode_not_default()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5054 && !ctrl_x_mode_path_patterns()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5055 && !ctrl_x_mode_path_defines()))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5056 compl_cont_status &= ~CONT_N_ADDS;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5057 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5058
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5059 if (compl_curr_match->cp_flags & CP_CONT_S_IPOS)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5060 compl_cont_status |= CONT_S_IPOS;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5061 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5062 compl_cont_status &= ~CONT_S_IPOS;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5063
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5064 ins_compl_show_statusmsg();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5065
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5066 // Show the popup menu, unless we got interrupted.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5067 if (enable_pum && !compl_interrupted)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5068 show_pum(save_w_wrow, save_w_leftcol);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5069
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5070 compl_was_interrupted = compl_interrupted;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5071 compl_interrupted = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5072
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5073 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5074 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5075
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5076 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5077 * Remove (if needed) and show the popup menu
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5078 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5079 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5080 show_pum(int prev_w_wrow, int prev_w_leftcol)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5081 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5082 // RedrawingDisabled may be set when invoked through complete().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5083 int save_RedrawingDisabled = RedrawingDisabled;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5084 RedrawingDisabled = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5085
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5086 // If the cursor moved or the display scrolled we need to remove the pum
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5087 // first.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5088 setcursor();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5089 if (prev_w_wrow != curwin->w_wrow || prev_w_leftcol != curwin->w_leftcol)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5090 ins_compl_del_pum();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5091
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5092 ins_compl_show_pum();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5093 setcursor();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5094
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5095 RedrawingDisabled = save_RedrawingDisabled;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5096 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5097
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5098 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5099 * Looks in the first "len" chars. of "src" for search-metachars.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5100 * If dest is not NULL the chars. are copied there quoting (with
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5101 * a backslash) the metachars, and dest would be NUL terminated.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5102 * Returns the length (needed) of dest
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5103 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5104 static unsigned
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5105 quote_meta(char_u *dest, char_u *src, int len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5106 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5107 unsigned m = (unsigned)len + 1; // one extra for the NUL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5108
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5109 for ( ; --len >= 0; src++)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5110 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5111 switch (*src)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5112 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5113 case '.':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5114 case '*':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5115 case '[':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5116 if (ctrl_x_mode_dictionary() || ctrl_x_mode_thesaurus())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5117 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5118 // FALLTHROUGH
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5119 case '~':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5120 if (!magic_isset()) // quote these only if magic is set
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5121 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5122 // FALLTHROUGH
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5123 case '\\':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5124 if (ctrl_x_mode_dictionary() || ctrl_x_mode_thesaurus())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5125 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5126 // FALLTHROUGH
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5127 case '^': // currently it's not needed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5128 case '$':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5129 m++;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5130 if (dest != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5131 *dest++ = '\\';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5132 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5133 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5134 if (dest != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5135 *dest++ = *src;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5136 // Copy remaining bytes of a multibyte character.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5137 if (has_mbyte)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5138 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5139 int i, mb_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5140
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5141 mb_len = (*mb_ptr2len)(src) - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5142 if (mb_len > 0 && len >= mb_len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5143 for (i = 0; i < mb_len; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5144 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5145 --len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5146 ++src;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5147 if (dest != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5148 *dest++ = *src;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5149 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5150 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5151 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5152 if (dest != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5153 *dest = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5154
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5155 return m;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5156 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5157
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5158 #if defined(EXITFREE) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5159 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5160 free_insexpand_stuff(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5161 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5162 VIM_CLEAR(compl_orig_text);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5163 # ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5164 free_callback(&cfu_cb);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5165 free_callback(&ofu_cb);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5166 free_callback(&tsrfu_cb);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5167 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5168 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5169 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5170
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5171 #ifdef FEAT_SPELL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5172 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5173 * Called when starting CTRL_X_SPELL mode: Move backwards to a previous badly
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5174 * spelled word, if there is one.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5175 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5176 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5177 spell_back_to_badword(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5178 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5179 pos_T tpos = curwin->w_cursor;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5180
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5181 spell_bad_len = spell_move_to(curwin, BACKWARD, TRUE, TRUE, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5182 if (curwin->w_cursor.col != tpos.col)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5183 start_arrow(&tpos);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5184 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32479
diff changeset
5185 #endif