7
|
1 /* vi:set ts=8 sts=4 sw=4:
|
|
2 *
|
|
3 * VIM - Vi IMproved by Bram Moolenaar
|
|
4 *
|
|
5 * Do ":help uganda" in Vim to read copying and usage conditions.
|
|
6 * Do ":help credits" in Vim to see a list of people who contributed.
|
|
7 * See README.txt for an overview of the Vim source code.
|
|
8 */
|
|
9
|
|
10 /*
|
|
11 * edit.c: functions for Insert mode
|
|
12 */
|
|
13
|
|
14 #include "vim.h"
|
|
15
|
|
16 #ifdef FEAT_INS_EXPAND
|
|
17 /*
|
|
18 * definitions used for CTRL-X submode
|
|
19 */
|
|
20 #define CTRL_X_WANT_IDENT 0x100
|
|
21
|
|
22 #define CTRL_X_NOT_DEFINED_YET 1
|
|
23 #define CTRL_X_SCROLL 2
|
|
24 #define CTRL_X_WHOLE_LINE 3
|
|
25 #define CTRL_X_FILES 4
|
|
26 #define CTRL_X_TAGS (5 + CTRL_X_WANT_IDENT)
|
|
27 #define CTRL_X_PATH_PATTERNS (6 + CTRL_X_WANT_IDENT)
|
|
28 #define CTRL_X_PATH_DEFINES (7 + CTRL_X_WANT_IDENT)
|
|
29 #define CTRL_X_FINISHED 8
|
|
30 #define CTRL_X_DICTIONARY (9 + CTRL_X_WANT_IDENT)
|
|
31 #define CTRL_X_THESAURUS (10 + CTRL_X_WANT_IDENT)
|
|
32 #define CTRL_X_CMDLINE 11
|
12
|
33 #define CTRL_X_FUNCTION 12
|
523
|
34 #define CTRL_X_OMNI 13
|
477
|
35 #define CTRL_X_SPELL 14
|
|
36 #define CTRL_X_LOCAL_MSG 15 /* only used in "ctrl_x_msgs" */
|
7
|
37
|
|
38 #define CTRL_X_MSG(i) ctrl_x_msgs[(i) & ~CTRL_X_WANT_IDENT]
|
|
39
|
|
40 static char *ctrl_x_msgs[] =
|
|
41 {
|
|
42 N_(" Keyword completion (^N^P)"), /* ctrl_x_mode == 0, ^P/^N compl. */
|
819
|
43 N_(" ^X mode (^]^D^E^F^I^K^L^N^O^Ps^U^V^Y)"),
|
449
|
44 NULL,
|
7
|
45 N_(" Whole line completion (^L^N^P)"),
|
|
46 N_(" File name completion (^F^N^P)"),
|
|
47 N_(" Tag completion (^]^N^P)"),
|
|
48 N_(" Path pattern completion (^N^P)"),
|
|
49 N_(" Definition completion (^D^N^P)"),
|
|
50 NULL,
|
|
51 N_(" Dictionary completion (^K^N^P)"),
|
|
52 N_(" Thesaurus completion (^T^N^P)"),
|
12
|
53 N_(" Command-line completion (^V^N^P)"),
|
|
54 N_(" User defined completion (^U^N^P)"),
|
523
|
55 N_(" Omni completion (^O^N^P)"),
|
819
|
56 N_(" Spelling suggestion (s^N^P)"),
|
449
|
57 N_(" Keyword Local completion (^N^P)"),
|
7
|
58 };
|
|
59
|
|
60 static char_u e_hitend[] = N_("Hit end of paragraph");
|
|
61
|
|
62 /*
|
|
63 * Structure used to store one match for insert completion.
|
|
64 */
|
681
|
65 typedef struct compl_S compl_T;
|
|
66 struct compl_S
|
7
|
67 {
|
464
|
68 compl_T *cp_next;
|
|
69 compl_T *cp_prev;
|
|
70 char_u *cp_str; /* matched text */
|
681
|
71 char cp_icase; /* TRUE or FALSE: ignore case */
|
786
|
72 char_u *(cp_text[CPT_COUNT]); /* text for the menu */
|
659
|
73 char_u *cp_fname; /* file containing the match, allocated when
|
|
74 * cp_flags has FREE_FNAME */
|
464
|
75 int cp_flags; /* ORIGINAL_TEXT, CONT_S_IPOS or FREE_FNAME */
|
|
76 int cp_number; /* sequence number */
|
7
|
77 };
|
|
78
|
464
|
79 #define ORIGINAL_TEXT (1) /* the original text when the expansion begun */
|
7
|
80 #define FREE_FNAME (2)
|
|
81
|
|
82 /*
|
|
83 * All the current matches are stored in a list.
|
449
|
84 * "compl_first_match" points to the start of the list.
|
|
85 * "compl_curr_match" points to the currently selected entry.
|
|
86 * "compl_shown_match" is different from compl_curr_match during
|
|
87 * ins_compl_get_exp().
|
7
|
88 */
|
464
|
89 static compl_T *compl_first_match = NULL;
|
|
90 static compl_T *compl_curr_match = NULL;
|
|
91 static compl_T *compl_shown_match = NULL;
|
449
|
92
|
825
|
93 /* After using a cursor key <Enter> selects a match in the popup menu,
|
|
94 * otherwise it inserts a line break. */
|
|
95 static int compl_enter_selects = FALSE;
|
|
96
|
657
|
97 /* When "compl_leader" is not NULL only matches that start with this string
|
|
98 * are used. */
|
|
99 static char_u *compl_leader = NULL;
|
|
100
|
665
|
101 static int compl_get_longest = FALSE; /* put longest common string
|
|
102 in compl_leader */
|
|
103
|
657
|
104 static int compl_used_match; /* Selected one of the matches. When
|
|
105 FALSE the match was edited or using
|
|
106 the longest common string. */
|
|
107
|
874
|
108 static int compl_was_interrupted = FALSE; /* didn't finish finding
|
|
109 completions. */
|
|
110
|
|
111 static int compl_restarting = FALSE; /* don't insert match */
|
|
112
|
449
|
113 /* When the first completion is done "compl_started" is set. When it's
|
|
114 * FALSE the word to be completed must be located. */
|
644
|
115 static int compl_started = FALSE;
|
449
|
116
|
464
|
117 static int compl_matches = 0;
|
|
118 static char_u *compl_pattern = NULL;
|
|
119 static int compl_direction = FORWARD;
|
|
120 static int compl_shows_dir = FORWARD;
|
716
|
121 static int compl_pending = 0; /* > 1 for postponed CTRL-N */
|
464
|
122 static pos_T compl_startpos;
|
|
123 static colnr_T compl_col = 0; /* column where the text starts
|
|
124 * that is being completed */
|
|
125 static char_u *compl_orig_text = NULL; /* text as it was before
|
|
126 * completion started */
|
|
127 static int compl_cont_mode = 0;
|
|
128 static expand_T compl_xp;
|
449
|
129
|
|
130 static void ins_ctrl_x __ARGS((void));
|
|
131 static int has_compl_option __ARGS((int dict_opt));
|
841
|
132 static int ins_compl_add __ARGS((char_u *str, int len, int icase, char_u *fname, char_u **cptext, int cdir, int flags, int dup));
|
681
|
133 static int ins_compl_equal __ARGS((compl_T *match, char_u *str, int len));
|
665
|
134 static void ins_compl_longest_match __ARGS((compl_T *match));
|
681
|
135 static void ins_compl_add_matches __ARGS((int num_matches, char_u **matches, int icase));
|
7
|
136 static int ins_compl_make_cyclic __ARGS((void));
|
540
|
137 static void ins_compl_upd_pum __ARGS((void));
|
|
138 static void ins_compl_del_pum __ARGS((void));
|
648
|
139 static int pum_wanted __ARGS((void));
|
707
|
140 static int pum_enough_matches __ARGS((void));
|
659
|
141 static void ins_compl_dictionaries __ARGS((char_u *dict, char_u *pat, int flags, int thesaurus));
|
703
|
142 static void ins_compl_files __ARGS((int count, char_u **files, int thesaurus, int flags, regmatch_T *regmatch, char_u *buf, int *dir));
|
667
|
143 static char_u *find_line_end __ARGS((char_u *ptr));
|
7
|
144 static void ins_compl_free __ARGS((void));
|
|
145 static void ins_compl_clear __ARGS((void));
|
657
|
146 static int ins_compl_bs __ARGS((void));
|
874
|
147 static void ins_compl_new_leader __ARGS((void));
|
657
|
148 static void ins_compl_addleader __ARGS((int c));
|
874
|
149 static void ins_compl_restart __ARGS((void));
|
694
|
150 static void ins_compl_set_original_text __ARGS((char_u *str));
|
659
|
151 static void ins_compl_addfrommatch __ARGS((void));
|
540
|
152 static int ins_compl_prep __ARGS((int c));
|
7
|
153 static buf_T *ins_compl_next_buf __ARGS((buf_T *buf, int flag));
|
724
|
154 #if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL)
|
|
155 static void ins_compl_add_list __ARGS((list_T *list));
|
|
156 #endif
|
659
|
157 static int ins_compl_get_exp __ARGS((pos_T *ini));
|
7
|
158 static void ins_compl_delete __ARGS((void));
|
|
159 static void ins_compl_insert __ARGS((void));
|
665
|
160 static int ins_compl_next __ARGS((int allow_get_expansion, int count, int insert_match));
|
610
|
161 static int ins_compl_key2dir __ARGS((int c));
|
644
|
162 static int ins_compl_pum_key __ARGS((int c));
|
610
|
163 static int ins_compl_key2count __ARGS((int c));
|
681
|
164 static int ins_compl_use_match __ARGS((int c));
|
7
|
165 static int ins_complete __ARGS((int c));
|
|
166 static int quote_meta __ARGS((char_u *dest, char_u *str, int len));
|
|
167 #endif /* FEAT_INS_EXPAND */
|
|
168
|
|
169 #define BACKSPACE_CHAR 1
|
|
170 #define BACKSPACE_WORD 2
|
|
171 #define BACKSPACE_WORD_NOT_SPACE 3
|
|
172 #define BACKSPACE_LINE 4
|
|
173
|
661
|
174 static void ins_redraw __ARGS((int ready));
|
7
|
175 static void ins_ctrl_v __ARGS((void));
|
|
176 static void undisplay_dollar __ARGS((void));
|
|
177 static void insert_special __ARGS((int, int, int));
|
667
|
178 static void internal_format __ARGS((int textwidth, int second_indent, int flags, int format_only));
|
7
|
179 static void check_auto_format __ARGS((int));
|
|
180 static void redo_literal __ARGS((int c));
|
|
181 static void start_arrow __ARGS((pos_T *end_insert_pos));
|
744
|
182 #ifdef FEAT_SPELL
|
221
|
183 static void check_spell_redraw __ARGS((void));
|
484
|
184 static void spell_back_to_badword __ARGS((void));
|
497
|
185 static int spell_bad_len = 0; /* length of located bad word */
|
221
|
186 #endif
|
7
|
187 static void stop_insert __ARGS((pos_T *end_insert_pos, int esc));
|
|
188 static int echeck_abbr __ARGS((int));
|
840
|
189 #if 0
|
7
|
190 static void replace_push_off __ARGS((int c));
|
840
|
191 #endif
|
7
|
192 static int replace_pop __ARGS((void));
|
|
193 static void replace_join __ARGS((int off));
|
|
194 static void replace_pop_ins __ARGS((void));
|
|
195 #ifdef FEAT_MBYTE
|
|
196 static void mb_replace_pop_ins __ARGS((int cc));
|
|
197 #endif
|
|
198 static void replace_flush __ARGS((void));
|
|
199 static void replace_do_bs __ARGS((void));
|
|
200 #ifdef FEAT_CINDENT
|
|
201 static int cindent_on __ARGS((void));
|
|
202 #endif
|
|
203 static void ins_reg __ARGS((void));
|
|
204 static void ins_ctrl_g __ARGS((void));
|
449
|
205 static void ins_ctrl_hat __ARGS((void));
|
477
|
206 static int ins_esc __ARGS((long *count, int cmdchar, int nomove));
|
7
|
207 #ifdef FEAT_RIGHTLEFT
|
|
208 static void ins_ctrl_ __ARGS((void));
|
|
209 #endif
|
|
210 #ifdef FEAT_VISUAL
|
|
211 static int ins_start_select __ARGS((int c));
|
|
212 #endif
|
449
|
213 static void ins_insert __ARGS((int replaceState));
|
|
214 static void ins_ctrl_o __ARGS((void));
|
7
|
215 static void ins_shift __ARGS((int c, int lastc));
|
|
216 static void ins_del __ARGS((void));
|
|
217 static int ins_bs __ARGS((int c, int mode, int *inserted_space_p));
|
|
218 #ifdef FEAT_MOUSE
|
|
219 static void ins_mouse __ARGS((int c));
|
|
220 static void ins_mousescroll __ARGS((int up));
|
|
221 #endif
|
692
|
222 #if defined(FEAT_GUI_TABLINE) || defined(PROTO)
|
|
223 static void ins_tabline __ARGS((int c));
|
|
224 #endif
|
7
|
225 static void ins_left __ARGS((void));
|
|
226 static void ins_home __ARGS((int c));
|
|
227 static void ins_end __ARGS((int c));
|
|
228 static void ins_s_left __ARGS((void));
|
|
229 static void ins_right __ARGS((void));
|
|
230 static void ins_s_right __ARGS((void));
|
|
231 static void ins_up __ARGS((int startcol));
|
|
232 static void ins_pageup __ARGS((void));
|
|
233 static void ins_down __ARGS((int startcol));
|
|
234 static void ins_pagedown __ARGS((void));
|
|
235 #ifdef FEAT_DND
|
|
236 static void ins_drop __ARGS((void));
|
|
237 #endif
|
|
238 static int ins_tab __ARGS((void));
|
|
239 static int ins_eol __ARGS((int c));
|
|
240 #ifdef FEAT_DIGRAPHS
|
|
241 static int ins_digraph __ARGS((void));
|
|
242 #endif
|
|
243 static int ins_copychar __ARGS((linenr_T lnum));
|
449
|
244 static int ins_ctrl_ey __ARGS((int tc));
|
7
|
245 #ifdef FEAT_SMARTINDENT
|
|
246 static void ins_try_si __ARGS((int c));
|
|
247 #endif
|
|
248 static colnr_T get_nolist_virtcol __ARGS((void));
|
|
249
|
|
250 static colnr_T Insstart_textlen; /* length of line when insert started */
|
|
251 static colnr_T Insstart_blank_vcol; /* vcol for first inserted blank */
|
|
252
|
|
253 static char_u *last_insert = NULL; /* the text of the previous insert,
|
|
254 K_SPECIAL and CSI are escaped */
|
|
255 static int last_insert_skip; /* nr of chars in front of previous insert */
|
|
256 static int new_insert_skip; /* nr of chars in front of current insert */
|
603
|
257 static int did_restart_edit; /* "restart_edit" when calling edit() */
|
7
|
258
|
|
259 #ifdef FEAT_CINDENT
|
|
260 static int can_cindent; /* may do cindenting on this line */
|
|
261 #endif
|
|
262
|
|
263 static int old_indent = 0; /* for ^^D command in insert mode */
|
|
264
|
|
265 #ifdef FEAT_RIGHTLEFT
|
298
|
266 static int revins_on; /* reverse insert mode on */
|
|
267 static int revins_chars; /* how much to skip after edit */
|
|
268 static int revins_legal; /* was the last char 'legal'? */
|
|
269 static int revins_scol; /* start column of revins session */
|
7
|
270 #endif
|
|
271
|
|
272 static int ins_need_undo; /* call u_save() before inserting a
|
|
273 char. Set when edit() is called.
|
|
274 after that arrow_used is used. */
|
|
275
|
|
276 static int did_add_space = FALSE; /* auto_format() added an extra space
|
|
277 under the cursor */
|
|
278
|
|
279 /*
|
|
280 * edit(): Start inserting text.
|
|
281 *
|
|
282 * "cmdchar" can be:
|
|
283 * 'i' normal insert command
|
|
284 * 'a' normal append command
|
|
285 * 'R' replace command
|
|
286 * 'r' "r<CR>" command: insert one <CR>. Note: count can be > 1, for redo,
|
|
287 * but still only one <CR> is inserted. The <Esc> is not used for redo.
|
|
288 * 'g' "gI" command.
|
|
289 * 'V' "gR" command for Virtual Replace mode.
|
|
290 * 'v' "gr" command for single character Virtual Replace mode.
|
|
291 *
|
|
292 * This function is not called recursively. For CTRL-O commands, it returns
|
|
293 * and lets the caller handle the Normal-mode command.
|
|
294 *
|
|
295 * Return TRUE if a CTRL-O command caused the return (insert mode pending).
|
|
296 */
|
|
297 int
|
|
298 edit(cmdchar, startln, count)
|
|
299 int cmdchar;
|
|
300 int startln; /* if set, insert at start of line */
|
|
301 long count;
|
|
302 {
|
|
303 int c = 0;
|
|
304 char_u *ptr;
|
|
305 int lastc;
|
|
306 colnr_T mincol;
|
|
307 static linenr_T o_lnum = 0;
|
|
308 int i;
|
|
309 int did_backspace = TRUE; /* previous char was backspace */
|
|
310 #ifdef FEAT_CINDENT
|
|
311 int line_is_white = FALSE; /* line is empty before insert */
|
|
312 #endif
|
|
313 linenr_T old_topline = 0; /* topline before insertion */
|
|
314 #ifdef FEAT_DIFF
|
|
315 int old_topfill = -1;
|
|
316 #endif
|
|
317 int inserted_space = FALSE; /* just inserted a space */
|
|
318 int replaceState = REPLACE;
|
477
|
319 int nomove = FALSE; /* don't move cursor on return */
|
7
|
320
|
603
|
321 /* Remember whether editing was restarted after CTRL-O. */
|
|
322 did_restart_edit = restart_edit;
|
|
323
|
7
|
324 /* sleep before redrawing, needed for "CTRL-O :" that results in an
|
|
325 * error message */
|
|
326 check_for_delay(TRUE);
|
|
327
|
|
328 #ifdef HAVE_SANDBOX
|
|
329 /* Don't allow inserting in the sandbox. */
|
|
330 if (sandbox != 0)
|
|
331 {
|
|
332 EMSG(_(e_sandbox));
|
|
333 return FALSE;
|
|
334 }
|
|
335 #endif
|
632
|
336 /* Don't allow changes in the buffer while editing the cmdline. The
|
|
337 * caller of getcmdline() may get confused. */
|
634
|
338 if (textlock != 0)
|
632
|
339 {
|
|
340 EMSG(_(e_secure));
|
|
341 return FALSE;
|
|
342 }
|
7
|
343
|
|
344 #ifdef FEAT_INS_EXPAND
|
844
|
345 /* Don't allow recursive insert mode when busy with completion. */
|
|
346 if (compl_started || pum_visible())
|
|
347 {
|
|
348 EMSG(_(e_secure));
|
|
349 return FALSE;
|
|
350 }
|
7
|
351 ins_compl_clear(); /* clear stuff for CTRL-X mode */
|
|
352 #endif
|
|
353
|
11
|
354 #ifdef FEAT_AUTOCMD
|
|
355 /*
|
|
356 * Trigger InsertEnter autocommands. Do not do this for "r<CR>" or "grx".
|
|
357 */
|
|
358 if (cmdchar != 'r' && cmdchar != 'v')
|
|
359 {
|
532
|
360 # ifdef FEAT_EVAL
|
11
|
361 if (cmdchar == 'R')
|
|
362 ptr = (char_u *)"r";
|
|
363 else if (cmdchar == 'V')
|
|
364 ptr = (char_u *)"v";
|
|
365 else
|
|
366 ptr = (char_u *)"i";
|
|
367 set_vim_var_string(VV_INSERTMODE, ptr, 1);
|
532
|
368 # endif
|
11
|
369 apply_autocmds(EVENT_INSERTENTER, NULL, NULL, FALSE, curbuf);
|
|
370 }
|
|
371 #endif
|
|
372
|
7
|
373 #ifdef FEAT_MOUSE
|
|
374 /*
|
|
375 * When doing a paste with the middle mouse button, Insstart is set to
|
|
376 * where the paste started.
|
|
377 */
|
|
378 if (where_paste_started.lnum != 0)
|
|
379 Insstart = where_paste_started;
|
|
380 else
|
|
381 #endif
|
|
382 {
|
|
383 Insstart = curwin->w_cursor;
|
|
384 if (startln)
|
|
385 Insstart.col = 0;
|
|
386 }
|
|
387 Insstart_textlen = linetabsize(ml_get_curline());
|
|
388 Insstart_blank_vcol = MAXCOL;
|
|
389 if (!did_ai)
|
|
390 ai_col = 0;
|
|
391
|
|
392 if (cmdchar != NUL && restart_edit == 0)
|
|
393 {
|
|
394 ResetRedobuff();
|
|
395 AppendNumberToRedobuff(count);
|
|
396 #ifdef FEAT_VREPLACE
|
|
397 if (cmdchar == 'V' || cmdchar == 'v')
|
|
398 {
|
|
399 /* "gR" or "gr" command */
|
|
400 AppendCharToRedobuff('g');
|
|
401 AppendCharToRedobuff((cmdchar == 'v') ? 'r' : 'R');
|
|
402 }
|
|
403 else
|
|
404 #endif
|
|
405 {
|
|
406 AppendCharToRedobuff(cmdchar);
|
|
407 if (cmdchar == 'g') /* "gI" command */
|
|
408 AppendCharToRedobuff('I');
|
|
409 else if (cmdchar == 'r') /* "r<CR>" command */
|
|
410 count = 1; /* insert only one <CR> */
|
|
411 }
|
|
412 }
|
|
413
|
|
414 if (cmdchar == 'R')
|
|
415 {
|
|
416 #ifdef FEAT_FKMAP
|
|
417 if (p_fkmap && p_ri)
|
|
418 {
|
|
419 beep_flush();
|
|
420 EMSG(farsi_text_3); /* encoded in Farsi */
|
|
421 State = INSERT;
|
|
422 }
|
|
423 else
|
|
424 #endif
|
|
425 State = REPLACE;
|
|
426 }
|
|
427 #ifdef FEAT_VREPLACE
|
|
428 else if (cmdchar == 'V' || cmdchar == 'v')
|
|
429 {
|
|
430 State = VREPLACE;
|
|
431 replaceState = VREPLACE;
|
|
432 orig_line_count = curbuf->b_ml.ml_line_count;
|
|
433 vr_lines_changed = 1;
|
|
434 }
|
|
435 #endif
|
|
436 else
|
|
437 State = INSERT;
|
|
438
|
|
439 stop_insert_mode = FALSE;
|
|
440
|
|
441 /*
|
|
442 * Need to recompute the cursor position, it might move when the cursor is
|
|
443 * on a TAB or special character.
|
|
444 */
|
|
445 curs_columns(TRUE);
|
|
446
|
|
447 /*
|
|
448 * Enable langmap or IME, indicated by 'iminsert'.
|
|
449 * Note that IME may enabled/disabled without us noticing here, thus the
|
|
450 * 'iminsert' value may not reflect what is actually used. It is updated
|
|
451 * when hitting <Esc>.
|
|
452 */
|
|
453 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
|
|
454 State |= LANGMAP;
|
|
455 #ifdef USE_IM_CONTROL
|
|
456 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
|
|
457 #endif
|
|
458
|
|
459 #ifdef FEAT_MOUSE
|
|
460 setmouse();
|
|
461 #endif
|
|
462 #ifdef FEAT_CMDL_INFO
|
|
463 clear_showcmd();
|
|
464 #endif
|
|
465 #ifdef FEAT_RIGHTLEFT
|
|
466 /* there is no reverse replace mode */
|
|
467 revins_on = (State == INSERT && p_ri);
|
|
468 if (revins_on)
|
|
469 undisplay_dollar();
|
|
470 revins_chars = 0;
|
|
471 revins_legal = 0;
|
|
472 revins_scol = -1;
|
|
473 #endif
|
|
474
|
|
475 /*
|
|
476 * Handle restarting Insert mode.
|
|
477 * Don't do this for "CTRL-O ." (repeat an insert): we get here with
|
|
478 * restart_edit non-zero, and something in the stuff buffer.
|
|
479 */
|
|
480 if (restart_edit != 0 && stuff_empty())
|
|
481 {
|
|
482 #ifdef FEAT_MOUSE
|
|
483 /*
|
|
484 * After a paste we consider text typed to be part of the insert for
|
|
485 * the pasted text. You can backspace over the pasted text too.
|
|
486 */
|
|
487 if (where_paste_started.lnum)
|
|
488 arrow_used = FALSE;
|
|
489 else
|
|
490 #endif
|
|
491 arrow_used = TRUE;
|
|
492 restart_edit = 0;
|
|
493
|
|
494 /*
|
|
495 * If the cursor was after the end-of-line before the CTRL-O and it is
|
|
496 * now at the end-of-line, put it after the end-of-line (this is not
|
|
497 * correct in very rare cases).
|
|
498 * Also do this if curswant is greater than the current virtual
|
|
499 * column. Eg after "^O$" or "^O80|".
|
|
500 */
|
|
501 validate_virtcol();
|
|
502 update_curswant();
|
230
|
503 if (((ins_at_eol && curwin->w_cursor.lnum == o_lnum)
|
7
|
504 || curwin->w_curswant > curwin->w_virtcol)
|
|
505 && *(ptr = ml_get_curline() + curwin->w_cursor.col) != NUL)
|
|
506 {
|
|
507 if (ptr[1] == NUL)
|
|
508 ++curwin->w_cursor.col;
|
|
509 #ifdef FEAT_MBYTE
|
|
510 else if (has_mbyte)
|
|
511 {
|
474
|
512 i = (*mb_ptr2len)(ptr);
|
7
|
513 if (ptr[i] == NUL)
|
|
514 curwin->w_cursor.col += i;
|
|
515 }
|
|
516 #endif
|
|
517 }
|
230
|
518 ins_at_eol = FALSE;
|
7
|
519 }
|
|
520 else
|
|
521 arrow_used = FALSE;
|
|
522
|
|
523 /* we are in insert mode now, don't need to start it anymore */
|
|
524 need_start_insertmode = FALSE;
|
|
525
|
|
526 /* Need to save the line for undo before inserting the first char. */
|
|
527 ins_need_undo = TRUE;
|
|
528
|
|
529 #ifdef FEAT_MOUSE
|
|
530 where_paste_started.lnum = 0;
|
|
531 #endif
|
|
532 #ifdef FEAT_CINDENT
|
|
533 can_cindent = TRUE;
|
|
534 #endif
|
|
535 #ifdef FEAT_FOLDING
|
|
536 /* The cursor line is not in a closed fold, unless 'insertmode' is set or
|
|
537 * restarting. */
|
|
538 if (!p_im && did_restart_edit == 0)
|
|
539 foldOpenCursor();
|
|
540 #endif
|
|
541
|
|
542 /*
|
|
543 * If 'showmode' is set, show the current (insert/replace/..) mode.
|
|
544 * A warning message for changing a readonly file is given here, before
|
|
545 * actually changing anything. It's put after the mode, if any.
|
|
546 */
|
|
547 i = 0;
|
644
|
548 if (p_smd && msg_silent == 0)
|
7
|
549 i = showmode();
|
|
550
|
|
551 if (!p_im && did_restart_edit == 0)
|
|
552 change_warning(i + 1);
|
|
553
|
|
554 #ifdef CURSOR_SHAPE
|
|
555 ui_cursor_shape(); /* may show different cursor shape */
|
|
556 #endif
|
|
557 #ifdef FEAT_DIGRAPHS
|
|
558 do_digraph(-1); /* clear digraphs */
|
|
559 #endif
|
|
560
|
603
|
561 /*
|
|
562 * Get the current length of the redo buffer, those characters have to be
|
|
563 * skipped if we want to get to the inserted characters.
|
|
564 */
|
7
|
565 ptr = get_inserted();
|
|
566 if (ptr == NULL)
|
|
567 new_insert_skip = 0;
|
|
568 else
|
|
569 {
|
|
570 new_insert_skip = (int)STRLEN(ptr);
|
|
571 vim_free(ptr);
|
|
572 }
|
|
573
|
|
574 old_indent = 0;
|
|
575
|
|
576 /*
|
|
577 * Main loop in Insert mode: repeat until Insert mode is left.
|
|
578 */
|
|
579 for (;;)
|
|
580 {
|
|
581 #ifdef FEAT_RIGHTLEFT
|
|
582 if (!revins_legal)
|
|
583 revins_scol = -1; /* reset on illegal motions */
|
|
584 else
|
|
585 revins_legal = 0;
|
|
586 #endif
|
|
587 if (arrow_used) /* don't repeat insert when arrow key used */
|
|
588 count = 0;
|
|
589
|
|
590 if (stop_insert_mode)
|
|
591 {
|
|
592 /* ":stopinsert" used or 'insertmode' reset */
|
|
593 count = 0;
|
|
594 goto doESCkey;
|
|
595 }
|
|
596
|
|
597 /* set curwin->w_curswant for next K_DOWN or K_UP */
|
|
598 if (!arrow_used)
|
|
599 curwin->w_set_curswant = TRUE;
|
|
600
|
|
601 /* If there is no typeahead may check for timestamps (e.g., for when a
|
|
602 * menu invoked a shell command). */
|
|
603 if (stuff_empty())
|
|
604 {
|
|
605 did_check_timestamps = FALSE;
|
|
606 if (need_check_timestamps)
|
|
607 check_timestamps(FALSE);
|
|
608 }
|
|
609
|
|
610 /*
|
|
611 * When emsg() was called msg_scroll will have been set.
|
|
612 */
|
|
613 msg_scroll = FALSE;
|
|
614
|
|
615 #ifdef FEAT_GUI
|
|
616 /* When 'mousefocus' is set a mouse movement may have taken us to
|
|
617 * another window. "need_mouse_correct" may then be set because of an
|
|
618 * autocommand. */
|
|
619 if (need_mouse_correct)
|
|
620 gui_mouse_correct();
|
|
621 #endif
|
|
622
|
|
623 #ifdef FEAT_FOLDING
|
|
624 /* Open fold at the cursor line, according to 'foldopen'. */
|
|
625 if (fdo_flags & FDO_INSERT)
|
|
626 foldOpenCursor();
|
|
627 /* Close folds where the cursor isn't, according to 'foldclose' */
|
|
628 if (!char_avail())
|
|
629 foldCheckClose();
|
|
630 #endif
|
|
631
|
|
632 /*
|
|
633 * If we inserted a character at the last position of the last line in
|
|
634 * the window, scroll the window one line up. This avoids an extra
|
|
635 * redraw.
|
|
636 * This is detected when the cursor column is smaller after inserting
|
|
637 * something.
|
|
638 * Don't do this when the topline changed already, it has
|
|
639 * already been adjusted (by insertchar() calling open_line())).
|
|
640 */
|
|
641 if (curbuf->b_mod_set
|
|
642 && curwin->w_p_wrap
|
|
643 && !did_backspace
|
|
644 && curwin->w_topline == old_topline
|
|
645 #ifdef FEAT_DIFF
|
|
646 && curwin->w_topfill == old_topfill
|
|
647 #endif
|
|
648 )
|
|
649 {
|
|
650 mincol = curwin->w_wcol;
|
|
651 validate_cursor_col();
|
|
652
|
|
653 if ((int)curwin->w_wcol < (int)mincol - curbuf->b_p_ts
|
|
654 && curwin->w_wrow == W_WINROW(curwin)
|
|
655 + curwin->w_height - 1 - p_so
|
|
656 && (curwin->w_cursor.lnum != curwin->w_topline
|
|
657 #ifdef FEAT_DIFF
|
|
658 || curwin->w_topfill > 0
|
|
659 #endif
|
|
660 ))
|
|
661 {
|
|
662 #ifdef FEAT_DIFF
|
|
663 if (curwin->w_topfill > 0)
|
|
664 --curwin->w_topfill;
|
|
665 else
|
|
666 #endif
|
|
667 #ifdef FEAT_FOLDING
|
|
668 if (hasFolding(curwin->w_topline, NULL, &old_topline))
|
|
669 set_topline(curwin, old_topline + 1);
|
|
670 else
|
|
671 #endif
|
|
672 set_topline(curwin, curwin->w_topline + 1);
|
|
673 }
|
|
674 }
|
|
675
|
|
676 /* May need to adjust w_topline to show the cursor. */
|
|
677 update_topline();
|
|
678
|
|
679 did_backspace = FALSE;
|
|
680
|
|
681 validate_cursor(); /* may set must_redraw */
|
|
682
|
|
683 /*
|
|
684 * Redraw the display when no characters are waiting.
|
|
685 * Also shows mode, ruler and positions cursor.
|
|
686 */
|
661
|
687 ins_redraw(TRUE);
|
7
|
688
|
|
689 #ifdef FEAT_SCROLLBIND
|
|
690 if (curwin->w_p_scb)
|
|
691 do_check_scrollbind(TRUE);
|
|
692 #endif
|
|
693
|
|
694 update_curswant();
|
|
695 old_topline = curwin->w_topline;
|
|
696 #ifdef FEAT_DIFF
|
|
697 old_topfill = curwin->w_topfill;
|
|
698 #endif
|
|
699
|
|
700 #ifdef USE_ON_FLY_SCROLL
|
|
701 dont_scroll = FALSE; /* allow scrolling here */
|
|
702 #endif
|
|
703
|
|
704 /*
|
|
705 * Get a character for Insert mode.
|
|
706 */
|
|
707 lastc = c; /* remember previous char for CTRL-D */
|
|
708 c = safe_vgetc();
|
|
709
|
|
710 #ifdef FEAT_RIGHTLEFT
|
|
711 if (p_hkmap && KeyTyped)
|
|
712 c = hkmap(c); /* Hebrew mode mapping */
|
|
713 #endif
|
|
714 #ifdef FEAT_FKMAP
|
|
715 if (p_fkmap && KeyTyped)
|
|
716 c = fkmap(c); /* Farsi mode mapping */
|
|
717 #endif
|
|
718
|
|
719 #ifdef FEAT_INS_EXPAND
|
659
|
720 /*
|
|
721 * Special handling of keys while the popup menu is visible or wanted
|
897
|
722 * and the cursor is still in the completed word. Only when there is
|
|
723 * a match, skip this when no matches were found.
|
659
|
724 */
|
897
|
725 if (compl_started
|
|
726 && pum_wanted()
|
|
727 && curwin->w_cursor.col >= compl_col
|
|
728 && (compl_shown_match == NULL
|
|
729 || compl_shown_match != compl_shown_match->cp_next))
|
659
|
730 {
|
|
731 /* BS: Delete one character from "compl_leader". */
|
|
732 if ((c == K_BS || c == Ctrl_H)
|
836
|
733 && curwin->w_cursor.col > compl_col
|
|
734 && (c = ins_compl_bs()) == NUL)
|
657
|
735 continue;
|
|
736
|
659
|
737 /* When no match was selected or it was edited. */
|
|
738 if (!compl_used_match)
|
657
|
739 {
|
659
|
740 /* CTRL-L: Add one character from the current match to
|
836
|
741 * "compl_leader". Except when at the original match and
|
|
742 * there is nothing to add, CTRL-L works like CTRL-P then. */
|
|
743 if (c == Ctrl_L
|
|
744 && (ctrl_x_mode != CTRL_X_WHOLE_LINE
|
|
745 || STRLEN(compl_shown_match->cp_str)
|
|
746 > curwin->w_cursor.col - compl_col))
|
659
|
747 {
|
|
748 ins_compl_addfrommatch();
|
|
749 continue;
|
|
750 }
|
|
751
|
683
|
752 /* A printable, non-white character: Add to "compl_leader". */
|
|
753 if (vim_isprintc(c) && !vim_iswhite(c))
|
659
|
754 {
|
|
755 ins_compl_addleader(c);
|
|
756 continue;
|
|
757 }
|
665
|
758
|
887
|
759 /* Pressing CTRL-Y selects the current match. When
|
825
|
760 * compl_enter_selects is set the Enter key does the same. */
|
|
761 if (c == Ctrl_Y || (compl_enter_selects
|
|
762 && (c == CAR || c == K_KENTER || c == NL)))
|
665
|
763 {
|
|
764 ins_compl_delete();
|
|
765 ins_compl_insert();
|
|
766 }
|
657
|
767 }
|
|
768 }
|
|
769
|
7
|
770 /* Prepare for or stop CTRL-X mode. This doesn't do completion, but
|
|
771 * it does fix up the text when finishing completion. */
|
665
|
772 compl_get_longest = FALSE;
|
657
|
773 if (c != K_IGNORE && ins_compl_prep(c))
|
|
774 continue;
|
7
|
775 #endif
|
|
776
|
477
|
777 /* CTRL-\ CTRL-N goes to Normal mode,
|
|
778 * CTRL-\ CTRL-G goes to mode selected with 'insertmode',
|
|
779 * CTRL-\ CTRL-O is like CTRL-O but without moving the cursor. */
|
7
|
780 if (c == Ctrl_BSL)
|
|
781 {
|
|
782 /* may need to redraw when no more chars available now */
|
661
|
783 ins_redraw(FALSE);
|
7
|
784 ++no_mapping;
|
|
785 ++allow_keys;
|
|
786 c = safe_vgetc();
|
|
787 --no_mapping;
|
|
788 --allow_keys;
|
477
|
789 if (c != Ctrl_N && c != Ctrl_G && c != Ctrl_O)
|
7
|
790 {
|
477
|
791 /* it's something else */
|
7
|
792 vungetc(c);
|
|
793 c = Ctrl_BSL;
|
|
794 }
|
|
795 else if (c == Ctrl_G && p_im)
|
|
796 continue;
|
|
797 else
|
|
798 {
|
477
|
799 if (c == Ctrl_O)
|
|
800 {
|
|
801 ins_ctrl_o();
|
|
802 ins_at_eol = FALSE; /* cursor keeps its column */
|
|
803 nomove = TRUE;
|
|
804 }
|
7
|
805 count = 0;
|
|
806 goto doESCkey;
|
|
807 }
|
|
808 }
|
|
809
|
|
810 #ifdef FEAT_DIGRAPHS
|
|
811 c = do_digraph(c);
|
|
812 #endif
|
|
813
|
|
814 #ifdef FEAT_INS_EXPAND
|
|
815 if ((c == Ctrl_V || c == Ctrl_Q) && ctrl_x_mode == CTRL_X_CMDLINE)
|
|
816 goto docomplete;
|
|
817 #endif
|
|
818 if (c == Ctrl_V || c == Ctrl_Q)
|
|
819 {
|
|
820 ins_ctrl_v();
|
|
821 c = Ctrl_V; /* pretend CTRL-V is last typed character */
|
|
822 continue;
|
|
823 }
|
|
824
|
|
825 #ifdef FEAT_CINDENT
|
|
826 if (cindent_on()
|
|
827 # ifdef FEAT_INS_EXPAND
|
|
828 && ctrl_x_mode == 0
|
|
829 # endif
|
|
830 )
|
|
831 {
|
|
832 /* A key name preceded by a bang means this key is not to be
|
|
833 * inserted. Skip ahead to the re-indenting below.
|
|
834 * A key name preceded by a star means that indenting has to be
|
|
835 * done before inserting the key. */
|
|
836 line_is_white = inindent(0);
|
|
837 if (in_cinkeys(c, '!', line_is_white))
|
|
838 goto force_cindent;
|
|
839 if (can_cindent && in_cinkeys(c, '*', line_is_white)
|
|
840 && stop_arrow() == OK)
|
|
841 do_c_expr_indent();
|
|
842 }
|
|
843 #endif
|
|
844
|
|
845 #ifdef FEAT_RIGHTLEFT
|
|
846 if (curwin->w_p_rl)
|
|
847 switch (c)
|
|
848 {
|
|
849 case K_LEFT: c = K_RIGHT; break;
|
|
850 case K_S_LEFT: c = K_S_RIGHT; break;
|
|
851 case K_C_LEFT: c = K_C_RIGHT; break;
|
|
852 case K_RIGHT: c = K_LEFT; break;
|
|
853 case K_S_RIGHT: c = K_S_LEFT; break;
|
|
854 case K_C_RIGHT: c = K_C_LEFT; break;
|
|
855 }
|
|
856 #endif
|
|
857
|
|
858 #ifdef FEAT_VISUAL
|
|
859 /*
|
|
860 * If 'keymodel' contains "startsel", may start selection. If it
|
|
861 * does, a CTRL-O and c will be stuffed, we need to get these
|
|
862 * characters.
|
|
863 */
|
|
864 if (ins_start_select(c))
|
|
865 continue;
|
|
866 #endif
|
|
867
|
|
868 /*
|
|
869 * The big switch to handle a character in insert mode.
|
|
870 */
|
|
871 switch (c)
|
|
872 {
|
449
|
873 case ESC: /* End input mode */
|
7
|
874 if (echeck_abbr(ESC + ABBR_OFF))
|
|
875 break;
|
|
876 /*FALLTHROUGH*/
|
|
877
|
449
|
878 case Ctrl_C: /* End input mode */
|
7
|
879 #ifdef FEAT_CMDWIN
|
|
880 if (c == Ctrl_C && cmdwin_type != 0)
|
|
881 {
|
|
882 /* Close the cmdline window. */
|
|
883 cmdwin_result = K_IGNORE;
|
|
884 got_int = FALSE; /* don't stop executing autocommands et al. */
|
|
885 goto doESCkey;
|
|
886 }
|
|
887 #endif
|
|
888
|
|
889 #ifdef UNIX
|
|
890 do_intr:
|
|
891 #endif
|
|
892 /* when 'insertmode' set, and not halfway a mapping, don't leave
|
|
893 * Insert mode */
|
|
894 if (goto_im())
|
|
895 {
|
|
896 if (got_int)
|
|
897 {
|
|
898 (void)vgetc(); /* flush all buffers */
|
|
899 got_int = FALSE;
|
|
900 }
|
|
901 else
|
|
902 vim_beep();
|
|
903 break;
|
|
904 }
|
|
905 doESCkey:
|
|
906 /*
|
|
907 * This is the ONLY return from edit()!
|
|
908 */
|
|
909 /* Always update o_lnum, so that a "CTRL-O ." that adds a line
|
|
910 * still puts the cursor back after the inserted text. */
|
230
|
911 if (ins_at_eol && gchar_cursor() == NUL)
|
7
|
912 o_lnum = curwin->w_cursor.lnum;
|
|
913
|
477
|
914 if (ins_esc(&count, cmdchar, nomove))
|
11
|
915 {
|
|
916 #ifdef FEAT_AUTOCMD
|
|
917 if (cmdchar != 'r' && cmdchar != 'v')
|
|
918 apply_autocmds(EVENT_INSERTLEAVE, NULL, NULL,
|
|
919 FALSE, curbuf);
|
|
920 #endif
|
7
|
921 return (c == Ctrl_O);
|
11
|
922 }
|
7
|
923 continue;
|
|
924
|
449
|
925 case Ctrl_Z: /* suspend when 'insertmode' set */
|
|
926 if (!p_im)
|
|
927 goto normalchar; /* insert CTRL-Z as normal char */
|
|
928 stuffReadbuff((char_u *)":st\r");
|
|
929 c = Ctrl_O;
|
|
930 /*FALLTHROUGH*/
|
|
931
|
|
932 case Ctrl_O: /* execute one command */
|
502
|
933 #ifdef FEAT_COMPL_FUNC
|
523
|
934 if (ctrl_x_mode == CTRL_X_OMNI)
|
449
|
935 goto docomplete;
|
|
936 #endif
|
|
937 if (echeck_abbr(Ctrl_O + ABBR_OFF))
|
|
938 break;
|
|
939 ins_ctrl_o();
|
853
|
940
|
|
941 #ifdef FEAT_VIRTUALEDIT
|
|
942 /* don't move the cursor left when 'virtualedit' has "onemore". */
|
|
943 if (ve_flags & VE_ONEMORE)
|
|
944 {
|
|
945 ins_at_eol = FALSE;
|
|
946 nomove = TRUE;
|
|
947 }
|
|
948 #endif
|
449
|
949 count = 0;
|
|
950 goto doESCkey;
|
|
951
|
464
|
952 case K_INS: /* toggle insert/replace mode */
|
|
953 case K_KINS:
|
|
954 ins_insert(replaceState);
|
|
955 break;
|
|
956
|
|
957 case K_SELECT: /* end of Select mode mapping - ignore */
|
|
958 break;
|
|
959
|
449
|
960 #ifdef FEAT_SNIFF
|
|
961 case K_SNIFF: /* Sniff command received */
|
|
962 stuffcharReadbuff(K_SNIFF);
|
|
963 goto doESCkey;
|
|
964 #endif
|
|
965
|
|
966 case K_HELP: /* Help key works like <ESC> <Help> */
|
|
967 case K_F1:
|
|
968 case K_XF1:
|
|
969 stuffcharReadbuff(K_HELP);
|
|
970 if (p_im)
|
|
971 need_start_insertmode = TRUE;
|
|
972 goto doESCkey;
|
|
973
|
|
974 #ifdef FEAT_NETBEANS_INTG
|
|
975 case K_F21: /* NetBeans command */
|
|
976 ++no_mapping; /* don't map the next key hits */
|
|
977 i = safe_vgetc();
|
|
978 --no_mapping;
|
|
979 netbeans_keycommand(i);
|
|
980 break;
|
|
981 #endif
|
|
982
|
|
983 case K_ZERO: /* Insert the previously inserted text. */
|
7
|
984 case NUL:
|
|
985 case Ctrl_A:
|
449
|
986 /* For ^@ the trailing ESC will end the insert, unless there is an
|
|
987 * error. */
|
7
|
988 if (stuff_inserted(NUL, 1L, (c == Ctrl_A)) == FAIL
|
|
989 && c != Ctrl_A && !p_im)
|
|
990 goto doESCkey; /* quit insert mode */
|
|
991 inserted_space = FALSE;
|
|
992 break;
|
|
993
|
449
|
994 case Ctrl_R: /* insert the contents of a register */
|
7
|
995 ins_reg();
|
|
996 auto_format(FALSE, TRUE);
|
|
997 inserted_space = FALSE;
|
|
998 break;
|
|
999
|
449
|
1000 case Ctrl_G: /* commands starting with CTRL-G */
|
7
|
1001 ins_ctrl_g();
|
|
1002 break;
|
|
1003
|
449
|
1004 case Ctrl_HAT: /* switch input mode and/or langmap */
|
|
1005 ins_ctrl_hat();
|
7
|
1006 break;
|
|
1007
|
|
1008 #ifdef FEAT_RIGHTLEFT
|
449
|
1009 case Ctrl__: /* switch between languages */
|
7
|
1010 if (!p_ari)
|
|
1011 goto normalchar;
|
|
1012 ins_ctrl_();
|
|
1013 break;
|
|
1014 #endif
|
|
1015
|
449
|
1016 case Ctrl_D: /* Make indent one shiftwidth smaller. */
|
7
|
1017 #if defined(FEAT_INS_EXPAND) && defined(FEAT_FIND_ID)
|
|
1018 if (ctrl_x_mode == CTRL_X_PATH_DEFINES)
|
|
1019 goto docomplete;
|
|
1020 #endif
|
|
1021 /* FALLTHROUGH */
|
|
1022
|
449
|
1023 case Ctrl_T: /* Make indent one shiftwidth greater. */
|
7
|
1024 # ifdef FEAT_INS_EXPAND
|
|
1025 if (c == Ctrl_T && ctrl_x_mode == CTRL_X_THESAURUS)
|
|
1026 {
|
449
|
1027 if (has_compl_option(FALSE))
|
|
1028 goto docomplete;
|
|
1029 break;
|
7
|
1030 }
|
|
1031 # endif
|
|
1032 ins_shift(c, lastc);
|
|
1033 auto_format(FALSE, TRUE);
|
|
1034 inserted_space = FALSE;
|
|
1035 break;
|
|
1036
|
449
|
1037 case K_DEL: /* delete character under the cursor */
|
7
|
1038 case K_KDEL:
|
|
1039 ins_del();
|
|
1040 auto_format(FALSE, TRUE);
|
|
1041 break;
|
|
1042
|
449
|
1043 case K_BS: /* delete character before the cursor */
|
7
|
1044 case Ctrl_H:
|
|
1045 did_backspace = ins_bs(c, BACKSPACE_CHAR, &inserted_space);
|
|
1046 auto_format(FALSE, TRUE);
|
|
1047 break;
|
|
1048
|
449
|
1049 case Ctrl_W: /* delete word before the cursor */
|
7
|
1050 did_backspace = ins_bs(c, BACKSPACE_WORD, &inserted_space);
|
|
1051 auto_format(FALSE, TRUE);
|
|
1052 break;
|
|
1053
|
449
|
1054 case Ctrl_U: /* delete all inserted text in current line */
|
12
|
1055 # ifdef FEAT_COMPL_FUNC
|
|
1056 /* CTRL-X CTRL-U completes with 'completefunc'. */
|
449
|
1057 if (ctrl_x_mode == CTRL_X_FUNCTION)
|
12
|
1058 goto docomplete;
|
|
1059 # endif
|
7
|
1060 did_backspace = ins_bs(c, BACKSPACE_LINE, &inserted_space);
|
|
1061 auto_format(FALSE, TRUE);
|
|
1062 inserted_space = FALSE;
|
|
1063 break;
|
|
1064
|
|
1065 #ifdef FEAT_MOUSE
|
449
|
1066 case K_LEFTMOUSE: /* mouse keys */
|
7
|
1067 case K_LEFTMOUSE_NM:
|
|
1068 case K_LEFTDRAG:
|
|
1069 case K_LEFTRELEASE:
|
|
1070 case K_LEFTRELEASE_NM:
|
|
1071 case K_MIDDLEMOUSE:
|
|
1072 case K_MIDDLEDRAG:
|
|
1073 case K_MIDDLERELEASE:
|
|
1074 case K_RIGHTMOUSE:
|
|
1075 case K_RIGHTDRAG:
|
|
1076 case K_RIGHTRELEASE:
|
|
1077 case K_X1MOUSE:
|
|
1078 case K_X1DRAG:
|
|
1079 case K_X1RELEASE:
|
|
1080 case K_X2MOUSE:
|
|
1081 case K_X2DRAG:
|
|
1082 case K_X2RELEASE:
|
|
1083 ins_mouse(c);
|
|
1084 break;
|
|
1085
|
449
|
1086 case K_MOUSEDOWN: /* Default action for scroll wheel up: scroll up */
|
7
|
1087 ins_mousescroll(FALSE);
|
|
1088 break;
|
|
1089
|
449
|
1090 case K_MOUSEUP: /* Default action for scroll wheel down: scroll down */
|
7
|
1091 ins_mousescroll(TRUE);
|
|
1092 break;
|
|
1093 #endif
|
692
|
1094 #ifdef FEAT_GUI_TABLINE
|
|
1095 case K_TABLINE:
|
|
1096 case K_TABMENU:
|
|
1097 ins_tabline(c);
|
|
1098 break;
|
|
1099 #endif
|
7
|
1100
|
449
|
1101 case K_IGNORE: /* Something mapped to nothing */
|
7
|
1102 break;
|
|
1103
|
661
|
1104 #ifdef FEAT_AUTOCMD
|
|
1105 case K_CURSORHOLD: /* Didn't type something for a while. */
|
|
1106 apply_autocmds(EVENT_CURSORHOLDI, NULL, NULL, FALSE, curbuf);
|
|
1107 did_cursorhold = TRUE;
|
|
1108 break;
|
|
1109 #endif
|
|
1110
|
625
|
1111 #ifdef FEAT_GUI_W32
|
|
1112 /* On Win32 ignore <M-F4>, we get it when closing the window was
|
|
1113 * cancelled. */
|
|
1114 case K_F4:
|
|
1115 if (mod_mask != MOD_MASK_ALT)
|
|
1116 goto normalchar;
|
|
1117 break;
|
|
1118 #endif
|
|
1119
|
7
|
1120 #ifdef FEAT_GUI
|
|
1121 case K_VER_SCROLLBAR:
|
|
1122 ins_scroll();
|
|
1123 break;
|
|
1124
|
|
1125 case K_HOR_SCROLLBAR:
|
|
1126 ins_horscroll();
|
|
1127 break;
|
|
1128 #endif
|
|
1129
|
449
|
1130 case K_HOME: /* <Home> */
|
7
|
1131 case K_KHOME:
|
|
1132 case K_S_HOME:
|
|
1133 case K_C_HOME:
|
|
1134 ins_home(c);
|
|
1135 break;
|
|
1136
|
449
|
1137 case K_END: /* <End> */
|
7
|
1138 case K_KEND:
|
|
1139 case K_S_END:
|
|
1140 case K_C_END:
|
|
1141 ins_end(c);
|
|
1142 break;
|
|
1143
|
449
|
1144 case K_LEFT: /* <Left> */
|
180
|
1145 if (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))
|
|
1146 ins_s_left();
|
|
1147 else
|
|
1148 ins_left();
|
7
|
1149 break;
|
|
1150
|
449
|
1151 case K_S_LEFT: /* <S-Left> */
|
7
|
1152 case K_C_LEFT:
|
|
1153 ins_s_left();
|
|
1154 break;
|
|
1155
|
449
|
1156 case K_RIGHT: /* <Right> */
|
180
|
1157 if (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))
|
|
1158 ins_s_right();
|
|
1159 else
|
|
1160 ins_right();
|
7
|
1161 break;
|
|
1162
|
449
|
1163 case K_S_RIGHT: /* <S-Right> */
|
7
|
1164 case K_C_RIGHT:
|
|
1165 ins_s_right();
|
|
1166 break;
|
|
1167
|
449
|
1168 case K_UP: /* <Up> */
|
665
|
1169 #ifdef FEAT_INS_EXPAND
|
|
1170 if (pum_visible())
|
|
1171 goto docomplete;
|
|
1172 #endif
|
180
|
1173 if (mod_mask & MOD_MASK_SHIFT)
|
|
1174 ins_pageup();
|
|
1175 else
|
|
1176 ins_up(FALSE);
|
7
|
1177 break;
|
|
1178
|
449
|
1179 case K_S_UP: /* <S-Up> */
|
7
|
1180 case K_PAGEUP:
|
|
1181 case K_KPAGEUP:
|
613
|
1182 #ifdef FEAT_INS_EXPAND
|
610
|
1183 if (pum_visible())
|
|
1184 goto docomplete;
|
613
|
1185 #endif
|
7
|
1186 ins_pageup();
|
|
1187 break;
|
|
1188
|
449
|
1189 case K_DOWN: /* <Down> */
|
665
|
1190 #ifdef FEAT_INS_EXPAND
|
|
1191 if (pum_visible())
|
|
1192 goto docomplete;
|
|
1193 #endif
|
180
|
1194 if (mod_mask & MOD_MASK_SHIFT)
|
|
1195 ins_pagedown();
|
|
1196 else
|
|
1197 ins_down(FALSE);
|
7
|
1198 break;
|
|
1199
|
449
|
1200 case K_S_DOWN: /* <S-Down> */
|
7
|
1201 case K_PAGEDOWN:
|
|
1202 case K_KPAGEDOWN:
|
613
|
1203 #ifdef FEAT_INS_EXPAND
|
610
|
1204 if (pum_visible())
|
|
1205 goto docomplete;
|
613
|
1206 #endif
|
7
|
1207 ins_pagedown();
|
|
1208 break;
|
|
1209
|
|
1210 #ifdef FEAT_DND
|
449
|
1211 case K_DROP: /* drag-n-drop event */
|
7
|
1212 ins_drop();
|
|
1213 break;
|
|
1214 #endif
|
|
1215
|
449
|
1216 case K_S_TAB: /* When not mapped, use like a normal TAB */
|
7
|
1217 c = TAB;
|
|
1218 /* FALLTHROUGH */
|
|
1219
|
449
|
1220 case TAB: /* TAB or Complete patterns along path */
|
7
|
1221 #if defined(FEAT_INS_EXPAND) && defined(FEAT_FIND_ID)
|
|
1222 if (ctrl_x_mode == CTRL_X_PATH_PATTERNS)
|
|
1223 goto docomplete;
|
|
1224 #endif
|
|
1225 inserted_space = FALSE;
|
|
1226 if (ins_tab())
|
|
1227 goto normalchar; /* insert TAB as a normal char */
|
|
1228 auto_format(FALSE, TRUE);
|
|
1229 break;
|
|
1230
|
449
|
1231 case K_KENTER: /* <Enter> */
|
7
|
1232 c = CAR;
|
|
1233 /* FALLTHROUGH */
|
|
1234 case CAR:
|
|
1235 case NL:
|
|
1236 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
|
|
1237 /* In a quickfix window a <CR> jumps to the error under the
|
|
1238 * cursor. */
|
|
1239 if (bt_quickfix(curbuf) && c == CAR)
|
|
1240 {
|
644
|
1241 if (curwin->w_llist_ref == NULL) /* quickfix window */
|
|
1242 do_cmdline_cmd((char_u *)".cc");
|
|
1243 else /* location list window */
|
|
1244 do_cmdline_cmd((char_u *)".ll");
|
7
|
1245 break;
|
|
1246 }
|
|
1247 #endif
|
|
1248 #ifdef FEAT_CMDWIN
|
|
1249 if (cmdwin_type != 0)
|
|
1250 {
|
|
1251 /* Execute the command in the cmdline window. */
|
|
1252 cmdwin_result = CAR;
|
|
1253 goto doESCkey;
|
|
1254 }
|
|
1255 #endif
|
|
1256 if (ins_eol(c) && !p_im)
|
|
1257 goto doESCkey; /* out of memory */
|
|
1258 auto_format(FALSE, FALSE);
|
|
1259 inserted_space = FALSE;
|
|
1260 break;
|
|
1261
|
|
1262 #if defined(FEAT_DIGRAPHS) || defined (FEAT_INS_EXPAND)
|
449
|
1263 case Ctrl_K: /* digraph or keyword completion */
|
7
|
1264 # ifdef FEAT_INS_EXPAND
|
|
1265 if (ctrl_x_mode == CTRL_X_DICTIONARY)
|
|
1266 {
|
449
|
1267 if (has_compl_option(TRUE))
|
|
1268 goto docomplete;
|
|
1269 break;
|
7
|
1270 }
|
|
1271 # endif
|
|
1272 # ifdef FEAT_DIGRAPHS
|
|
1273 c = ins_digraph();
|
|
1274 if (c == NUL)
|
|
1275 break;
|
|
1276 # endif
|
|
1277 goto normalchar;
|
449
|
1278 #endif
|
7
|
1279
|
|
1280 #ifdef FEAT_INS_EXPAND
|
464
|
1281 case Ctrl_X: /* Enter CTRL-X mode */
|
|
1282 ins_ctrl_x();
|
|
1283 break;
|
|
1284
|
449
|
1285 case Ctrl_RSB: /* Tag name completion after ^X */
|
7
|
1286 if (ctrl_x_mode != CTRL_X_TAGS)
|
|
1287 goto normalchar;
|
|
1288 goto docomplete;
|
|
1289
|
449
|
1290 case Ctrl_F: /* File name completion after ^X */
|
7
|
1291 if (ctrl_x_mode != CTRL_X_FILES)
|
|
1292 goto normalchar;
|
|
1293 goto docomplete;
|
477
|
1294
|
|
1295 case 's': /* Spelling completion after ^X */
|
|
1296 case Ctrl_S:
|
|
1297 if (ctrl_x_mode != CTRL_X_SPELL)
|
|
1298 goto normalchar;
|
|
1299 goto docomplete;
|
7
|
1300 #endif
|
|
1301
|
449
|
1302 case Ctrl_L: /* Whole line completion after ^X */
|
7
|
1303 #ifdef FEAT_INS_EXPAND
|
|
1304 if (ctrl_x_mode != CTRL_X_WHOLE_LINE)
|
|
1305 #endif
|
|
1306 {
|
|
1307 /* CTRL-L with 'insertmode' set: Leave Insert mode */
|
|
1308 if (p_im)
|
|
1309 {
|
|
1310 if (echeck_abbr(Ctrl_L + ABBR_OFF))
|
|
1311 break;
|
|
1312 goto doESCkey;
|
|
1313 }
|
|
1314 goto normalchar;
|
|
1315 }
|
|
1316 #ifdef FEAT_INS_EXPAND
|
|
1317 /* FALLTHROUGH */
|
|
1318
|
449
|
1319 case Ctrl_P: /* Do previous/next pattern completion */
|
7
|
1320 case Ctrl_N:
|
|
1321 /* if 'complete' is empty then plain ^P is no longer special,
|
|
1322 * but it is under other ^X modes */
|
|
1323 if (*curbuf->b_p_cpt == NUL
|
|
1324 && ctrl_x_mode != 0
|
449
|
1325 && !(compl_cont_status & CONT_LOCAL))
|
7
|
1326 goto normalchar;
|
|
1327
|
|
1328 docomplete:
|
|
1329 if (ins_complete(c) == FAIL)
|
449
|
1330 compl_cont_status = 0;
|
7
|
1331 break;
|
|
1332 #endif /* FEAT_INS_EXPAND */
|
|
1333
|
449
|
1334 case Ctrl_Y: /* copy from previous line or scroll down */
|
|
1335 case Ctrl_E: /* copy from next line or scroll up */
|
|
1336 c = ins_ctrl_ey(c);
|
7
|
1337 break;
|
|
1338
|
|
1339 default:
|
|
1340 #ifdef UNIX
|
|
1341 if (c == intr_char) /* special interrupt char */
|
|
1342 goto do_intr;
|
|
1343 #endif
|
|
1344
|
|
1345 /*
|
|
1346 * Insert a nomal character.
|
|
1347 */
|
|
1348 normalchar:
|
|
1349 #ifdef FEAT_SMARTINDENT
|
|
1350 /* Try to perform smart-indenting. */
|
|
1351 ins_try_si(c);
|
|
1352 #endif
|
|
1353
|
|
1354 if (c == ' ')
|
|
1355 {
|
|
1356 inserted_space = TRUE;
|
|
1357 #ifdef FEAT_CINDENT
|
|
1358 if (inindent(0))
|
|
1359 can_cindent = FALSE;
|
|
1360 #endif
|
|
1361 if (Insstart_blank_vcol == MAXCOL
|
|
1362 && curwin->w_cursor.lnum == Insstart.lnum)
|
|
1363 Insstart_blank_vcol = get_nolist_virtcol();
|
|
1364 }
|
|
1365
|
|
1366 if (vim_iswordc(c) || !echeck_abbr(
|
|
1367 #ifdef FEAT_MBYTE
|
|
1368 /* Add ABBR_OFF for characters above 0x100, this is
|
|
1369 * what check_abbr() expects. */
|
|
1370 (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) :
|
|
1371 #endif
|
|
1372 c))
|
|
1373 {
|
|
1374 insert_special(c, FALSE, FALSE);
|
|
1375 #ifdef FEAT_RIGHTLEFT
|
|
1376 revins_legal++;
|
|
1377 revins_chars++;
|
|
1378 #endif
|
|
1379 }
|
|
1380
|
|
1381 auto_format(FALSE, TRUE);
|
|
1382
|
|
1383 #ifdef FEAT_FOLDING
|
|
1384 /* When inserting a character the cursor line must never be in a
|
|
1385 * closed fold. */
|
|
1386 foldOpenCursor();
|
|
1387 #endif
|
|
1388 break;
|
|
1389 } /* end of switch (c) */
|
|
1390
|
|
1391 /* If the cursor was moved we didn't just insert a space */
|
|
1392 if (arrow_used)
|
|
1393 inserted_space = FALSE;
|
|
1394
|
|
1395 #ifdef FEAT_CINDENT
|
|
1396 if (can_cindent && cindent_on()
|
|
1397 # ifdef FEAT_INS_EXPAND
|
|
1398 && ctrl_x_mode == 0
|
|
1399 # endif
|
|
1400 )
|
|
1401 {
|
|
1402 force_cindent:
|
|
1403 /*
|
|
1404 * Indent now if a key was typed that is in 'cinkeys'.
|
|
1405 */
|
|
1406 if (in_cinkeys(c, ' ', line_is_white))
|
|
1407 {
|
|
1408 if (stop_arrow() == OK)
|
|
1409 /* re-indent the current line */
|
|
1410 do_c_expr_indent();
|
|
1411 }
|
|
1412 }
|
|
1413 #endif /* FEAT_CINDENT */
|
|
1414
|
|
1415 } /* for (;;) */
|
|
1416 /* NOTREACHED */
|
|
1417 }
|
|
1418
|
|
1419 /*
|
|
1420 * Redraw for Insert mode.
|
|
1421 * This is postponed until getting the next character to make '$' in the 'cpo'
|
|
1422 * option work correctly.
|
|
1423 * Only redraw when there are no characters available. This speeds up
|
|
1424 * inserting sequences of characters (e.g., for CTRL-R).
|
|
1425 */
|
661
|
1426 /*ARGSUSED*/
|
7
|
1427 static void
|
661
|
1428 ins_redraw(ready)
|
|
1429 int ready; /* not busy with something */
|
7
|
1430 {
|
|
1431 if (!char_avail())
|
|
1432 {
|
661
|
1433 #ifdef FEAT_AUTOCMD
|
794
|
1434 /* Trigger CursorMoved if the cursor moved. Not when the popup menu is
|
|
1435 * visible, the command might delete it. */
|
661
|
1436 if (ready && has_cursormovedI()
|
794
|
1437 && !equalpos(last_cursormoved, curwin->w_cursor)
|
|
1438 # ifdef FEAT_INS_EXPAND
|
|
1439 && !pum_visible()
|
|
1440 # endif
|
|
1441 )
|
661
|
1442 {
|
|
1443 apply_autocmds(EVENT_CURSORMOVEDI, NULL, NULL, FALSE, curbuf);
|
|
1444 last_cursormoved = curwin->w_cursor;
|
|
1445 }
|
|
1446 #endif
|
7
|
1447 if (must_redraw)
|
|
1448 update_screen(0);
|
|
1449 else if (clear_cmdline || redraw_cmdline)
|
|
1450 showmode(); /* clear cmdline and show mode */
|
|
1451 showruler(FALSE);
|
|
1452 setcursor();
|
|
1453 emsg_on_display = FALSE; /* may remove error message now */
|
|
1454 }
|
|
1455 }
|
|
1456
|
|
1457 /*
|
|
1458 * Handle a CTRL-V or CTRL-Q typed in Insert mode.
|
|
1459 */
|
|
1460 static void
|
|
1461 ins_ctrl_v()
|
|
1462 {
|
|
1463 int c;
|
|
1464
|
|
1465 /* may need to redraw when no more chars available now */
|
661
|
1466 ins_redraw(FALSE);
|
7
|
1467
|
|
1468 if (redrawing() && !char_avail())
|
|
1469 edit_putchar('^', TRUE);
|
|
1470 AppendToRedobuff((char_u *)CTRL_V_STR); /* CTRL-V */
|
|
1471
|
|
1472 #ifdef FEAT_CMDL_INFO
|
|
1473 add_to_showcmd_c(Ctrl_V);
|
|
1474 #endif
|
|
1475
|
|
1476 c = get_literal();
|
|
1477 #ifdef FEAT_CMDL_INFO
|
|
1478 clear_showcmd();
|
|
1479 #endif
|
|
1480 insert_special(c, FALSE, TRUE);
|
|
1481 #ifdef FEAT_RIGHTLEFT
|
|
1482 revins_chars++;
|
|
1483 revins_legal++;
|
|
1484 #endif
|
|
1485 }
|
|
1486
|
|
1487 /*
|
|
1488 * Put a character directly onto the screen. It's not stored in a buffer.
|
|
1489 * Used while handling CTRL-K, CTRL-V, etc. in Insert mode.
|
|
1490 */
|
|
1491 static int pc_status;
|
|
1492 #define PC_STATUS_UNSET 0 /* pc_bytes was not set */
|
|
1493 #define PC_STATUS_RIGHT 1 /* right halve of double-wide char */
|
|
1494 #define PC_STATUS_LEFT 2 /* left halve of double-wide char */
|
|
1495 #define PC_STATUS_SET 3 /* pc_bytes was filled */
|
|
1496 #ifdef FEAT_MBYTE
|
|
1497 static char_u pc_bytes[MB_MAXBYTES + 1]; /* saved bytes */
|
|
1498 #else
|
|
1499 static char_u pc_bytes[2]; /* saved bytes */
|
|
1500 #endif
|
|
1501 static int pc_attr;
|
|
1502 static int pc_row;
|
|
1503 static int pc_col;
|
|
1504
|
|
1505 void
|
|
1506 edit_putchar(c, highlight)
|
|
1507 int c;
|
|
1508 int highlight;
|
|
1509 {
|
|
1510 int attr;
|
|
1511
|
|
1512 if (ScreenLines != NULL)
|
|
1513 {
|
|
1514 update_topline(); /* just in case w_topline isn't valid */
|
|
1515 validate_cursor();
|
|
1516 if (highlight)
|
|
1517 attr = hl_attr(HLF_8);
|
|
1518 else
|
|
1519 attr = 0;
|
|
1520 pc_row = W_WINROW(curwin) + curwin->w_wrow;
|
|
1521 pc_col = W_WINCOL(curwin);
|
|
1522 #if defined(FEAT_RIGHTLEFT) || defined(FEAT_MBYTE)
|
|
1523 pc_status = PC_STATUS_UNSET;
|
|
1524 #endif
|
|
1525 #ifdef FEAT_RIGHTLEFT
|
|
1526 if (curwin->w_p_rl)
|
|
1527 {
|
|
1528 pc_col += W_WIDTH(curwin) - 1 - curwin->w_wcol;
|
|
1529 # ifdef FEAT_MBYTE
|
|
1530 if (has_mbyte)
|
|
1531 {
|
|
1532 int fix_col = mb_fix_col(pc_col, pc_row);
|
|
1533
|
|
1534 if (fix_col != pc_col)
|
|
1535 {
|
|
1536 screen_putchar(' ', pc_row, fix_col, attr);
|
|
1537 --curwin->w_wcol;
|
|
1538 pc_status = PC_STATUS_RIGHT;
|
|
1539 }
|
|
1540 }
|
|
1541 # endif
|
|
1542 }
|
|
1543 else
|
|
1544 #endif
|
|
1545 {
|
|
1546 pc_col += curwin->w_wcol;
|
|
1547 #ifdef FEAT_MBYTE
|
|
1548 if (mb_lefthalve(pc_row, pc_col))
|
|
1549 pc_status = PC_STATUS_LEFT;
|
|
1550 #endif
|
|
1551 }
|
|
1552
|
|
1553 /* save the character to be able to put it back */
|
|
1554 #if defined(FEAT_RIGHTLEFT) || defined(FEAT_MBYTE)
|
|
1555 if (pc_status == PC_STATUS_UNSET)
|
|
1556 #endif
|
|
1557 {
|
|
1558 screen_getbytes(pc_row, pc_col, pc_bytes, &pc_attr);
|
|
1559 pc_status = PC_STATUS_SET;
|
|
1560 }
|
|
1561 screen_putchar(c, pc_row, pc_col, attr);
|
|
1562 }
|
|
1563 }
|
|
1564
|
|
1565 /*
|
|
1566 * Undo the previous edit_putchar().
|
|
1567 */
|
|
1568 void
|
|
1569 edit_unputchar()
|
|
1570 {
|
|
1571 if (pc_status != PC_STATUS_UNSET && pc_row >= msg_scrolled)
|
|
1572 {
|
|
1573 #if defined(FEAT_MBYTE)
|
|
1574 if (pc_status == PC_STATUS_RIGHT)
|
|
1575 ++curwin->w_wcol;
|
|
1576 if (pc_status == PC_STATUS_RIGHT || pc_status == PC_STATUS_LEFT)
|
|
1577 redrawWinline(curwin->w_cursor.lnum, FALSE);
|
|
1578 else
|
|
1579 #endif
|
|
1580 screen_puts(pc_bytes, pc_row - msg_scrolled, pc_col, pc_attr);
|
|
1581 }
|
|
1582 }
|
|
1583
|
|
1584 /*
|
|
1585 * Called when p_dollar is set: display a '$' at the end of the changed text
|
|
1586 * Only works when cursor is in the line that changes.
|
|
1587 */
|
|
1588 void
|
|
1589 display_dollar(col)
|
|
1590 colnr_T col;
|
|
1591 {
|
|
1592 colnr_T save_col;
|
|
1593
|
|
1594 if (!redrawing())
|
|
1595 return;
|
|
1596
|
|
1597 cursor_off();
|
|
1598 save_col = curwin->w_cursor.col;
|
|
1599 curwin->w_cursor.col = col;
|
|
1600 #ifdef FEAT_MBYTE
|
|
1601 if (has_mbyte)
|
|
1602 {
|
|
1603 char_u *p;
|
|
1604
|
|
1605 /* If on the last byte of a multi-byte move to the first byte. */
|
|
1606 p = ml_get_curline();
|
|
1607 curwin->w_cursor.col -= (*mb_head_off)(p, p + col);
|
|
1608 }
|
|
1609 #endif
|
|
1610 curs_columns(FALSE); /* recompute w_wrow and w_wcol */
|
|
1611 if (curwin->w_wcol < W_WIDTH(curwin))
|
|
1612 {
|
|
1613 edit_putchar('$', FALSE);
|
|
1614 dollar_vcol = curwin->w_virtcol;
|
|
1615 }
|
|
1616 curwin->w_cursor.col = save_col;
|
|
1617 }
|
|
1618
|
|
1619 /*
|
|
1620 * Call this function before moving the cursor from the normal insert position
|
|
1621 * in insert mode.
|
|
1622 */
|
|
1623 static void
|
|
1624 undisplay_dollar()
|
|
1625 {
|
|
1626 if (dollar_vcol)
|
|
1627 {
|
|
1628 dollar_vcol = 0;
|
|
1629 redrawWinline(curwin->w_cursor.lnum, FALSE);
|
|
1630 }
|
|
1631 }
|
|
1632
|
|
1633 /*
|
|
1634 * Insert an indent (for <Tab> or CTRL-T) or delete an indent (for CTRL-D).
|
|
1635 * Keep the cursor on the same character.
|
|
1636 * type == INDENT_INC increase indent (for CTRL-T or <Tab>)
|
|
1637 * type == INDENT_DEC decrease indent (for CTRL-D)
|
|
1638 * type == INDENT_SET set indent to "amount"
|
|
1639 * if round is TRUE, round the indent to 'shiftwidth' (only with _INC and _Dec).
|
|
1640 */
|
|
1641 void
|
|
1642 change_indent(type, amount, round, replaced)
|
|
1643 int type;
|
|
1644 int amount;
|
|
1645 int round;
|
|
1646 int replaced; /* replaced character, put on replace stack */
|
|
1647 {
|
|
1648 int vcol;
|
|
1649 int last_vcol;
|
|
1650 int insstart_less; /* reduction for Insstart.col */
|
|
1651 int new_cursor_col;
|
|
1652 int i;
|
|
1653 char_u *ptr;
|
|
1654 int save_p_list;
|
|
1655 int start_col;
|
|
1656 colnr_T vc;
|
|
1657 #ifdef FEAT_VREPLACE
|
|
1658 colnr_T orig_col = 0; /* init for GCC */
|
|
1659 char_u *new_line, *orig_line = NULL; /* init for GCC */
|
|
1660
|
|
1661 /* VREPLACE mode needs to know what the line was like before changing */
|
|
1662 if (State & VREPLACE_FLAG)
|
|
1663 {
|
|
1664 orig_line = vim_strsave(ml_get_curline()); /* Deal with NULL below */
|
|
1665 orig_col = curwin->w_cursor.col;
|
|
1666 }
|
|
1667 #endif
|
|
1668
|
|
1669 /* for the following tricks we don't want list mode */
|
|
1670 save_p_list = curwin->w_p_list;
|
|
1671 curwin->w_p_list = FALSE;
|
|
1672 vc = getvcol_nolist(&curwin->w_cursor);
|
|
1673 vcol = vc;
|
|
1674
|
|
1675 /*
|
|
1676 * For Replace mode we need to fix the replace stack later, which is only
|
|
1677 * possible when the cursor is in the indent. Remember the number of
|
|
1678 * characters before the cursor if it's possible.
|
|
1679 */
|
|
1680 start_col = curwin->w_cursor.col;
|
|
1681
|
|
1682 /* determine offset from first non-blank */
|
|
1683 new_cursor_col = curwin->w_cursor.col;
|
|
1684 beginline(BL_WHITE);
|
|
1685 new_cursor_col -= curwin->w_cursor.col;
|
|
1686
|
|
1687 insstart_less = curwin->w_cursor.col;
|
|
1688
|
|
1689 /*
|
|
1690 * If the cursor is in the indent, compute how many screen columns the
|
|
1691 * cursor is to the left of the first non-blank.
|
|
1692 */
|
|
1693 if (new_cursor_col < 0)
|
|
1694 vcol = get_indent() - vcol;
|
|
1695
|
|
1696 if (new_cursor_col > 0) /* can't fix replace stack */
|
|
1697 start_col = -1;
|
|
1698
|
|
1699 /*
|
|
1700 * Set the new indent. The cursor will be put on the first non-blank.
|
|
1701 */
|
|
1702 if (type == INDENT_SET)
|
|
1703 (void)set_indent(amount, SIN_CHANGED);
|
|
1704 else
|
|
1705 {
|
|
1706 #ifdef FEAT_VREPLACE
|
|
1707 int save_State = State;
|
|
1708
|
|
1709 /* Avoid being called recursively. */
|
|
1710 if (State & VREPLACE_FLAG)
|
|
1711 State = INSERT;
|
|
1712 #endif
|
|
1713 shift_line(type == INDENT_DEC, round, 1);
|
|
1714 #ifdef FEAT_VREPLACE
|
|
1715 State = save_State;
|
|
1716 #endif
|
|
1717 }
|
|
1718 insstart_less -= curwin->w_cursor.col;
|
|
1719
|
|
1720 /*
|
|
1721 * Try to put cursor on same character.
|
|
1722 * If the cursor is at or after the first non-blank in the line,
|
|
1723 * compute the cursor column relative to the column of the first
|
|
1724 * non-blank character.
|
|
1725 * If we are not in insert mode, leave the cursor on the first non-blank.
|
|
1726 * If the cursor is before the first non-blank, position it relative
|
|
1727 * to the first non-blank, counted in screen columns.
|
|
1728 */
|
|
1729 if (new_cursor_col >= 0)
|
|
1730 {
|
|
1731 /*
|
|
1732 * When changing the indent while the cursor is touching it, reset
|
|
1733 * Insstart_col to 0.
|
|
1734 */
|
|
1735 if (new_cursor_col == 0)
|
|
1736 insstart_less = MAXCOL;
|
|
1737 new_cursor_col += curwin->w_cursor.col;
|
|
1738 }
|
|
1739 else if (!(State & INSERT))
|
|
1740 new_cursor_col = curwin->w_cursor.col;
|
|
1741 else
|
|
1742 {
|
|
1743 /*
|
|
1744 * Compute the screen column where the cursor should be.
|
|
1745 */
|
|
1746 vcol = get_indent() - vcol;
|
|
1747 curwin->w_virtcol = (vcol < 0) ? 0 : vcol;
|
|
1748
|
|
1749 /*
|
|
1750 * Advance the cursor until we reach the right screen column.
|
|
1751 */
|
|
1752 vcol = last_vcol = 0;
|
|
1753 new_cursor_col = -1;
|
|
1754 ptr = ml_get_curline();
|
|
1755 while (vcol <= (int)curwin->w_virtcol)
|
|
1756 {
|
|
1757 last_vcol = vcol;
|
|
1758 #ifdef FEAT_MBYTE
|
|
1759 if (has_mbyte && new_cursor_col >= 0)
|
474
|
1760 new_cursor_col += (*mb_ptr2len)(ptr + new_cursor_col);
|
7
|
1761 else
|
|
1762 #endif
|
|
1763 ++new_cursor_col;
|
|
1764 vcol += lbr_chartabsize(ptr + new_cursor_col, (colnr_T)vcol);
|
|
1765 }
|
|
1766 vcol = last_vcol;
|
|
1767
|
|
1768 /*
|
|
1769 * May need to insert spaces to be able to position the cursor on
|
|
1770 * the right screen column.
|
|
1771 */
|
|
1772 if (vcol != (int)curwin->w_virtcol)
|
|
1773 {
|
|
1774 curwin->w_cursor.col = new_cursor_col;
|
|
1775 i = (int)curwin->w_virtcol - vcol;
|
|
1776 ptr = alloc(i + 1);
|
|
1777 if (ptr != NULL)
|
|
1778 {
|
|
1779 new_cursor_col += i;
|
|
1780 ptr[i] = NUL;
|
|
1781 while (--i >= 0)
|
|
1782 ptr[i] = ' ';
|
|
1783 ins_str(ptr);
|
|
1784 vim_free(ptr);
|
|
1785 }
|
|
1786 }
|
|
1787
|
|
1788 /*
|
|
1789 * When changing the indent while the cursor is in it, reset
|
|
1790 * Insstart_col to 0.
|
|
1791 */
|
|
1792 insstart_less = MAXCOL;
|
|
1793 }
|
|
1794
|
|
1795 curwin->w_p_list = save_p_list;
|
|
1796
|
|
1797 if (new_cursor_col <= 0)
|
|
1798 curwin->w_cursor.col = 0;
|
|
1799 else
|
|
1800 curwin->w_cursor.col = new_cursor_col;
|
|
1801 curwin->w_set_curswant = TRUE;
|
|
1802 changed_cline_bef_curs();
|
|
1803
|
|
1804 /*
|
|
1805 * May have to adjust the start of the insert.
|
|
1806 */
|
|
1807 if (State & INSERT)
|
|
1808 {
|
|
1809 if (curwin->w_cursor.lnum == Insstart.lnum && Insstart.col != 0)
|
|
1810 {
|
|
1811 if ((int)Insstart.col <= insstart_less)
|
|
1812 Insstart.col = 0;
|
|
1813 else
|
|
1814 Insstart.col -= insstart_less;
|
|
1815 }
|
|
1816 if ((int)ai_col <= insstart_less)
|
|
1817 ai_col = 0;
|
|
1818 else
|
|
1819 ai_col -= insstart_less;
|
|
1820 }
|
|
1821
|
|
1822 /*
|
|
1823 * For REPLACE mode, may have to fix the replace stack, if it's possible.
|
|
1824 * If the number of characters before the cursor decreased, need to pop a
|
|
1825 * few characters from the replace stack.
|
|
1826 * If the number of characters before the cursor increased, need to push a
|
|
1827 * few NULs onto the replace stack.
|
|
1828 */
|
|
1829 if (REPLACE_NORMAL(State) && start_col >= 0)
|
|
1830 {
|
|
1831 while (start_col > (int)curwin->w_cursor.col)
|
|
1832 {
|
|
1833 replace_join(0); /* remove a NUL from the replace stack */
|
|
1834 --start_col;
|
|
1835 }
|
|
1836 while (start_col < (int)curwin->w_cursor.col || replaced)
|
|
1837 {
|
|
1838 replace_push(NUL);
|
|
1839 if (replaced)
|
|
1840 {
|
|
1841 replace_push(replaced);
|
|
1842 replaced = NUL;
|
|
1843 }
|
|
1844 ++start_col;
|
|
1845 }
|
|
1846 }
|
|
1847
|
|
1848 #ifdef FEAT_VREPLACE
|
|
1849 /*
|
|
1850 * For VREPLACE mode, we also have to fix the replace stack. In this case
|
|
1851 * it is always possible because we backspace over the whole line and then
|
|
1852 * put it back again the way we wanted it.
|
|
1853 */
|
|
1854 if (State & VREPLACE_FLAG)
|
|
1855 {
|
|
1856 /* If orig_line didn't allocate, just return. At least we did the job,
|
|
1857 * even if you can't backspace. */
|
|
1858 if (orig_line == NULL)
|
|
1859 return;
|
|
1860
|
|
1861 /* Save new line */
|
|
1862 new_line = vim_strsave(ml_get_curline());
|
|
1863 if (new_line == NULL)
|
|
1864 return;
|
|
1865
|
|
1866 /* We only put back the new line up to the cursor */
|
|
1867 new_line[curwin->w_cursor.col] = NUL;
|
|
1868
|
|
1869 /* Put back original line */
|
|
1870 ml_replace(curwin->w_cursor.lnum, orig_line, FALSE);
|
|
1871 curwin->w_cursor.col = orig_col;
|
|
1872
|
|
1873 /* Backspace from cursor to start of line */
|
|
1874 backspace_until_column(0);
|
|
1875
|
|
1876 /* Insert new stuff into line again */
|
|
1877 ins_bytes(new_line);
|
|
1878
|
|
1879 vim_free(new_line);
|
|
1880 }
|
|
1881 #endif
|
|
1882 }
|
|
1883
|
|
1884 /*
|
|
1885 * Truncate the space at the end of a line. This is to be used only in an
|
|
1886 * insert mode. It handles fixing the replace stack for REPLACE and VREPLACE
|
|
1887 * modes.
|
|
1888 */
|
|
1889 void
|
|
1890 truncate_spaces(line)
|
|
1891 char_u *line;
|
|
1892 {
|
|
1893 int i;
|
|
1894
|
|
1895 /* find start of trailing white space */
|
|
1896 for (i = (int)STRLEN(line) - 1; i >= 0 && vim_iswhite(line[i]); i--)
|
|
1897 {
|
|
1898 if (State & REPLACE_FLAG)
|
|
1899 replace_join(0); /* remove a NUL from the replace stack */
|
|
1900 }
|
|
1901 line[i + 1] = NUL;
|
|
1902 }
|
|
1903
|
|
1904 #if defined(FEAT_VREPLACE) || defined(FEAT_INS_EXPAND) \
|
|
1905 || defined(FEAT_COMMENTS) || defined(PROTO)
|
|
1906 /*
|
|
1907 * Backspace the cursor until the given column. Handles REPLACE and VREPLACE
|
|
1908 * modes correctly. May also be used when not in insert mode at all.
|
|
1909 */
|
|
1910 void
|
|
1911 backspace_until_column(col)
|
|
1912 int col;
|
|
1913 {
|
|
1914 while ((int)curwin->w_cursor.col > col)
|
|
1915 {
|
|
1916 curwin->w_cursor.col--;
|
|
1917 if (State & REPLACE_FLAG)
|
|
1918 replace_do_bs();
|
|
1919 else
|
|
1920 (void)del_char(FALSE);
|
|
1921 }
|
|
1922 }
|
|
1923 #endif
|
|
1924
|
|
1925 #if defined(FEAT_INS_EXPAND) || defined(PROTO)
|
|
1926 /*
|
449
|
1927 * CTRL-X pressed in Insert mode.
|
|
1928 */
|
|
1929 static void
|
|
1930 ins_ctrl_x()
|
|
1931 {
|
|
1932 /* CTRL-X after CTRL-X CTRL-V doesn't do anything, so that CTRL-X
|
|
1933 * CTRL-V works like CTRL-N */
|
|
1934 if (ctrl_x_mode != CTRL_X_CMDLINE)
|
|
1935 {
|
|
1936 /* if the next ^X<> won't ADD nothing, then reset
|
|
1937 * compl_cont_status */
|
|
1938 if (compl_cont_status & CONT_N_ADDS)
|
665
|
1939 compl_cont_status |= CONT_INTRPT;
|
449
|
1940 else
|
|
1941 compl_cont_status = 0;
|
|
1942 /* We're not sure which CTRL-X mode it will be yet */
|
|
1943 ctrl_x_mode = CTRL_X_NOT_DEFINED_YET;
|
|
1944 edit_submode = (char_u *)_(CTRL_X_MSG(ctrl_x_mode));
|
|
1945 edit_submode_pre = NULL;
|
|
1946 showmode();
|
|
1947 }
|
|
1948 }
|
|
1949
|
|
1950 /*
|
|
1951 * Return TRUE if the 'dict' or 'tsr' option can be used.
|
|
1952 */
|
|
1953 static int
|
|
1954 has_compl_option(dict_opt)
|
|
1955 int dict_opt;
|
|
1956 {
|
703
|
1957 if (dict_opt ? (*curbuf->b_p_dict == NUL && *p_dict == NUL
|
744
|
1958 # ifdef FEAT_SPELL
|
|
1959 && !curwin->w_p_spell
|
|
1960 # endif
|
|
1961 )
|
449
|
1962 : (*curbuf->b_p_tsr == NUL && *p_tsr == NUL))
|
|
1963 {
|
|
1964 ctrl_x_mode = 0;
|
|
1965 edit_submode = NULL;
|
|
1966 msg_attr(dict_opt ? (char_u *)_("'dictionary' option is empty")
|
|
1967 : (char_u *)_("'thesaurus' option is empty"),
|
|
1968 hl_attr(HLF_E));
|
|
1969 if (emsg_silent == 0)
|
|
1970 {
|
|
1971 vim_beep();
|
|
1972 setcursor();
|
|
1973 out_flush();
|
|
1974 ui_delay(2000L, FALSE);
|
|
1975 }
|
|
1976 return FALSE;
|
|
1977 }
|
|
1978 return TRUE;
|
|
1979 }
|
|
1980
|
|
1981 /*
|
7
|
1982 * Is the character 'c' a valid key to go to or keep us in CTRL-X mode?
|
|
1983 * This depends on the current mode.
|
|
1984 */
|
|
1985 int
|
|
1986 vim_is_ctrl_x_key(c)
|
|
1987 int c;
|
|
1988 {
|
|
1989 /* Always allow ^R - let it's results then be checked */
|
|
1990 if (c == Ctrl_R)
|
|
1991 return TRUE;
|
|
1992
|
610
|
1993 /* Accept <PageUp> and <PageDown> if the popup menu is visible. */
|
644
|
1994 if (ins_compl_pum_key(c))
|
610
|
1995 return TRUE;
|
|
1996
|
7
|
1997 switch (ctrl_x_mode)
|
|
1998 {
|
|
1999 case 0: /* Not in any CTRL-X mode */
|
|
2000 return (c == Ctrl_N || c == Ctrl_P || c == Ctrl_X);
|
|
2001 case CTRL_X_NOT_DEFINED_YET:
|
449
|
2002 return ( c == Ctrl_X || c == Ctrl_Y || c == Ctrl_E
|
7
|
2003 || c == Ctrl_L || c == Ctrl_F || c == Ctrl_RSB
|
|
2004 || c == Ctrl_I || c == Ctrl_D || c == Ctrl_P
|
|
2005 || c == Ctrl_N || c == Ctrl_T || c == Ctrl_V
|
477
|
2006 || c == Ctrl_Q || c == Ctrl_U || c == Ctrl_O
|
|
2007 || c == Ctrl_S || c == 's');
|
7
|
2008 case CTRL_X_SCROLL:
|
|
2009 return (c == Ctrl_Y || c == Ctrl_E);
|
|
2010 case CTRL_X_WHOLE_LINE:
|
|
2011 return (c == Ctrl_L || c == Ctrl_P || c == Ctrl_N);
|
|
2012 case CTRL_X_FILES:
|
|
2013 return (c == Ctrl_F || c == Ctrl_P || c == Ctrl_N);
|
|
2014 case CTRL_X_DICTIONARY:
|
|
2015 return (c == Ctrl_K || c == Ctrl_P || c == Ctrl_N);
|
|
2016 case CTRL_X_THESAURUS:
|
|
2017 return (c == Ctrl_T || c == Ctrl_P || c == Ctrl_N);
|
|
2018 case CTRL_X_TAGS:
|
|
2019 return (c == Ctrl_RSB || c == Ctrl_P || c == Ctrl_N);
|
|
2020 #ifdef FEAT_FIND_ID
|
|
2021 case CTRL_X_PATH_PATTERNS:
|
|
2022 return (c == Ctrl_P || c == Ctrl_N);
|
|
2023 case CTRL_X_PATH_DEFINES:
|
|
2024 return (c == Ctrl_D || c == Ctrl_P || c == Ctrl_N);
|
|
2025 #endif
|
|
2026 case CTRL_X_CMDLINE:
|
|
2027 return (c == Ctrl_V || c == Ctrl_Q || c == Ctrl_P || c == Ctrl_N
|
|
2028 || c == Ctrl_X);
|
12
|
2029 #ifdef FEAT_COMPL_FUNC
|
|
2030 case CTRL_X_FUNCTION:
|
449
|
2031 return (c == Ctrl_U || c == Ctrl_P || c == Ctrl_N);
|
523
|
2032 case CTRL_X_OMNI:
|
449
|
2033 return (c == Ctrl_O || c == Ctrl_P || c == Ctrl_N);
|
502
|
2034 #endif
|
477
|
2035 case CTRL_X_SPELL:
|
|
2036 return (c == Ctrl_S || c == Ctrl_P || c == Ctrl_N);
|
7
|
2037 }
|
|
2038 EMSG(_(e_internal));
|
|
2039 return FALSE;
|
|
2040 }
|
|
2041
|
|
2042 /*
|
659
|
2043 * This is like ins_compl_add(), but if 'ic' and 'inf' are set, then the
|
7
|
2044 * case of the originally typed text is used, and the case of the completed
|
|
2045 * text is infered, ie this tries to work out what case you probably wanted
|
|
2046 * the rest of the word to be in -- webb
|
449
|
2047 * TODO: make this work for multi-byte characters.
|
7
|
2048 */
|
|
2049 int
|
681
|
2050 ins_compl_add_infercase(str, len, icase, fname, dir, flags)
|
7
|
2051 char_u *str;
|
|
2052 int len;
|
681
|
2053 int icase;
|
7
|
2054 char_u *fname;
|
|
2055 int dir;
|
464
|
2056 int flags;
|
7
|
2057 {
|
|
2058 int has_lower = FALSE;
|
|
2059 int was_letter = FALSE;
|
|
2060 int idx;
|
|
2061
|
|
2062 if (p_ic && curbuf->b_p_inf && len < IOSIZE)
|
|
2063 {
|
|
2064 /* Infer case of completed part -- webb */
|
|
2065 /* Use IObuff, str would change text in buffer! */
|
419
|
2066 vim_strncpy(IObuff, str, len);
|
7
|
2067
|
|
2068 /* Rule 1: Were any chars converted to lower? */
|
449
|
2069 for (idx = 0; idx < compl_length; ++idx)
|
|
2070 {
|
|
2071 if (islower(compl_orig_text[idx]))
|
7
|
2072 {
|
|
2073 has_lower = TRUE;
|
|
2074 if (isupper(IObuff[idx]))
|
|
2075 {
|
|
2076 /* Rule 1 is satisfied */
|
449
|
2077 for (idx = compl_length; idx < len; ++idx)
|
7
|
2078 IObuff[idx] = TOLOWER_LOC(IObuff[idx]);
|
|
2079 break;
|
|
2080 }
|
|
2081 }
|
|
2082 }
|
|
2083
|
|
2084 /*
|
|
2085 * Rule 2: No lower case, 2nd consecutive letter converted to
|
|
2086 * upper case.
|
|
2087 */
|
|
2088 if (!has_lower)
|
|
2089 {
|
449
|
2090 for (idx = 0; idx < compl_length; ++idx)
|
7
|
2091 {
|
449
|
2092 if (was_letter && isupper(compl_orig_text[idx])
|
7
|
2093 && islower(IObuff[idx]))
|
|
2094 {
|
|
2095 /* Rule 2 is satisfied */
|
449
|
2096 for (idx = compl_length; idx < len; ++idx)
|
7
|
2097 IObuff[idx] = TOUPPER_LOC(IObuff[idx]);
|
|
2098 break;
|
|
2099 }
|
449
|
2100 was_letter = isalpha(compl_orig_text[idx]);
|
7
|
2101 }
|
|
2102 }
|
|
2103
|
|
2104 /* Copy the original case of the part we typed */
|
449
|
2105 STRNCPY(IObuff, compl_orig_text, compl_length);
|
7
|
2106
|
841
|
2107 return ins_compl_add(IObuff, len, icase, fname, NULL, dir,
|
|
2108 flags, FALSE);
|
|
2109 }
|
|
2110 return ins_compl_add(str, len, icase, fname, NULL, dir, flags, FALSE);
|
7
|
2111 }
|
|
2112
|
|
2113 /*
|
|
2114 * Add a match to the list of matches.
|
|
2115 * If the given string is already in the list of completions, then return
|
464
|
2116 * NOTDONE, otherwise add it to the list and return OK. If there is an error,
|
681
|
2117 * maybe because alloc() returns NULL, then FAIL is returned.
|
7
|
2118 */
|
841
|
2119 static int
|
|
2120 ins_compl_add(str, len, icase, fname, cptext, cdir, flags, dup)
|
7
|
2121 char_u *str;
|
|
2122 int len;
|
681
|
2123 int icase;
|
7
|
2124 char_u *fname;
|
841
|
2125 char_u **cptext; /* extra text for popup menu or NULL */
|
659
|
2126 int cdir;
|
464
|
2127 int flags;
|
841
|
2128 int dup; /* accept duplicate match */
|
7
|
2129 {
|
464
|
2130 compl_T *match;
|
659
|
2131 int dir = (cdir == 0 ? compl_direction : cdir);
|
7
|
2132
|
|
2133 ui_breakcheck();
|
|
2134 if (got_int)
|
464
|
2135 return FAIL;
|
7
|
2136 if (len < 0)
|
|
2137 len = (int)STRLEN(str);
|
|
2138
|
|
2139 /*
|
|
2140 * If the same match is already present, don't add it.
|
|
2141 */
|
841
|
2142 if (compl_first_match != NULL && !dup)
|
449
|
2143 {
|
|
2144 match = compl_first_match;
|
7
|
2145 do
|
|
2146 {
|
464
|
2147 if ( !(match->cp_flags & ORIGINAL_TEXT)
|
681
|
2148 && ins_compl_equal(match, str, len)
|
464
|
2149 && match->cp_str[len] == NUL)
|
|
2150 return NOTDONE;
|
|
2151 match = match->cp_next;
|
449
|
2152 } while (match != NULL && match != compl_first_match);
|
7
|
2153 }
|
|
2154
|
540
|
2155 /* Remove any popup menu before changing the list of matches. */
|
|
2156 ins_compl_del_pum();
|
|
2157
|
7
|
2158 /*
|
|
2159 * Allocate a new match structure.
|
|
2160 * Copy the values to the new match structure.
|
|
2161 */
|
659
|
2162 match = (compl_T *)alloc_clear((unsigned)sizeof(compl_T));
|
7
|
2163 if (match == NULL)
|
464
|
2164 return FAIL;
|
|
2165 match->cp_number = -1;
|
|
2166 if (flags & ORIGINAL_TEXT)
|
|
2167 match->cp_number = 0;
|
694
|
2168 if ((match->cp_str = vim_strnsave(str, len)) == NULL)
|
7
|
2169 {
|
|
2170 vim_free(match);
|
464
|
2171 return FAIL;
|
7
|
2172 }
|
681
|
2173 match->cp_icase = icase;
|
659
|
2174
|
7
|
2175 /* match-fname is:
|
464
|
2176 * - compl_curr_match->cp_fname if it is a string equal to fname.
|
7
|
2177 * - a copy of fname, FREE_FNAME is set to free later THE allocated mem.
|
|
2178 * - NULL otherwise. --Acevedo */
|
659
|
2179 if (fname != NULL
|
829
|
2180 && compl_curr_match != NULL
|
659
|
2181 && compl_curr_match->cp_fname != NULL
|
|
2182 && STRCMP(fname, compl_curr_match->cp_fname) == 0)
|
464
|
2183 match->cp_fname = compl_curr_match->cp_fname;
|
659
|
2184 else if (fname != NULL)
|
|
2185 {
|
|
2186 match->cp_fname = vim_strsave(fname);
|
464
|
2187 flags |= FREE_FNAME;
|
659
|
2188 }
|
7
|
2189 else
|
464
|
2190 match->cp_fname = NULL;
|
|
2191 match->cp_flags = flags;
|
786
|
2192
|
|
2193 if (cptext != NULL)
|
|
2194 {
|
|
2195 int i;
|
|
2196
|
|
2197 for (i = 0; i < CPT_COUNT; ++i)
|
|
2198 if (cptext[i] != NULL && *cptext[i] != NUL)
|
|
2199 match->cp_text[i] = vim_strsave(cptext[i]);
|
|
2200 }
|
7
|
2201
|
|
2202 /*
|
|
2203 * Link the new match structure in the list of matches.
|
|
2204 */
|
449
|
2205 if (compl_first_match == NULL)
|
464
|
2206 match->cp_next = match->cp_prev = NULL;
|
7
|
2207 else if (dir == FORWARD)
|
|
2208 {
|
464
|
2209 match->cp_next = compl_curr_match->cp_next;
|
|
2210 match->cp_prev = compl_curr_match;
|
7
|
2211 }
|
|
2212 else /* BACKWARD */
|
|
2213 {
|
464
|
2214 match->cp_next = compl_curr_match;
|
|
2215 match->cp_prev = compl_curr_match->cp_prev;
|
|
2216 }
|
|
2217 if (match->cp_next)
|
|
2218 match->cp_next->cp_prev = match;
|
|
2219 if (match->cp_prev)
|
|
2220 match->cp_prev->cp_next = match;
|
7
|
2221 else /* if there's nothing before, it is the first match */
|
449
|
2222 compl_first_match = match;
|
|
2223 compl_curr_match = match;
|
7
|
2224
|
665
|
2225 /*
|
|
2226 * Find the longest common string if still doing that.
|
|
2227 */
|
|
2228 if (compl_get_longest && (flags & ORIGINAL_TEXT) == 0)
|
|
2229 ins_compl_longest_match(match);
|
|
2230
|
7
|
2231 return OK;
|
|
2232 }
|
|
2233
|
|
2234 /*
|
681
|
2235 * Return TRUE if "str[len]" matches with match->cp_str, considering
|
|
2236 * match->cp_icase.
|
|
2237 */
|
|
2238 static int
|
|
2239 ins_compl_equal(match, str, len)
|
|
2240 compl_T *match;
|
|
2241 char_u *str;
|
|
2242 int len;
|
|
2243 {
|
|
2244 if (match->cp_icase)
|
|
2245 return STRNICMP(match->cp_str, str, (size_t)len) == 0;
|
|
2246 return STRNCMP(match->cp_str, str, (size_t)len) == 0;
|
|
2247 }
|
|
2248
|
|
2249 /*
|
665
|
2250 * Reduce the longest common string for match "match".
|
|
2251 */
|
|
2252 static void
|
|
2253 ins_compl_longest_match(match)
|
|
2254 compl_T *match;
|
|
2255 {
|
|
2256 char_u *p, *s;
|
681
|
2257 int c1, c2;
|
665
|
2258 int had_match;
|
|
2259
|
|
2260 if (compl_leader == NULL)
|
842
|
2261 {
|
665
|
2262 /* First match, use it as a whole. */
|
|
2263 compl_leader = vim_strsave(match->cp_str);
|
842
|
2264 if (compl_leader != NULL)
|
|
2265 {
|
|
2266 had_match = (curwin->w_cursor.col > compl_col);
|
|
2267 ins_compl_delete();
|
|
2268 ins_bytes(compl_leader + curwin->w_cursor.col - compl_col);
|
|
2269 ins_redraw(FALSE);
|
|
2270
|
|
2271 /* When the match isn't there (to avoid matching itself) remove it
|
|
2272 * again after redrawing. */
|
|
2273 if (!had_match)
|
|
2274 ins_compl_delete();
|
|
2275 compl_used_match = FALSE;
|
|
2276 }
|
|
2277 }
|
665
|
2278 else
|
|
2279 {
|
|
2280 /* Reduce the text if this match differs from compl_leader. */
|
681
|
2281 p = compl_leader;
|
|
2282 s = match->cp_str;
|
|
2283 while (*p != NUL)
|
665
|
2284 {
|
|
2285 #ifdef FEAT_MBYTE
|
|
2286 if (has_mbyte)
|
|
2287 {
|
681
|
2288 c1 = mb_ptr2char(p);
|
|
2289 c2 = mb_ptr2char(s);
|
665
|
2290 }
|
|
2291 else
|
|
2292 #endif
|
|
2293 {
|
681
|
2294 c1 = *p;
|
|
2295 c2 = *s;
|
|
2296 }
|
|
2297 if (match->cp_icase ? (MB_TOLOWER(c1) != MB_TOLOWER(c2))
|
|
2298 : (c1 != c2))
|
|
2299 break;
|
|
2300 #ifdef FEAT_MBYTE
|
|
2301 if (has_mbyte)
|
|
2302 {
|
|
2303 mb_ptr_adv(p);
|
|
2304 mb_ptr_adv(s);
|
|
2305 }
|
|
2306 else
|
|
2307 #endif
|
|
2308 {
|
|
2309 ++p;
|
|
2310 ++s;
|
665
|
2311 }
|
|
2312 }
|
|
2313
|
|
2314 if (*p != NUL)
|
|
2315 {
|
|
2316 /* Leader was shortened, need to change the inserted text. */
|
|
2317 *p = NUL;
|
|
2318 had_match = (curwin->w_cursor.col > compl_col);
|
|
2319 ins_compl_delete();
|
|
2320 ins_bytes(compl_leader + curwin->w_cursor.col - compl_col);
|
|
2321 ins_redraw(FALSE);
|
|
2322
|
|
2323 /* When the match isn't there (to avoid matching itself) remove it
|
|
2324 * again after redrawing. */
|
|
2325 if (!had_match)
|
|
2326 ins_compl_delete();
|
|
2327 }
|
|
2328
|
|
2329 compl_used_match = FALSE;
|
|
2330 }
|
|
2331 }
|
|
2332
|
|
2333 /*
|
7
|
2334 * Add an array of matches to the list of matches.
|
|
2335 * Frees matches[].
|
|
2336 */
|
|
2337 static void
|
681
|
2338 ins_compl_add_matches(num_matches, matches, icase)
|
7
|
2339 int num_matches;
|
|
2340 char_u **matches;
|
681
|
2341 int icase;
|
7
|
2342 {
|
|
2343 int i;
|
|
2344 int add_r = OK;
|
659
|
2345 int dir = compl_direction;
|
7
|
2346
|
464
|
2347 for (i = 0; i < num_matches && add_r != FAIL; i++)
|
681
|
2348 if ((add_r = ins_compl_add(matches[i], -1, icase,
|
841
|
2349 NULL, NULL, dir, 0, FALSE)) == OK)
|
7
|
2350 /* if dir was BACKWARD then honor it just once */
|
659
|
2351 dir = FORWARD;
|
7
|
2352 FreeWild(num_matches, matches);
|
|
2353 }
|
|
2354
|
|
2355 /* Make the completion list cyclic.
|
|
2356 * Return the number of matches (excluding the original).
|
|
2357 */
|
|
2358 static int
|
|
2359 ins_compl_make_cyclic()
|
|
2360 {
|
464
|
2361 compl_T *match;
|
7
|
2362 int count = 0;
|
|
2363
|
449
|
2364 if (compl_first_match != NULL)
|
7
|
2365 {
|
|
2366 /*
|
|
2367 * Find the end of the list.
|
|
2368 */
|
449
|
2369 match = compl_first_match;
|
|
2370 /* there's always an entry for the compl_orig_text, it doesn't count. */
|
464
|
2371 while (match->cp_next != NULL && match->cp_next != compl_first_match)
|
|
2372 {
|
|
2373 match = match->cp_next;
|
7
|
2374 ++count;
|
|
2375 }
|
464
|
2376 match->cp_next = compl_first_match;
|
|
2377 compl_first_match->cp_prev = match;
|
7
|
2378 }
|
|
2379 return count;
|
|
2380 }
|
|
2381
|
724
|
2382 /*
|
|
2383 * Start completion for the complete() function.
|
|
2384 * "startcol" is where the matched text starts (1 is first column).
|
|
2385 * "list" is the list of matches.
|
|
2386 */
|
|
2387 void
|
|
2388 set_completion(startcol, list)
|
|
2389 int startcol;
|
|
2390 list_T *list;
|
|
2391 {
|
|
2392 /* If already doing completions stop it. */
|
|
2393 if (ctrl_x_mode != 0)
|
|
2394 ins_compl_prep(' ');
|
|
2395 ins_compl_clear();
|
|
2396
|
|
2397 if (stop_arrow() == FAIL)
|
|
2398 return;
|
|
2399
|
744
|
2400 if (startcol > (int)curwin->w_cursor.col)
|
724
|
2401 startcol = curwin->w_cursor.col;
|
|
2402 compl_col = startcol;
|
|
2403 compl_length = curwin->w_cursor.col - startcol;
|
|
2404 /* compl_pattern doesn't need to be set */
|
|
2405 compl_orig_text = vim_strnsave(ml_get_curline() + compl_col, compl_length);
|
|
2406 if (compl_orig_text == NULL || ins_compl_add(compl_orig_text,
|
841
|
2407 -1, FALSE, NULL, NULL, 0, ORIGINAL_TEXT, FALSE) != OK)
|
724
|
2408 return;
|
|
2409
|
|
2410 /* Handle like dictionary completion. */
|
|
2411 ctrl_x_mode = CTRL_X_WHOLE_LINE;
|
|
2412
|
|
2413 ins_compl_add_list(list);
|
|
2414 compl_matches = ins_compl_make_cyclic();
|
|
2415 compl_started = TRUE;
|
|
2416 compl_used_match = TRUE;
|
|
2417
|
|
2418 compl_curr_match = compl_first_match;
|
|
2419 ins_complete(Ctrl_N);
|
|
2420 out_flush();
|
|
2421 }
|
|
2422
|
|
2423
|
574
|
2424 /* "compl_match_array" points the currently displayed list of entries in the
|
|
2425 * popup menu. It is NULL when there is no popup menu. */
|
659
|
2426 static pumitem_T *compl_match_array = NULL;
|
540
|
2427 static int compl_match_arraysize;
|
|
2428
|
|
2429 /*
|
|
2430 * Update the screen and when there is any scrolling remove the popup menu.
|
|
2431 */
|
|
2432 static void
|
|
2433 ins_compl_upd_pum()
|
|
2434 {
|
|
2435 int h;
|
|
2436
|
|
2437 if (compl_match_array != NULL)
|
|
2438 {
|
|
2439 h = curwin->w_cline_height;
|
|
2440 update_screen(0);
|
|
2441 if (h != curwin->w_cline_height)
|
|
2442 ins_compl_del_pum();
|
|
2443 }
|
|
2444 }
|
|
2445
|
|
2446 /*
|
|
2447 * Remove any popup menu.
|
|
2448 */
|
|
2449 static void
|
|
2450 ins_compl_del_pum()
|
|
2451 {
|
|
2452 if (compl_match_array != NULL)
|
|
2453 {
|
|
2454 pum_undisplay();
|
|
2455 vim_free(compl_match_array);
|
|
2456 compl_match_array = NULL;
|
|
2457 }
|
|
2458 }
|
|
2459
|
|
2460 /*
|
|
2461 * Return TRUE if the popup menu should be displayed.
|
|
2462 */
|
|
2463 static int
|
|
2464 pum_wanted()
|
|
2465 {
|
707
|
2466 /* 'completeopt' must contain "menu" or "menuone" */
|
665
|
2467 if (vim_strchr(p_cot, 'm') == NULL)
|
540
|
2468 return FALSE;
|
|
2469
|
|
2470 /* The display looks bad on a B&W display. */
|
|
2471 if (t_colors < 8
|
|
2472 #ifdef FEAT_GUI
|
|
2473 && !gui.in_use
|
|
2474 #endif
|
|
2475 )
|
|
2476 return FALSE;
|
657
|
2477 return TRUE;
|
|
2478 }
|
|
2479
|
|
2480 /*
|
|
2481 * Return TRUE if there are two or more matches to be shown in the popup menu.
|
707
|
2482 * One if 'completopt' contains "menuone".
|
657
|
2483 */
|
|
2484 static int
|
707
|
2485 pum_enough_matches()
|
657
|
2486 {
|
|
2487 compl_T *compl;
|
|
2488 int i;
|
540
|
2489
|
|
2490 /* Don't display the popup menu if there are no matches or there is only
|
|
2491 * one (ignoring the original text). */
|
|
2492 compl = compl_first_match;
|
|
2493 i = 0;
|
|
2494 do
|
|
2495 {
|
|
2496 if (compl == NULL
|
|
2497 || ((compl->cp_flags & ORIGINAL_TEXT) == 0 && ++i == 2))
|
|
2498 break;
|
|
2499 compl = compl->cp_next;
|
|
2500 } while (compl != compl_first_match);
|
|
2501
|
707
|
2502 if (strstr((char *)p_cot, "menuone") != NULL)
|
|
2503 return (i >= 1);
|
540
|
2504 return (i >= 2);
|
|
2505 }
|
|
2506
|
|
2507 /*
|
|
2508 * Show the popup menu for the list of matches.
|
659
|
2509 * Also adjusts "compl_shown_match" to an entry that is actually displayed.
|
540
|
2510 */
|
648
|
2511 void
|
540
|
2512 ins_compl_show_pum()
|
|
2513 {
|
|
2514 compl_T *compl;
|
659
|
2515 compl_T *shown_compl = NULL;
|
|
2516 int did_find_shown_match = FALSE;
|
|
2517 int shown_match_ok = FALSE;
|
540
|
2518 int i;
|
|
2519 int cur = -1;
|
|
2520 colnr_T col;
|
657
|
2521 int lead_len = 0;
|
|
2522
|
707
|
2523 if (!pum_wanted() || !pum_enough_matches())
|
540
|
2524 return;
|
|
2525
|
794
|
2526 #if defined(FEAT_EVAL)
|
|
2527 /* Dirty hard-coded hack: remove any matchparen highlighting. */
|
|
2528 do_cmdline_cmd((char_u *)"if exists('g:loaded_matchparen')|3match none|endif");
|
|
2529 #endif
|
|
2530
|
540
|
2531 /* Update the screen before drawing the popup menu over it. */
|
|
2532 update_screen(0);
|
|
2533
|
|
2534 if (compl_match_array == NULL)
|
|
2535 {
|
|
2536 /* Need to build the popup menu list. */
|
|
2537 compl_match_arraysize = 0;
|
|
2538 compl = compl_first_match;
|
657
|
2539 if (compl_leader != NULL)
|
835
|
2540 lead_len = (int)STRLEN(compl_leader);
|
540
|
2541 do
|
|
2542 {
|
657
|
2543 if ((compl->cp_flags & ORIGINAL_TEXT) == 0
|
|
2544 && (compl_leader == NULL
|
681
|
2545 || ins_compl_equal(compl, compl_leader, lead_len)))
|
540
|
2546 ++compl_match_arraysize;
|
|
2547 compl = compl->cp_next;
|
|
2548 } while (compl != NULL && compl != compl_first_match);
|
657
|
2549 if (compl_match_arraysize == 0)
|
|
2550 return;
|
659
|
2551 compl_match_array = (pumitem_T *)alloc_clear(
|
|
2552 (unsigned)(sizeof(pumitem_T)
|
540
|
2553 * compl_match_arraysize));
|
|
2554 if (compl_match_array != NULL)
|
|
2555 {
|
829
|
2556 /* If the current match is the original text don't find the first
|
|
2557 * match after it, don't highlight anything. */
|
|
2558 if (compl_shown_match->cp_flags & ORIGINAL_TEXT)
|
|
2559 shown_match_ok = TRUE;
|
|
2560
|
540
|
2561 i = 0;
|
|
2562 compl = compl_first_match;
|
|
2563 do
|
|
2564 {
|
657
|
2565 if ((compl->cp_flags & ORIGINAL_TEXT) == 0
|
|
2566 && (compl_leader == NULL
|
681
|
2567 || ins_compl_equal(compl, compl_leader, lead_len)))
|
540
|
2568 {
|
659
|
2569 if (!shown_match_ok)
|
|
2570 {
|
|
2571 if (compl == compl_shown_match || did_find_shown_match)
|
|
2572 {
|
|
2573 /* This item is the shown match or this is the
|
|
2574 * first displayed item after the shown match. */
|
|
2575 compl_shown_match = compl;
|
|
2576 did_find_shown_match = TRUE;
|
|
2577 shown_match_ok = TRUE;
|
|
2578 }
|
|
2579 else
|
|
2580 /* Remember this displayed match for when the
|
|
2581 * shown match is just below it. */
|
|
2582 shown_compl = compl;
|
540
|
2583 cur = i;
|
659
|
2584 }
|
786
|
2585
|
|
2586 if (compl->cp_text[CPT_ABBR] != NULL)
|
|
2587 compl_match_array[i].pum_text =
|
|
2588 compl->cp_text[CPT_ABBR];
|
|
2589 else
|
|
2590 compl_match_array[i].pum_text = compl->cp_str;
|
|
2591 compl_match_array[i].pum_kind = compl->cp_text[CPT_KIND];
|
|
2592 compl_match_array[i].pum_info = compl->cp_text[CPT_INFO];
|
|
2593 if (compl->cp_text[CPT_MENU] != NULL)
|
|
2594 compl_match_array[i++].pum_extra =
|
|
2595 compl->cp_text[CPT_MENU];
|
659
|
2596 else
|
|
2597 compl_match_array[i++].pum_extra = compl->cp_fname;
|
|
2598 }
|
|
2599
|
|
2600 if (compl == compl_shown_match)
|
|
2601 {
|
|
2602 did_find_shown_match = TRUE;
|
716
|
2603
|
|
2604 /* When the original text is the shown match don't set
|
|
2605 * compl_shown_match. */
|
|
2606 if (compl->cp_flags & ORIGINAL_TEXT)
|
|
2607 shown_match_ok = TRUE;
|
|
2608
|
659
|
2609 if (!shown_match_ok && shown_compl != NULL)
|
|
2610 {
|
|
2611 /* The shown match isn't displayed, set it to the
|
|
2612 * previously displayed match. */
|
|
2613 compl_shown_match = shown_compl;
|
|
2614 shown_match_ok = TRUE;
|
|
2615 }
|
540
|
2616 }
|
|
2617 compl = compl->cp_next;
|
|
2618 } while (compl != NULL && compl != compl_first_match);
|
659
|
2619
|
|
2620 if (!shown_match_ok) /* no displayed match at all */
|
|
2621 cur = -1;
|
540
|
2622 }
|
|
2623 }
|
|
2624 else
|
|
2625 {
|
|
2626 /* popup menu already exists, only need to find the current item.*/
|
657
|
2627 for (i = 0; i < compl_match_arraysize; ++i)
|
786
|
2628 if (compl_match_array[i].pum_text == compl_shown_match->cp_str
|
|
2629 || compl_match_array[i].pum_text
|
|
2630 == compl_shown_match->cp_text[CPT_ABBR])
|
829
|
2631 {
|
|
2632 cur = i;
|
657
|
2633 break;
|
829
|
2634 }
|
540
|
2635 }
|
|
2636
|
|
2637 if (compl_match_array != NULL)
|
|
2638 {
|
|
2639 /* Compute the screen column of the start of the completed text.
|
|
2640 * Use the cursor to get all wrapping and other settings right. */
|
|
2641 col = curwin->w_cursor.col;
|
|
2642 curwin->w_cursor.col = compl_col;
|
732
|
2643 pum_display(compl_match_array, compl_match_arraysize, cur);
|
540
|
2644 curwin->w_cursor.col = col;
|
|
2645 }
|
|
2646 }
|
|
2647
|
7
|
2648 #define DICT_FIRST (1) /* use just first element in "dict" */
|
|
2649 #define DICT_EXACT (2) /* "dict" is the exact name of a file */
|
648
|
2650
|
7
|
2651 /*
|
703
|
2652 * Add any identifiers that match the given pattern in the list of dictionary
|
|
2653 * files "dict_start" to the list of completions.
|
7
|
2654 */
|
|
2655 static void
|
703
|
2656 ins_compl_dictionaries(dict_start, pat, flags, thesaurus)
|
|
2657 char_u *dict_start;
|
7
|
2658 char_u *pat;
|
667
|
2659 int flags; /* DICT_FIRST and/or DICT_EXACT */
|
703
|
2660 int thesaurus; /* Thesaurus completion */
|
|
2661 {
|
|
2662 char_u *dict = dict_start;
|
7
|
2663 char_u *ptr;
|
|
2664 char_u *buf;
|
|
2665 regmatch_T regmatch;
|
|
2666 char_u **files;
|
|
2667 int count;
|
|
2668 int i;
|
|
2669 int save_p_scs;
|
659
|
2670 int dir = compl_direction;
|
7
|
2671
|
703
|
2672 if (*dict == NUL)
|
|
2673 {
|
744
|
2674 #ifdef FEAT_SPELL
|
703
|
2675 /* When 'dictionary' is empty and spell checking is enabled use
|
|
2676 * "spell". */
|
|
2677 if (!thesaurus && curwin->w_p_spell)
|
|
2678 dict = (char_u *)"spell";
|
|
2679 else
|
|
2680 #endif
|
|
2681 return;
|
|
2682 }
|
|
2683
|
7
|
2684 buf = alloc(LSIZE);
|
703
|
2685 if (buf == NULL)
|
|
2686 return;
|
|
2687
|
7
|
2688 /* If 'infercase' is set, don't use 'smartcase' here */
|
|
2689 save_p_scs = p_scs;
|
|
2690 if (curbuf->b_p_inf)
|
|
2691 p_scs = FALSE;
|
667
|
2692
|
|
2693 /* When invoked to match whole lines for CTRL-X CTRL-L adjust the pattern
|
|
2694 * to only match at the start of a line. Otherwise just match the
|
842
|
2695 * pattern. Also need to double backslashes. */
|
667
|
2696 if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
|
|
2697 {
|
842
|
2698 char_u *pat_esc = vim_strsave_escaped(pat, (char_u *)"\\");
|
|
2699
|
|
2700 if (pat_esc == NULL)
|
|
2701 return ;
|
|
2702 i = (int)STRLEN(pat_esc) + 10;
|
667
|
2703 ptr = alloc(i);
|
|
2704 if (ptr == NULL)
|
842
|
2705 {
|
|
2706 vim_free(pat_esc);
|
667
|
2707 return;
|
842
|
2708 }
|
|
2709 vim_snprintf((char *)ptr, i, "^\\s*\\zs\\V%s", pat_esc);
|
|
2710 regmatch.regprog = vim_regcomp(ptr, RE_MAGIC);
|
|
2711 vim_free(pat_esc);
|
667
|
2712 vim_free(ptr);
|
|
2713 }
|
|
2714 else
|
703
|
2715 {
|
667
|
2716 regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0);
|
703
|
2717 if (regmatch.regprog == NULL)
|
|
2718 goto theend;
|
|
2719 }
|
667
|
2720
|
7
|
2721 /* ignore case depends on 'ignorecase', 'smartcase' and "pat" */
|
|
2722 regmatch.rm_ic = ignorecase(pat);
|
703
|
2723 while (*dict != NUL && !got_int && !compl_interrupted)
|
7
|
2724 {
|
|
2725 /* copy one dictionary file name into buf */
|
|
2726 if (flags == DICT_EXACT)
|
|
2727 {
|
|
2728 count = 1;
|
|
2729 files = &dict;
|
|
2730 }
|
|
2731 else
|
|
2732 {
|
|
2733 /* Expand wildcards in the dictionary name, but do not allow
|
|
2734 * backticks (for security, the 'dict' option may have been set in
|
|
2735 * a modeline). */
|
|
2736 copy_option_part(&dict, buf, LSIZE, ",");
|
744
|
2737 # ifdef FEAT_SPELL
|
703
|
2738 if (!thesaurus && STRCMP(buf, "spell") == 0)
|
|
2739 count = -1;
|
744
|
2740 else
|
|
2741 # endif
|
|
2742 if (vim_strchr(buf, '`') != NULL
|
7
|
2743 || expand_wildcards(1, &buf, &count, &files,
|
|
2744 EW_FILE|EW_SILENT) != OK)
|
|
2745 count = 0;
|
|
2746 }
|
|
2747
|
744
|
2748 # ifdef FEAT_SPELL
|
703
|
2749 if (count == -1)
|
|
2750 {
|
712
|
2751 /* Complete from active spelling. Skip "\<" in the pattern, we
|
|
2752 * don't use it as a RE. */
|
703
|
2753 if (pat[0] == '\\' && pat[1] == '<')
|
|
2754 ptr = pat + 2;
|
|
2755 else
|
|
2756 ptr = pat;
|
|
2757 spell_dump_compl(curbuf, ptr, regmatch.rm_ic, &dir, 0);
|
|
2758 }
|
|
2759 else
|
744
|
2760 # endif
|
703
|
2761 {
|
|
2762 ins_compl_files(count, files, thesaurus, flags,
|
|
2763 ®match, buf, &dir);
|
7
|
2764 if (flags != DICT_EXACT)
|
703
|
2765 FreeWild(count, files);
|
|
2766 }
|
|
2767 if (flags != 0)
|
7
|
2768 break;
|
|
2769 }
|
703
|
2770
|
|
2771 theend:
|
7
|
2772 p_scs = save_p_scs;
|
|
2773 vim_free(regmatch.regprog);
|
|
2774 vim_free(buf);
|
|
2775 }
|
|
2776
|
703
|
2777 static void
|
|
2778 ins_compl_files(count, files, thesaurus, flags, regmatch, buf, dir)
|
|
2779 int count;
|
|
2780 char_u **files;
|
|
2781 int thesaurus;
|
|
2782 int flags;
|
|
2783 regmatch_T *regmatch;
|
|
2784 char_u *buf;
|
|
2785 int *dir;
|
|
2786 {
|
|
2787 char_u *ptr;
|
|
2788 int i;
|
|
2789 FILE *fp;
|
|
2790 int add_r;
|
|
2791
|
|
2792 for (i = 0; i < count && !got_int && !compl_interrupted; i++)
|
|
2793 {
|
|
2794 fp = mch_fopen((char *)files[i], "r"); /* open dictionary file */
|
|
2795 if (flags != DICT_EXACT)
|
|
2796 {
|
|
2797 vim_snprintf((char *)IObuff, IOSIZE,
|
|
2798 _("Scanning dictionary: %s"), (char *)files[i]);
|
|
2799 msg_trunc_attr(IObuff, TRUE, hl_attr(HLF_R));
|
|
2800 }
|
|
2801
|
|
2802 if (fp != NULL)
|
|
2803 {
|
|
2804 /*
|
|
2805 * Read dictionary file line by line.
|
|
2806 * Check each line for a match.
|
|
2807 */
|
|
2808 while (!got_int && !compl_interrupted
|
|
2809 && !vim_fgets(buf, LSIZE, fp))
|
|
2810 {
|
|
2811 ptr = buf;
|
|
2812 while (vim_regexec(regmatch, buf, (colnr_T)(ptr - buf)))
|
|
2813 {
|
|
2814 ptr = regmatch->startp[0];
|
|
2815 if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
|
|
2816 ptr = find_line_end(ptr);
|
|
2817 else
|
|
2818 ptr = find_word_end(ptr);
|
|
2819 add_r = ins_compl_add_infercase(regmatch->startp[0],
|
|
2820 (int)(ptr - regmatch->startp[0]),
|
867
|
2821 FALSE, files[i], *dir, 0);
|
703
|
2822 if (thesaurus)
|
|
2823 {
|
|
2824 char_u *wstart;
|
|
2825
|
|
2826 /*
|
|
2827 * Add the other matches on the line
|
|
2828 */
|
|
2829 while (!got_int)
|
|
2830 {
|
|
2831 /* Find start of the next word. Skip white
|
|
2832 * space and punctuation. */
|
|
2833 ptr = find_word_start(ptr);
|
|
2834 if (*ptr == NUL || *ptr == NL)
|
|
2835 break;
|
|
2836 wstart = ptr;
|
|
2837
|
|
2838 /* Find end of the word and add it. */
|
|
2839 #ifdef FEAT_MBYTE
|
|
2840 if (has_mbyte)
|
|
2841 /* Japanese words may have characters in
|
|
2842 * different classes, only separate words
|
|
2843 * with single-byte non-word characters. */
|
|
2844 while (*ptr != NUL)
|
|
2845 {
|
|
2846 int l = (*mb_ptr2len)(ptr);
|
|
2847
|
|
2848 if (l < 2 && !vim_iswordc(*ptr))
|
|
2849 break;
|
|
2850 ptr += l;
|
|
2851 }
|
|
2852 else
|
|
2853 #endif
|
|
2854 ptr = find_word_end(ptr);
|
|
2855 add_r = ins_compl_add_infercase(wstart,
|
|
2856 (int)(ptr - wstart),
|
867
|
2857 FALSE, files[i], *dir, 0);
|
703
|
2858 }
|
|
2859 }
|
|
2860 if (add_r == OK)
|
|
2861 /* if dir was BACKWARD then honor it just once */
|
|
2862 *dir = FORWARD;
|
|
2863 else if (add_r == FAIL)
|
|
2864 break;
|
|
2865 /* avoid expensive call to vim_regexec() when at end
|
|
2866 * of line */
|
|
2867 if (*ptr == '\n' || got_int)
|
|
2868 break;
|
|
2869 }
|
|
2870 line_breakcheck();
|
|
2871 ins_compl_check_keys(50);
|
|
2872 }
|
|
2873 fclose(fp);
|
|
2874 }
|
|
2875 }
|
|
2876 }
|
|
2877
|
7
|
2878 /*
|
|
2879 * Find the start of the next word.
|
|
2880 * Returns a pointer to the first char of the word. Also stops at a NUL.
|
|
2881 */
|
|
2882 char_u *
|
|
2883 find_word_start(ptr)
|
|
2884 char_u *ptr;
|
|
2885 {
|
|
2886 #ifdef FEAT_MBYTE
|
|
2887 if (has_mbyte)
|
|
2888 while (*ptr != NUL && *ptr != '\n' && mb_get_class(ptr) <= 1)
|
474
|
2889 ptr += (*mb_ptr2len)(ptr);
|
7
|
2890 else
|
|
2891 #endif
|
|
2892 while (*ptr != NUL && *ptr != '\n' && !vim_iswordc(*ptr))
|
|
2893 ++ptr;
|
|
2894 return ptr;
|
|
2895 }
|
|
2896
|
|
2897 /*
|
|
2898 * Find the end of the word. Assumes it starts inside a word.
|
|
2899 * Returns a pointer to just after the word.
|
|
2900 */
|
|
2901 char_u *
|
|
2902 find_word_end(ptr)
|
|
2903 char_u *ptr;
|
|
2904 {
|
|
2905 #ifdef FEAT_MBYTE
|
|
2906 int start_class;
|
|
2907
|
|
2908 if (has_mbyte)
|
|
2909 {
|
|
2910 start_class = mb_get_class(ptr);
|
|
2911 if (start_class > 1)
|
|
2912 while (*ptr != NUL)
|
|
2913 {
|
474
|
2914 ptr += (*mb_ptr2len)(ptr);
|
7
|
2915 if (mb_get_class(ptr) != start_class)
|
|
2916 break;
|
|
2917 }
|
|
2918 }
|
|
2919 else
|
|
2920 #endif
|
|
2921 while (vim_iswordc(*ptr))
|
|
2922 ++ptr;
|
|
2923 return ptr;
|
|
2924 }
|
|
2925
|
|
2926 /*
|
667
|
2927 * Find the end of the line, omitting CR and NL at the end.
|
|
2928 * Returns a pointer to just after the line.
|
|
2929 */
|
|
2930 static char_u *
|
|
2931 find_line_end(ptr)
|
|
2932 char_u *ptr;
|
|
2933 {
|
|
2934 char_u *s;
|
|
2935
|
|
2936 s = ptr + STRLEN(ptr);
|
|
2937 while (s > ptr && (s[-1] == CAR || s[-1] == NL))
|
|
2938 --s;
|
|
2939 return s;
|
|
2940 }
|
|
2941
|
|
2942 /*
|
7
|
2943 * Free the list of completions
|
|
2944 */
|
|
2945 static void
|
|
2946 ins_compl_free()
|
|
2947 {
|
464
|
2948 compl_T *match;
|
786
|
2949 int i;
|
7
|
2950
|
449
|
2951 vim_free(compl_pattern);
|
|
2952 compl_pattern = NULL;
|
657
|
2953 vim_free(compl_leader);
|
|
2954 compl_leader = NULL;
|
449
|
2955
|
|
2956 if (compl_first_match == NULL)
|
7
|
2957 return;
|
540
|
2958
|
|
2959 ins_compl_del_pum();
|
|
2960 pum_clear();
|
|
2961
|
449
|
2962 compl_curr_match = compl_first_match;
|
7
|
2963 do
|
|
2964 {
|
449
|
2965 match = compl_curr_match;
|
464
|
2966 compl_curr_match = compl_curr_match->cp_next;
|
|
2967 vim_free(match->cp_str);
|
7
|
2968 /* several entries may use the same fname, free it just once. */
|
464
|
2969 if (match->cp_flags & FREE_FNAME)
|
|
2970 vim_free(match->cp_fname);
|
786
|
2971 for (i = 0; i < CPT_COUNT; ++i)
|
|
2972 vim_free(match->cp_text[i]);
|
7
|
2973 vim_free(match);
|
449
|
2974 } while (compl_curr_match != NULL && compl_curr_match != compl_first_match);
|
|
2975 compl_first_match = compl_curr_match = NULL;
|
7
|
2976 }
|
|
2977
|
|
2978 static void
|
|
2979 ins_compl_clear()
|
|
2980 {
|
449
|
2981 compl_cont_status = 0;
|
|
2982 compl_started = FALSE;
|
|
2983 compl_matches = 0;
|
|
2984 vim_free(compl_pattern);
|
|
2985 compl_pattern = NULL;
|
657
|
2986 vim_free(compl_leader);
|
|
2987 compl_leader = NULL;
|
7
|
2988 edit_submode_extra = NULL;
|
724
|
2989 vim_free(compl_orig_text);
|
|
2990 compl_orig_text = NULL;
|
825
|
2991 compl_enter_selects = FALSE;
|
7
|
2992 }
|
|
2993
|
|
2994 /*
|
674
|
2995 * Return TRUE when Insert completion is active.
|
|
2996 */
|
|
2997 int
|
|
2998 ins_compl_active()
|
|
2999 {
|
|
3000 return compl_started;
|
|
3001 }
|
|
3002
|
|
3003 /*
|
659
|
3004 * Delete one character before the cursor and show the subset of the matches
|
|
3005 * that match the word that is now before the cursor.
|
836
|
3006 * Returns the character to be used, NUL if the work is done and another char
|
|
3007 * to be got from the user.
|
657
|
3008 */
|
|
3009 static int
|
|
3010 ins_compl_bs()
|
|
3011 {
|
|
3012 char_u *line;
|
|
3013 char_u *p;
|
|
3014
|
836
|
3015 line = ml_get_curline();
|
|
3016 p = line + curwin->w_cursor.col;
|
|
3017 mb_ptr_back(line, p);
|
|
3018
|
|
3019 /* Stop completion when the whole word was deleted. */
|
|
3020 if ((int)(p - line) - (int)compl_col <= 0)
|
|
3021 return K_BS;
|
|
3022
|
874
|
3023 /* For redo we need to repeat this backspace. */
|
|
3024 AppendCharToRedobuff(K_BS);
|
|
3025
|
|
3026 /* Deleted more than what was used to find matches or didn't finish
|
|
3027 * finding all matches: need to look for matches all over again. */
|
|
3028 if (curwin->w_cursor.col <= compl_col + compl_length
|
|
3029 || compl_was_interrupted)
|
|
3030 ins_compl_restart();
|
657
|
3031
|
|
3032 vim_free(compl_leader);
|
835
|
3033 compl_leader = vim_strnsave(line + compl_col, (int)(p - line) - compl_col);
|
657
|
3034 if (compl_leader != NULL)
|
|
3035 {
|
874
|
3036 ins_compl_new_leader();
|
|
3037 return NUL;
|
|
3038 }
|
|
3039 return K_BS;
|
|
3040 }
|
|
3041
|
|
3042 /*
|
|
3043 * Called after changing "compl_leader".
|
|
3044 * Show the popup menu with a different set of matches.
|
|
3045 * May also search for matches again if the previous search was interrupted.
|
|
3046 */
|
|
3047 static void
|
|
3048 ins_compl_new_leader()
|
|
3049 {
|
|
3050 ins_compl_del_pum();
|
|
3051 ins_compl_delete();
|
|
3052 ins_bytes(compl_leader + curwin->w_cursor.col - compl_col);
|
|
3053 compl_used_match = FALSE;
|
|
3054
|
|
3055 if (compl_started)
|
|
3056 ins_compl_set_original_text(compl_leader);
|
|
3057 else
|
|
3058 {
|
826
|
3059 #ifdef FEAT_SPELL
|
874
|
3060 spell_bad_len = 0; /* need to redetect bad word */
|
|
3061 #endif
|
|
3062 /*
|
|
3063 * Matches were cleared, need to search for them now. First display
|
|
3064 * the changed text before the cursor. Set "compl_restarting" to
|
|
3065 * avoid that the first match is inserted.
|
|
3066 */
|
|
3067 update_screen(0);
|
|
3068 #ifdef FEAT_GUI
|
|
3069 if (gui.in_use)
|
|
3070 {
|
|
3071 /* Show the cursor after the match, not after the redrawn text. */
|
|
3072 setcursor();
|
|
3073 out_flush();
|
|
3074 gui_update_cursor(FALSE, FALSE);
|
|
3075 }
|
|
3076 #endif
|
|
3077 compl_restarting = TRUE;
|
|
3078 if (ins_complete(Ctrl_N) == FAIL)
|
|
3079 compl_cont_status = 0;
|
|
3080 compl_restarting = FALSE;
|
|
3081 }
|
|
3082
|
887
|
3083 #if 0 /* disabled, made CTRL-L, BS and typing char jump to original text. */
|
874
|
3084 if (!compl_used_match)
|
|
3085 {
|
829
|
3086 /* Go to the original text, since none of the matches is inserted. */
|
|
3087 if (compl_first_match->cp_prev != NULL
|
|
3088 && (compl_first_match->cp_prev->cp_flags & ORIGINAL_TEXT))
|
|
3089 compl_shown_match = compl_first_match->cp_prev;
|
|
3090 else
|
|
3091 compl_shown_match = compl_first_match;
|
|
3092 compl_curr_match = compl_shown_match;
|
|
3093 compl_shows_dir = compl_direction;
|
874
|
3094 }
|
887
|
3095 #endif
|
|
3096 compl_enter_selects = !compl_used_match;
|
874
|
3097
|
|
3098 /* Show the popup menu with a different set of matches. */
|
|
3099 ins_compl_show_pum();
|
657
|
3100 }
|
|
3101
|
|
3102 /*
|
|
3103 * Append one character to the match leader. May reduce the number of
|
|
3104 * matches.
|
|
3105 */
|
|
3106 static void
|
|
3107 ins_compl_addleader(c)
|
|
3108 int c;
|
|
3109 {
|
|
3110 #ifdef FEAT_MBYTE
|
|
3111 int cc;
|
|
3112
|
|
3113 if (has_mbyte && (cc = (*mb_char2len)(c)) > 1)
|
|
3114 {
|
|
3115 char_u buf[MB_MAXBYTES + 1];
|
|
3116
|
|
3117 (*mb_char2bytes)(c, buf);
|
|
3118 buf[cc] = NUL;
|
|
3119 ins_char_bytes(buf, cc);
|
|
3120 }
|
|
3121 else
|
|
3122 #endif
|
|
3123 ins_char(c);
|
|
3124
|
874
|
3125 /* For redo we need to count this character so that the number of
|
|
3126 * backspaces is correct. */
|
|
3127 AppendCharToRedobuff(c);
|
|
3128
|
|
3129 /* If we didn't complete finding matches we must search again. */
|
|
3130 if (compl_was_interrupted)
|
|
3131 ins_compl_restart();
|
|
3132
|
657
|
3133 vim_free(compl_leader);
|
|
3134 compl_leader = vim_strnsave(ml_get_curline() + compl_col,
|
|
3135 curwin->w_cursor.col - compl_col);
|
|
3136 if (compl_leader != NULL)
|
874
|
3137 ins_compl_new_leader();
|
|
3138 }
|
|
3139
|
|
3140 /*
|
|
3141 * Setup for finding completions again without leaving CTRL-X mode. Used when
|
|
3142 * BS or a key was typed while still searching for matches.
|
|
3143 */
|
|
3144 static void
|
|
3145 ins_compl_restart()
|
|
3146 {
|
|
3147 ins_compl_free();
|
|
3148 compl_started = FALSE;
|
|
3149 compl_matches = 0;
|
|
3150 compl_cont_status = 0;
|
|
3151 compl_cont_mode = 0;
|
694
|
3152 }
|
|
3153
|
|
3154 /*
|
|
3155 * Set the first match, the original text.
|
|
3156 */
|
|
3157 static void
|
|
3158 ins_compl_set_original_text(str)
|
|
3159 char_u *str;
|
|
3160 {
|
|
3161 char_u *p;
|
|
3162
|
|
3163 /* Replace the original text entry. */
|
|
3164 if (compl_first_match->cp_flags & ORIGINAL_TEXT) /* safety check */
|
|
3165 {
|
|
3166 p = vim_strsave(str);
|
|
3167 if (p != NULL)
|
|
3168 {
|
|
3169 vim_free(compl_first_match->cp_str);
|
|
3170 compl_first_match->cp_str = p;
|
|
3171 }
|
657
|
3172 }
|
|
3173 }
|
|
3174
|
|
3175 /*
|
659
|
3176 * Append one character to the match leader. May reduce the number of
|
|
3177 * matches.
|
|
3178 */
|
|
3179 static void
|
|
3180 ins_compl_addfrommatch()
|
|
3181 {
|
|
3182 char_u *p;
|
|
3183 int len = curwin->w_cursor.col - compl_col;
|
|
3184 int c;
|
887
|
3185 compl_T *cp;
|
659
|
3186
|
|
3187 p = compl_shown_match->cp_str;
|
677
|
3188 if ((int)STRLEN(p) <= len) /* the match is too short */
|
887
|
3189 {
|
|
3190 /* When still at the original match use the first entry that matches
|
|
3191 * the leader. */
|
|
3192 if (compl_shown_match->cp_flags & ORIGINAL_TEXT)
|
|
3193 {
|
|
3194 p = NULL;
|
|
3195 for (cp = compl_shown_match->cp_next; cp != NULL
|
|
3196 && cp != compl_first_match; cp = cp->cp_next)
|
|
3197 {
|
|
3198 if (ins_compl_equal(cp, compl_leader,
|
|
3199 (int)STRLEN(compl_leader)))
|
|
3200 {
|
|
3201 p = cp->cp_str;
|
|
3202 break;
|
|
3203 }
|
|
3204 }
|
|
3205 if (p == NULL || (int)STRLEN(p) <= len)
|
|
3206 return;
|
|
3207 }
|
|
3208 else
|
|
3209 return;
|
|
3210 }
|
659
|
3211 p += len;
|
|
3212 #ifdef FEAT_MBYTE
|
|
3213 c = mb_ptr2char(p);
|
|
3214 #else
|
|
3215 c = *p;
|
|
3216 #endif
|
|
3217 ins_compl_addleader(c);
|
|
3218 }
|
|
3219
|
|
3220 /*
|
7
|
3221 * Prepare for Insert mode completion, or stop it.
|
464
|
3222 * Called just after typing a character in Insert mode.
|
540
|
3223 * Returns TRUE when the character is not to be inserted;
|
7
|
3224 */
|
540
|
3225 static int
|
7
|
3226 ins_compl_prep(c)
|
|
3227 int c;
|
|
3228 {
|
|
3229 char_u *ptr;
|
|
3230 int temp;
|
|
3231 int want_cindent;
|
540
|
3232 int retval = FALSE;
|
7
|
3233
|
|
3234 /* Forget any previous 'special' messages if this is actually
|
|
3235 * a ^X mode key - bar ^R, in which case we wait to see what it gives us.
|
|
3236 */
|
|
3237 if (c != Ctrl_R && vim_is_ctrl_x_key(c))
|
|
3238 edit_submode_extra = NULL;
|
|
3239
|
|
3240 /* Ignore end of Select mode mapping */
|
|
3241 if (c == K_SELECT)
|
540
|
3242 return retval;
|
7
|
3243
|
665
|
3244 /* Set "compl_get_longest" when finding the first matches. */
|
|
3245 if (ctrl_x_mode == CTRL_X_NOT_DEFINED_YET
|
|
3246 || (ctrl_x_mode == 0 && !compl_started))
|
|
3247 {
|
|
3248 compl_get_longest = (vim_strchr(p_cot, 'l') != NULL);
|
|
3249 compl_used_match = TRUE;
|
|
3250 }
|
|
3251
|
7
|
3252 if (ctrl_x_mode == CTRL_X_NOT_DEFINED_YET)
|
|
3253 {
|
|
3254 /*
|
|
3255 * We have just typed CTRL-X and aren't quite sure which CTRL-X mode
|
|
3256 * it will be yet. Now we decide.
|
|
3257 */
|
|
3258 switch (c)
|
|
3259 {
|
|
3260 case Ctrl_E:
|
|
3261 case Ctrl_Y:
|
|
3262 ctrl_x_mode = CTRL_X_SCROLL;
|
|
3263 if (!(State & REPLACE_FLAG))
|
|
3264 edit_submode = (char_u *)_(" (insert) Scroll (^E/^Y)");
|
|
3265 else
|
|
3266 edit_submode = (char_u *)_(" (replace) Scroll (^E/^Y)");
|
|
3267 edit_submode_pre = NULL;
|
|
3268 showmode();
|
|
3269 break;
|
|
3270 case Ctrl_L:
|
|
3271 ctrl_x_mode = CTRL_X_WHOLE_LINE;
|
|
3272 break;
|
|
3273 case Ctrl_F:
|
|
3274 ctrl_x_mode = CTRL_X_FILES;
|
|
3275 break;
|
|
3276 case Ctrl_K:
|
|
3277 ctrl_x_mode = CTRL_X_DICTIONARY;
|
|
3278 break;
|
|
3279 case Ctrl_R:
|
|
3280 /* Simply allow ^R to happen without affecting ^X mode */
|
|
3281 break;
|
|
3282 case Ctrl_T:
|
|
3283 ctrl_x_mode = CTRL_X_THESAURUS;
|
|
3284 break;
|
12
|
3285 #ifdef FEAT_COMPL_FUNC
|
|
3286 case Ctrl_U:
|
|
3287 ctrl_x_mode = CTRL_X_FUNCTION;
|
|
3288 break;
|
449
|
3289 case Ctrl_O:
|
523
|
3290 ctrl_x_mode = CTRL_X_OMNI;
|
449
|
3291 break;
|
502
|
3292 #endif
|
477
|
3293 case 's':
|
|
3294 case Ctrl_S:
|
|
3295 ctrl_x_mode = CTRL_X_SPELL;
|
744
|
3296 #ifdef FEAT_SPELL
|
819
|
3297 ++emsg_off; /* Avoid getting the E756 error twice. */
|
484
|
3298 spell_back_to_badword();
|
819
|
3299 --emsg_off;
|
484
|
3300 #endif
|
477
|
3301 break;
|
7
|
3302 case Ctrl_RSB:
|
|
3303 ctrl_x_mode = CTRL_X_TAGS;
|
|
3304 break;
|
|
3305 #ifdef FEAT_FIND_ID
|
|
3306 case Ctrl_I:
|
|
3307 case K_S_TAB:
|
|
3308 ctrl_x_mode = CTRL_X_PATH_PATTERNS;
|
|
3309 break;
|
|
3310 case Ctrl_D:
|
|
3311 ctrl_x_mode = CTRL_X_PATH_DEFINES;
|
|
3312 break;
|
|
3313 #endif
|
|
3314 case Ctrl_V:
|
|
3315 case Ctrl_Q:
|
|
3316 ctrl_x_mode = CTRL_X_CMDLINE;
|
|
3317 break;
|
|
3318 case Ctrl_P:
|
|
3319 case Ctrl_N:
|
|
3320 /* ^X^P means LOCAL expansion if nothing interrupted (eg we
|
|
3321 * just started ^X mode, or there were enough ^X's to cancel
|
|
3322 * the previous mode, say ^X^F^X^X^P or ^P^X^X^X^P, see below)
|
|
3323 * do normal expansion when interrupting a different mode (say
|
|
3324 * ^X^F^X^P or ^P^X^X^P, see below)
|
|
3325 * nothing changes if interrupting mode 0, (eg, the flag
|
|
3326 * doesn't change when going to ADDING mode -- Acevedo */
|
449
|
3327 if (!(compl_cont_status & CONT_INTRPT))
|
|
3328 compl_cont_status |= CONT_LOCAL;
|
|
3329 else if (compl_cont_mode != 0)
|
|
3330 compl_cont_status &= ~CONT_LOCAL;
|
7
|
3331 /* FALLTHROUGH */
|
|
3332 default:
|
449
|
3333 /* If we have typed at least 2 ^X's... for modes != 0, we set
|
|
3334 * compl_cont_status = 0 (eg, as if we had just started ^X
|
|
3335 * mode).
|
|
3336 * For mode 0, we set "compl_cont_mode" to an impossible
|
|
3337 * value, in both cases ^X^X can be used to restart the same
|
|
3338 * mode (avoiding ADDING mode).
|
|
3339 * Undocumented feature: In a mode != 0 ^X^P and ^X^X^P start
|
|
3340 * 'complete' and local ^P expansions respectively.
|
|
3341 * In mode 0 an extra ^X is needed since ^X^P goes to ADDING
|
|
3342 * mode -- Acevedo */
|
7
|
3343 if (c == Ctrl_X)
|
|
3344 {
|
449
|
3345 if (compl_cont_mode != 0)
|
|
3346 compl_cont_status = 0;
|
7
|
3347 else
|
449
|
3348 compl_cont_mode = CTRL_X_NOT_DEFINED_YET;
|
7
|
3349 }
|
|
3350 ctrl_x_mode = 0;
|
|
3351 edit_submode = NULL;
|
|
3352 showmode();
|
|
3353 break;
|
|
3354 }
|
|
3355 }
|
|
3356 else if (ctrl_x_mode != 0)
|
|
3357 {
|
|
3358 /* We're already in CTRL-X mode, do we stay in it? */
|
|
3359 if (!vim_is_ctrl_x_key(c))
|
|
3360 {
|
|
3361 if (ctrl_x_mode == CTRL_X_SCROLL)
|
|
3362 ctrl_x_mode = 0;
|
|
3363 else
|
|
3364 ctrl_x_mode = CTRL_X_FINISHED;
|
|
3365 edit_submode = NULL;
|
|
3366 }
|
|
3367 showmode();
|
|
3368 }
|
|
3369
|
449
|
3370 if (compl_started || ctrl_x_mode == CTRL_X_FINISHED)
|
7
|
3371 {
|
|
3372 /* Show error message from attempted keyword completion (probably
|
|
3373 * 'Pattern not found') until another key is hit, then go back to
|
449
|
3374 * showing what mode we are in. */
|
7
|
3375 showmode();
|
644
|
3376 if ((ctrl_x_mode == 0 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_R
|
|
3377 && !ins_compl_pum_key(c))
|
7
|
3378 || ctrl_x_mode == CTRL_X_FINISHED)
|
|
3379 {
|
|
3380 /* Get here when we have finished typing a sequence of ^N and
|
|
3381 * ^P or other completion characters in CTRL-X mode. Free up
|
449
|
3382 * memory that was used, and make sure we can redo the insert. */
|
836
|
3383 if (compl_curr_match != NULL || compl_leader != NULL || c == Ctrl_E)
|
7
|
3384 {
|
449
|
3385 char_u *p;
|
|
3386
|
7
|
3387 /*
|
836
|
3388 * If any of the original typed text has been changed, eg when
|
|
3389 * ignorecase is set, we must add back-spaces to the redo
|
|
3390 * buffer. We add as few as necessary to delete just the part
|
|
3391 * of the original text that has changed.
|
|
3392 * When using the longest match, edited the match or used
|
|
3393 * CTRL-E then don't use the current match.
|
7
|
3394 */
|
836
|
3395 if (compl_curr_match != NULL && compl_used_match && c != Ctrl_E)
|
|
3396 ptr = compl_curr_match->cp_str;
|
|
3397 else if (compl_leader != NULL)
|
|
3398 ptr = compl_leader;
|
|
3399 else
|
|
3400 ptr = compl_orig_text;
|
897
|
3401 if (compl_orig_text != NULL)
|
|
3402 {
|
|
3403 p = compl_orig_text;
|
|
3404 for (temp = 0; p[temp] != NUL && p[temp] == ptr[temp];
|
|
3405 ++temp)
|
|
3406 ;
|
836
|
3407 #ifdef FEAT_MBYTE
|
897
|
3408 if (temp > 0)
|
|
3409 temp -= (*mb_head_off)(compl_orig_text, p + temp);
|
|
3410 #endif
|
|
3411 for (p += temp; *p != NUL; mb_ptr_adv(p))
|
|
3412 AppendCharToRedobuff(K_BS);
|
|
3413 }
|
|
3414 if (ptr != NULL)
|
|
3415 AppendToRedobuffLit(ptr + temp, -1);
|
7
|
3416 }
|
|
3417
|
|
3418 #ifdef FEAT_CINDENT
|
|
3419 want_cindent = (can_cindent && cindent_on());
|
|
3420 #endif
|
|
3421 /*
|
|
3422 * When completing whole lines: fix indent for 'cindent'.
|
|
3423 * Otherwise, break line if it's too long.
|
|
3424 */
|
449
|
3425 if (compl_cont_mode == CTRL_X_WHOLE_LINE)
|
7
|
3426 {
|
|
3427 #ifdef FEAT_CINDENT
|
|
3428 /* re-indent the current line */
|
|
3429 if (want_cindent)
|
|
3430 {
|
|
3431 do_c_expr_indent();
|
|
3432 want_cindent = FALSE; /* don't do it again */
|
|
3433 }
|
|
3434 #endif
|
|
3435 }
|
|
3436 else
|
|
3437 {
|
|
3438 /* put the cursor on the last char, for 'tw' formatting */
|
|
3439 curwin->w_cursor.col--;
|
|
3440 if (stop_arrow() == OK)
|
|
3441 insertchar(NUL, 0, -1);
|
|
3442 curwin->w_cursor.col++;
|
|
3443 }
|
|
3444
|
|
3445 auto_format(FALSE, TRUE);
|
|
3446
|
816
|
3447 /* If the popup menu is displayed pressing CTRL-Y means accepting
|
825
|
3448 * the selection without inserting anything. When
|
|
3449 * compl_enter_selects is set the Enter key does the same. */
|
|
3450 if ((c == Ctrl_Y || (compl_enter_selects
|
|
3451 && (c == CAR || c == K_KENTER || c == NL)))
|
|
3452 && pum_visible())
|
540
|
3453 retval = TRUE;
|
|
3454
|
816
|
3455 /* CTRL-E means completion is Ended, go back to the typed text. */
|
|
3456 if (c == Ctrl_E)
|
|
3457 {
|
|
3458 ins_compl_delete();
|
|
3459 if (compl_leader != NULL)
|
|
3460 ins_bytes(compl_leader + curwin->w_cursor.col - compl_col);
|
|
3461 else if (compl_first_match != NULL)
|
819
|
3462 ins_bytes(compl_orig_text
|
816
|
3463 + curwin->w_cursor.col - compl_col);
|
|
3464 retval = TRUE;
|
|
3465 }
|
|
3466
|
7
|
3467 ins_compl_free();
|
449
|
3468 compl_started = FALSE;
|
|
3469 compl_matches = 0;
|
7
|
3470 msg_clr_cmdline(); /* necessary for "noshowmode" */
|
|
3471 ctrl_x_mode = 0;
|
825
|
3472 compl_enter_selects = FALSE;
|
7
|
3473 if (edit_submode != NULL)
|
|
3474 {
|
|
3475 edit_submode = NULL;
|
|
3476 showmode();
|
|
3477 }
|
|
3478
|
|
3479 #ifdef FEAT_CINDENT
|
|
3480 /*
|
|
3481 * Indent now if a key was typed that is in 'cinkeys'.
|
|
3482 */
|
|
3483 if (want_cindent && in_cinkeys(KEY_COMPLETE, ' ', inindent(0)))
|
|
3484 do_c_expr_indent();
|
|
3485 #endif
|
|
3486 }
|
|
3487 }
|
|
3488
|
|
3489 /* reset continue_* if we left expansion-mode, if we stay they'll be
|
|
3490 * (re)set properly in ins_complete() */
|
|
3491 if (!vim_is_ctrl_x_key(c))
|
|
3492 {
|
449
|
3493 compl_cont_status = 0;
|
|
3494 compl_cont_mode = 0;
|
7
|
3495 }
|
540
|
3496
|
|
3497 return retval;
|
7
|
3498 }
|
|
3499
|
|
3500 /*
|
|
3501 * Loops through the list of windows, loaded-buffers or non-loaded-buffers
|
|
3502 * (depending on flag) starting from buf and looking for a non-scanned
|
|
3503 * buffer (other than curbuf). curbuf is special, if it is called with
|
|
3504 * buf=curbuf then it has to be the first call for a given flag/expansion.
|
|
3505 *
|
|
3506 * Returns the buffer to scan, if any, otherwise returns curbuf -- Acevedo
|
|
3507 */
|
|
3508 static buf_T *
|
|
3509 ins_compl_next_buf(buf, flag)
|
|
3510 buf_T *buf;
|
|
3511 int flag;
|
|
3512 {
|
|
3513 #ifdef FEAT_WINDOWS
|
|
3514 static win_T *wp;
|
|
3515 #endif
|
|
3516
|
|
3517 if (flag == 'w') /* just windows */
|
|
3518 {
|
|
3519 #ifdef FEAT_WINDOWS
|
|
3520 if (buf == curbuf) /* first call for this flag/expansion */
|
|
3521 wp = curwin;
|
383
|
3522 while ((wp = (wp->w_next != NULL ? wp->w_next : firstwin)) != curwin
|
7
|
3523 && wp->w_buffer->b_scanned)
|
|
3524 ;
|
|
3525 buf = wp->w_buffer;
|
|
3526 #else
|
|
3527 buf = curbuf;
|
|
3528 #endif
|
|
3529 }
|
|
3530 else
|
|
3531 /* 'b' (just loaded buffers), 'u' (just non-loaded buffers) or 'U'
|
|
3532 * (unlisted buffers)
|
|
3533 * When completing whole lines skip unloaded buffers. */
|
383
|
3534 while ((buf = (buf->b_next != NULL ? buf->b_next : firstbuf)) != curbuf
|
7
|
3535 && ((flag == 'U'
|
|
3536 ? buf->b_p_bl
|
|
3537 : (!buf->b_p_bl
|
|
3538 || (buf->b_ml.ml_mfp == NULL) != (flag == 'u')))
|
667
|
3539 || buf->b_scanned))
|
7
|
3540 ;
|
|
3541 return buf;
|
|
3542 }
|
|
3543
|
12
|
3544 #ifdef FEAT_COMPL_FUNC
|
659
|
3545 static void expand_by_function __ARGS((int type, char_u *base));
|
12
|
3546
|
|
3547 /*
|
523
|
3548 * Execute user defined complete function 'completefunc' or 'omnifunc', and
|
502
|
3549 * get matches in "matches".
|
12
|
3550 */
|
659
|
3551 static void
|
|
3552 expand_by_function(type, base)
|
523
|
3553 int type; /* CTRL_X_OMNI or CTRL_X_FUNCTION */
|
12
|
3554 char_u *base;
|
|
3555 {
|
452
|
3556 list_T *matchlist;
|
502
|
3557 char_u *args[2];
|
|
3558 char_u *funcname;
|
|
3559 pos_T pos;
|
|
3560
|
|
3561 funcname = (type == CTRL_X_FUNCTION) ? curbuf->b_p_cfu : curbuf->b_p_ofu;
|
|
3562 if (*funcname == NUL)
|
659
|
3563 return;
|
452
|
3564
|
|
3565 /* Call 'completefunc' to obtain the list of matches. */
|
|
3566 args[0] = (char_u *)"0";
|
502
|
3567 args[1] = base;
|
|
3568
|
|
3569 pos = curwin->w_cursor;
|
|
3570 matchlist = call_func_retlist(funcname, 2, args, FALSE);
|
|
3571 curwin->w_cursor = pos; /* restore the cursor position */
|
452
|
3572 if (matchlist == NULL)
|
659
|
3573 return;
|
|
3574
|
724
|
3575 ins_compl_add_list(matchlist);
|
|
3576 list_unref(matchlist);
|
|
3577 }
|
|
3578 #endif /* FEAT_COMPL_FUNC */
|
|
3579
|
786
|
3580 #if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL) || defined(PROTO)
|
724
|
3581 /*
|
|
3582 * Add completions from a list.
|
|
3583 */
|
|
3584 static void
|
|
3585 ins_compl_add_list(list)
|
|
3586 list_T *list;
|
|
3587 {
|
|
3588 listitem_T *li;
|
|
3589 int dir = compl_direction;
|
|
3590
|
659
|
3591 /* Go through the List with matches and add each of them. */
|
724
|
3592 for (li = list->lv_first; li != NULL; li = li->li_next)
|
452
|
3593 {
|
786
|
3594 if (ins_compl_add_tv(&li->li_tv, dir) == OK)
|
|
3595 /* if dir was BACKWARD then honor it just once */
|
|
3596 dir = FORWARD;
|
648
|
3597 else if (did_emsg)
|
|
3598 break;
|
452
|
3599 }
|
724
|
3600 }
|
786
|
3601
|
|
3602 /*
|
|
3603 * Add a match to the list of matches from a typeval_T.
|
|
3604 * If the given string is already in the list of completions, then return
|
|
3605 * NOTDONE, otherwise add it to the list and return OK. If there is an error,
|
|
3606 * maybe because alloc() returns NULL, then FAIL is returned.
|
|
3607 */
|
|
3608 int
|
|
3609 ins_compl_add_tv(tv, dir)
|
|
3610 typval_T *tv;
|
|
3611 int dir;
|
|
3612 {
|
|
3613 char_u *word;
|
867
|
3614 int icase = FALSE;
|
841
|
3615 int dup = FALSE;
|
786
|
3616 char_u *(cptext[CPT_COUNT]);
|
|
3617
|
|
3618 if (tv->v_type == VAR_DICT && tv->vval.v_dict != NULL)
|
|
3619 {
|
|
3620 word = get_dict_string(tv->vval.v_dict, (char_u *)"word", FALSE);
|
|
3621 cptext[CPT_ABBR] = get_dict_string(tv->vval.v_dict,
|
|
3622 (char_u *)"abbr", FALSE);
|
|
3623 cptext[CPT_MENU] = get_dict_string(tv->vval.v_dict,
|
|
3624 (char_u *)"menu", FALSE);
|
|
3625 cptext[CPT_KIND] = get_dict_string(tv->vval.v_dict,
|
|
3626 (char_u *)"kind", FALSE);
|
|
3627 cptext[CPT_INFO] = get_dict_string(tv->vval.v_dict,
|
|
3628 (char_u *)"info", FALSE);
|
|
3629 if (get_dict_string(tv->vval.v_dict, (char_u *)"icase", FALSE) != NULL)
|
|
3630 icase = get_dict_number(tv->vval.v_dict, (char_u *)"icase");
|
841
|
3631 if (get_dict_string(tv->vval.v_dict, (char_u *)"dup", FALSE) != NULL)
|
|
3632 dup = get_dict_number(tv->vval.v_dict, (char_u *)"dup");
|
786
|
3633 }
|
|
3634 else
|
|
3635 {
|
|
3636 word = get_tv_string_chk(tv);
|
|
3637 vim_memset(cptext, 0, sizeof(cptext));
|
|
3638 }
|
|
3639 if (word == NULL || *word == NUL)
|
|
3640 return FAIL;
|
841
|
3641 return ins_compl_add(word, -1, icase, NULL, cptext, dir, 0, dup);
|
786
|
3642 }
|
724
|
3643 #endif
|
12
|
3644
|
449
|
3645 /*
|
|
3646 * Get the next expansion(s), using "compl_pattern".
|
659
|
3647 * The search starts at position "ini" in curbuf and in the direction
|
|
3648 * compl_direction.
|
667
|
3649 * When "compl_started" is FALSE start at that position, otherwise continue
|
|
3650 * where we stopped searching before.
|
449
|
3651 * This may return before finding all the matches.
|
|
3652 * Return the total number of matches or -1 if still unknown -- Acevedo
|
7
|
3653 */
|
|
3654 static int
|
659
|
3655 ins_compl_get_exp(ini)
|
7
|
3656 pos_T *ini;
|
|
3657 {
|
|
3658 static pos_T first_match_pos;
|
|
3659 static pos_T last_match_pos;
|
|
3660 static char_u *e_cpt = (char_u *)""; /* curr. entry in 'complete' */
|
449
|
3661 static int found_all = FALSE; /* Found all matches of a
|
|
3662 certain type. */
|
|
3663 static buf_T *ins_buf = NULL; /* buffer being scanned */
|
7
|
3664
|
464
|
3665 pos_T *pos;
|
|
3666 char_u **matches;
|
|
3667 int save_p_scs;
|
|
3668 int save_p_ws;
|
|
3669 int save_p_ic;
|
|
3670 int i;
|
|
3671 int num_matches;
|
|
3672 int len;
|
|
3673 int found_new_match;
|
|
3674 int type = ctrl_x_mode;
|
|
3675 char_u *ptr;
|
|
3676 char_u *dict = NULL;
|
|
3677 int dict_f = 0;
|
|
3678 compl_T *old_match;
|
7
|
3679
|
449
|
3680 if (!compl_started)
|
7
|
3681 {
|
|
3682 for (ins_buf = firstbuf; ins_buf != NULL; ins_buf = ins_buf->b_next)
|
|
3683 ins_buf->b_scanned = 0;
|
|
3684 found_all = FALSE;
|
|
3685 ins_buf = curbuf;
|
449
|
3686 e_cpt = (compl_cont_status & CONT_LOCAL)
|
12
|
3687 ? (char_u *)"." : curbuf->b_p_cpt;
|
7
|
3688 last_match_pos = first_match_pos = *ini;
|
|
3689 }
|
|
3690
|
449
|
3691 old_match = compl_curr_match; /* remember the last current match */
|
659
|
3692 pos = (compl_direction == FORWARD) ? &last_match_pos : &first_match_pos;
|
7
|
3693 /* For ^N/^P loop over all the flags/windows/buffers in 'complete' */
|
|
3694 for (;;)
|
|
3695 {
|
|
3696 found_new_match = FAIL;
|
|
3697
|
449
|
3698 /* For ^N/^P pick a new entry from e_cpt if compl_started is off,
|
7
|
3699 * or if found_all says this entry is done. For ^X^L only use the
|
|
3700 * entries from 'complete' that look in loaded buffers. */
|
|
3701 if ((ctrl_x_mode == 0 || ctrl_x_mode == CTRL_X_WHOLE_LINE)
|
449
|
3702 && (!compl_started || found_all))
|
7
|
3703 {
|
|
3704 found_all = FALSE;
|
|
3705 while (*e_cpt == ',' || *e_cpt == ' ')
|
|
3706 e_cpt++;
|
|
3707 if (*e_cpt == '.' && !curbuf->b_scanned)
|
|
3708 {
|
|
3709 ins_buf = curbuf;
|
|
3710 first_match_pos = *ini;
|
|
3711 /* So that ^N can match word immediately after cursor */
|
|
3712 if (ctrl_x_mode == 0)
|
|
3713 dec(&first_match_pos);
|
|
3714 last_match_pos = first_match_pos;
|
|
3715 type = 0;
|
|
3716 }
|
|
3717 else if (vim_strchr((char_u *)"buwU", *e_cpt) != NULL
|
|
3718 && (ins_buf = ins_compl_next_buf(ins_buf, *e_cpt)) != curbuf)
|
|
3719 {
|
|
3720 /* Scan a buffer, but not the current one. */
|
|
3721 if (ins_buf->b_ml.ml_mfp != NULL) /* loaded buffer */
|
|
3722 {
|
449
|
3723 compl_started = TRUE;
|
7
|
3724 first_match_pos.col = last_match_pos.col = 0;
|
|
3725 first_match_pos.lnum = ins_buf->b_ml.ml_line_count + 1;
|
|
3726 last_match_pos.lnum = 0;
|
|
3727 type = 0;
|
|
3728 }
|
|
3729 else /* unloaded buffer, scan like dictionary */
|
|
3730 {
|
|
3731 found_all = TRUE;
|
|
3732 if (ins_buf->b_fname == NULL)
|
|
3733 continue;
|
|
3734 type = CTRL_X_DICTIONARY;
|
|
3735 dict = ins_buf->b_fname;
|
|
3736 dict_f = DICT_EXACT;
|
|
3737 }
|
274
|
3738 vim_snprintf((char *)IObuff, IOSIZE, _("Scanning: %s"),
|
7
|
3739 ins_buf->b_fname == NULL
|
|
3740 ? buf_spname(ins_buf)
|
|
3741 : ins_buf->b_sfname == NULL
|
|
3742 ? (char *)ins_buf->b_fname
|
|
3743 : (char *)ins_buf->b_sfname);
|
|
3744 msg_trunc_attr(IObuff, TRUE, hl_attr(HLF_R));
|
|
3745 }
|
|
3746 else if (*e_cpt == NUL)
|
|
3747 break;
|
|
3748 else
|
|
3749 {
|
|
3750 if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
|
|
3751 type = -1;
|
|
3752 else if (*e_cpt == 'k' || *e_cpt == 's')
|
|
3753 {
|
|
3754 if (*e_cpt == 'k')
|
|
3755 type = CTRL_X_DICTIONARY;
|
|
3756 else
|
|
3757 type = CTRL_X_THESAURUS;
|
|
3758 if (*++e_cpt != ',' && *e_cpt != NUL)
|
|
3759 {
|
|
3760 dict = e_cpt;
|
|
3761 dict_f = DICT_FIRST;
|
|
3762 }
|
|
3763 }
|
|
3764 #ifdef FEAT_FIND_ID
|
|
3765 else if (*e_cpt == 'i')
|
|
3766 type = CTRL_X_PATH_PATTERNS;
|
|
3767 else if (*e_cpt == 'd')
|
|
3768 type = CTRL_X_PATH_DEFINES;
|
|
3769 #endif
|
|
3770 else if (*e_cpt == ']' || *e_cpt == 't')
|
|
3771 {
|
|
3772 type = CTRL_X_TAGS;
|
|
3773 sprintf((char*)IObuff, _("Scanning tags."));
|
|
3774 msg_trunc_attr(IObuff, TRUE, hl_attr(HLF_R));
|
|
3775 }
|
|
3776 else
|
|
3777 type = -1;
|
|
3778
|
|
3779 /* in any case e_cpt is advanced to the next entry */
|
|
3780 (void)copy_option_part(&e_cpt, IObuff, IOSIZE, ",");
|
|
3781
|
|
3782 found_all = TRUE;
|
|
3783 if (type == -1)
|
|
3784 continue;
|
|
3785 }
|
|
3786 }
|
|
3787
|
|
3788 switch (type)
|
|
3789 {
|
|
3790 case -1:
|
|
3791 break;
|
|
3792 #ifdef FEAT_FIND_ID
|
|
3793 case CTRL_X_PATH_PATTERNS:
|
|
3794 case CTRL_X_PATH_DEFINES:
|
659
|
3795 find_pattern_in_path(compl_pattern, compl_direction,
|
449
|
3796 (int)STRLEN(compl_pattern), FALSE, FALSE,
|
7
|
3797 (type == CTRL_X_PATH_DEFINES
|
449
|
3798 && !(compl_cont_status & CONT_SOL))
|
7
|
3799 ? FIND_DEFINE : FIND_ANY, 1L, ACTION_EXPAND,
|
|
3800 (linenr_T)1, (linenr_T)MAXLNUM);
|
|
3801 break;
|
|
3802 #endif
|
|
3803
|
|
3804 case CTRL_X_DICTIONARY:
|
|
3805 case CTRL_X_THESAURUS:
|
|
3806 ins_compl_dictionaries(
|
703
|
3807 dict != NULL ? dict
|
7
|
3808 : (type == CTRL_X_THESAURUS
|
|
3809 ? (*curbuf->b_p_tsr == NUL
|
|
3810 ? p_tsr
|
|
3811 : curbuf->b_p_tsr)
|
|
3812 : (*curbuf->b_p_dict == NUL
|
|
3813 ? p_dict
|
|
3814 : curbuf->b_p_dict)),
|
659
|
3815 compl_pattern,
|
703
|
3816 dict != NULL ? dict_f
|
|
3817 : 0, type == CTRL_X_THESAURUS);
|
7
|
3818 dict = NULL;
|
|
3819 break;
|
|
3820
|
|
3821 case CTRL_X_TAGS:
|
|
3822 /* set p_ic according to p_ic, p_scs and pat for find_tags(). */
|
|
3823 save_p_ic = p_ic;
|
449
|
3824 p_ic = ignorecase(compl_pattern);
|
7
|
3825
|
|
3826 /* Find up to TAG_MANY matches. Avoids that an enourmous number
|
449
|
3827 * of matches is found when compl_pattern is empty */
|
|
3828 if (find_tags(compl_pattern, &num_matches, &matches,
|
7
|
3829 TAG_REGEXP | TAG_NAMES | TAG_NOIC |
|
|
3830 TAG_INS_COMP | (ctrl_x_mode ? TAG_VERBOSE : 0),
|
|
3831 TAG_MANY, curbuf->b_ffname) == OK && num_matches > 0)
|
|
3832 {
|
867
|
3833 ins_compl_add_matches(num_matches, matches, FALSE);
|
7
|
3834 }
|
|
3835 p_ic = save_p_ic;
|
|
3836 break;
|
|
3837
|
|
3838 case CTRL_X_FILES:
|
449
|
3839 if (expand_wildcards(1, &compl_pattern, &num_matches, &matches,
|
7
|
3840 EW_FILE|EW_DIR|EW_ADDSLASH|EW_SILENT) == OK)
|
|
3841 {
|
|
3842
|
|
3843 /* May change home directory back to "~". */
|
449
|
3844 tilde_replace(compl_pattern, num_matches, matches);
|
681
|
3845 ins_compl_add_matches(num_matches, matches,
|
|
3846 #ifdef CASE_INSENSITIVE_FILENAME
|
|
3847 TRUE
|
|
3848 #else
|
|
3849 FALSE
|
|
3850 #endif
|
|
3851 );
|
7
|
3852 }
|
|
3853 break;
|
|
3854
|
|
3855 case CTRL_X_CMDLINE:
|
449
|
3856 if (expand_cmdline(&compl_xp, compl_pattern,
|
|
3857 (int)STRLEN(compl_pattern),
|
7
|
3858 &num_matches, &matches) == EXPAND_OK)
|
681
|
3859 ins_compl_add_matches(num_matches, matches, FALSE);
|
7
|
3860 break;
|
|
3861
|
12
|
3862 #ifdef FEAT_COMPL_FUNC
|
|
3863 case CTRL_X_FUNCTION:
|
523
|
3864 case CTRL_X_OMNI:
|
659
|
3865 expand_by_function(type, compl_pattern);
|
12
|
3866 break;
|
|
3867 #endif
|
|
3868
|
477
|
3869 case CTRL_X_SPELL:
|
744
|
3870 #ifdef FEAT_SPELL
|
477
|
3871 num_matches = expand_spelling(first_match_pos.lnum,
|
|
3872 first_match_pos.col, compl_pattern, &matches);
|
|
3873 if (num_matches > 0)
|
681
|
3874 ins_compl_add_matches(num_matches, matches, FALSE);
|
477
|
3875 #endif
|
|
3876 break;
|
|
3877
|
7
|
3878 default: /* normal ^P/^N and ^X^L */
|
|
3879 /*
|
|
3880 * If 'infercase' is set, don't use 'smartcase' here
|
|
3881 */
|
|
3882 save_p_scs = p_scs;
|
|
3883 if (ins_buf->b_p_inf)
|
|
3884 p_scs = FALSE;
|
449
|
3885
|
7
|
3886 /* buffers other than curbuf are scanned from the beginning or the
|
|
3887 * end but never from the middle, thus setting nowrapscan in this
|
|
3888 * buffers is a good idea, on the other hand, we always set
|
|
3889 * wrapscan for curbuf to avoid missing matches -- Acevedo,Webb */
|
|
3890 save_p_ws = p_ws;
|
|
3891 if (ins_buf != curbuf)
|
|
3892 p_ws = FALSE;
|
|
3893 else if (*e_cpt == '.')
|
|
3894 p_ws = TRUE;
|
|
3895 for (;;)
|
|
3896 {
|
464
|
3897 int flags = 0;
|
7
|
3898
|
540
|
3899 /* ctrl_x_mode == CTRL_X_WHOLE_LINE || word-wise search that
|
|
3900 * has added a word that was at the beginning of the line */
|
7
|
3901 if ( ctrl_x_mode == CTRL_X_WHOLE_LINE
|
449
|
3902 || (compl_cont_status & CONT_SOL))
|
7
|
3903 found_new_match = search_for_exact_line(ins_buf, pos,
|
659
|
3904 compl_direction, compl_pattern);
|
7
|
3905 else
|
659
|
3906 found_new_match = searchit(NULL, ins_buf, pos,
|
|
3907 compl_direction,
|
449
|
3908 compl_pattern, 1L, SEARCH_KEEP + SEARCH_NFMSG,
|
692
|
3909 RE_LAST, (linenr_T)0);
|
449
|
3910 if (!compl_started)
|
7
|
3911 {
|
667
|
3912 /* set "compl_started" even on fail */
|
449
|
3913 compl_started = TRUE;
|
7
|
3914 first_match_pos = *pos;
|
|
3915 last_match_pos = *pos;
|
|
3916 }
|
|
3917 else if (first_match_pos.lnum == last_match_pos.lnum
|
665
|
3918 && first_match_pos.col == last_match_pos.col)
|
7
|
3919 found_new_match = FAIL;
|
|
3920 if (found_new_match == FAIL)
|
|
3921 {
|
|
3922 if (ins_buf == curbuf)
|
|
3923 found_all = TRUE;
|
|
3924 break;
|
|
3925 }
|
|
3926
|
|
3927 /* when ADDING, the text before the cursor matches, skip it */
|
449
|
3928 if ( (compl_cont_status & CONT_ADDING) && ins_buf == curbuf
|
7
|
3929 && ini->lnum == pos->lnum
|
|
3930 && ini->col == pos->col)
|
|
3931 continue;
|
|
3932 ptr = ml_get_buf(ins_buf, pos->lnum, FALSE) + pos->col;
|
|
3933 if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
|
|
3934 {
|
449
|
3935 if (compl_cont_status & CONT_ADDING)
|
7
|
3936 {
|
|
3937 if (pos->lnum >= ins_buf->b_ml.ml_line_count)
|
|
3938 continue;
|
|
3939 ptr = ml_get_buf(ins_buf, pos->lnum + 1, FALSE);
|
|
3940 if (!p_paste)
|
|
3941 ptr = skipwhite(ptr);
|
|
3942 }
|
|
3943 len = (int)STRLEN(ptr);
|
|
3944 }
|
|
3945 else
|
|
3946 {
|
449
|
3947 char_u *tmp_ptr = ptr;
|
|
3948
|
|
3949 if (compl_cont_status & CONT_ADDING)
|
7
|
3950 {
|
449
|
3951 tmp_ptr += compl_length;
|
7
|
3952 /* Skip if already inside a word. */
|
|
3953 if (vim_iswordp(tmp_ptr))
|
|
3954 continue;
|
|
3955 /* Find start of next word. */
|
|
3956 tmp_ptr = find_word_start(tmp_ptr);
|
|
3957 }
|
|
3958 /* Find end of this word. */
|
|
3959 tmp_ptr = find_word_end(tmp_ptr);
|
|
3960 len = (int)(tmp_ptr - ptr);
|
|
3961
|
449
|
3962 if ((compl_cont_status & CONT_ADDING)
|
|
3963 && len == compl_length)
|
7
|
3964 {
|
|
3965 if (pos->lnum < ins_buf->b_ml.ml_line_count)
|
|
3966 {
|
|
3967 /* Try next line, if any. the new word will be
|
|
3968 * "join" as if the normal command "J" was used.
|
|
3969 * IOSIZE is always greater than
|
449
|
3970 * compl_length, so the next STRNCPY always
|
7
|
3971 * works -- Acevedo */
|
|
3972 STRNCPY(IObuff, ptr, len);
|
|
3973 ptr = ml_get_buf(ins_buf, pos->lnum + 1, FALSE);
|
|
3974 tmp_ptr = ptr = skipwhite(ptr);
|
|
3975 /* Find start of next word. */
|
|
3976 tmp_ptr = find_word_start(tmp_ptr);
|
|
3977 /* Find end of next word. */
|
|
3978 tmp_ptr = find_word_end(tmp_ptr);
|
|
3979 if (tmp_ptr > ptr)
|
|
3980 {
|
419
|
3981 if (*ptr != ')' && IObuff[len - 1] != TAB)
|
7
|
3982 {
|
419
|
3983 if (IObuff[len - 1] != ' ')
|
7
|
3984 IObuff[len++] = ' ';
|
|
3985 /* IObuf =~ "\k.* ", thus len >= 2 */
|
|
3986 if (p_js
|
419
|
3987 && (IObuff[len - 2] == '.'
|
7
|
3988 || (vim_strchr(p_cpo, CPO_JOINSP)
|
|
3989 == NULL
|
419
|
3990 && (IObuff[len - 2] == '?'
|
|
3991 || IObuff[len - 2] == '!'))))
|
7
|
3992 IObuff[len++] = ' ';
|
|
3993 }
|
|
3994 /* copy as much as posible of the new word */
|
|
3995 if (tmp_ptr - ptr >= IOSIZE - len)
|
|
3996 tmp_ptr = ptr + IOSIZE - len - 1;
|
|
3997 STRNCPY(IObuff + len, ptr, tmp_ptr - ptr);
|
|
3998 len += (int)(tmp_ptr - ptr);
|
464
|
3999 flags |= CONT_S_IPOS;
|
7
|
4000 }
|
|
4001 IObuff[len] = NUL;
|
|
4002 ptr = IObuff;
|
|
4003 }
|
449
|
4004 if (len == compl_length)
|
7
|
4005 continue;
|
|
4006 }
|
|
4007 }
|
867
|
4008 if (ins_compl_add_infercase(ptr, len, FALSE,
|
540
|
4009 ins_buf == curbuf ? NULL : ins_buf->b_sfname,
|
659
|
4010 0, flags) != NOTDONE)
|
7
|
4011 {
|
|
4012 found_new_match = OK;
|
|
4013 break;
|
|
4014 }
|
|
4015 }
|
|
4016 p_scs = save_p_scs;
|
|
4017 p_ws = save_p_ws;
|
|
4018 }
|
540
|
4019
|
449
|
4020 /* check if compl_curr_match has changed, (e.g. other type of
|
|
4021 * expansion added somenthing) */
|
540
|
4022 if (type != 0 && compl_curr_match != old_match)
|
7
|
4023 found_new_match = OK;
|
|
4024
|
|
4025 /* break the loop for specialized modes (use 'complete' just for the
|
|
4026 * generic ctrl_x_mode == 0) or when we've found a new match */
|
|
4027 if ((ctrl_x_mode != 0 && ctrl_x_mode != CTRL_X_WHOLE_LINE)
|
449
|
4028 || found_new_match != FAIL)
|
540
|
4029 {
|
|
4030 if (got_int)
|
|
4031 break;
|
665
|
4032 /* Fill the popup menu as soon as possible. */
|
540
|
4033 if (pum_wanted() && type != -1)
|
|
4034 ins_compl_check_keys(0);
|
665
|
4035
|
540
|
4036 if ((ctrl_x_mode != 0 && ctrl_x_mode != CTRL_X_WHOLE_LINE)
|
|
4037 || compl_interrupted)
|
|
4038 break;
|
|
4039 compl_started = TRUE;
|
|
4040 }
|
|
4041 else
|
|
4042 {
|
|
4043 /* Mark a buffer scanned when it has been scanned completely */
|
|
4044 if (type == 0 || type == CTRL_X_PATH_PATTERNS)
|
|
4045 ins_buf->b_scanned = TRUE;
|
|
4046
|
|
4047 compl_started = FALSE;
|
|
4048 }
|
449
|
4049 }
|
|
4050 compl_started = TRUE;
|
7
|
4051
|
|
4052 if ((ctrl_x_mode == 0 || ctrl_x_mode == CTRL_X_WHOLE_LINE)
|
|
4053 && *e_cpt == NUL) /* Got to end of 'complete' */
|
|
4054 found_new_match = FAIL;
|
|
4055
|
|
4056 i = -1; /* total of matches, unknown */
|
|
4057 if (found_new_match == FAIL
|
|
4058 || (ctrl_x_mode != 0 && ctrl_x_mode != CTRL_X_WHOLE_LINE))
|
|
4059 i = ins_compl_make_cyclic();
|
|
4060
|
|
4061 /* If several matches were added (FORWARD) or the search failed and has
|
449
|
4062 * just been made cyclic then we have to move compl_curr_match to the next
|
|
4063 * or previous entry (if any) -- Acevedo */
|
724
|
4064 compl_curr_match = compl_direction == FORWARD ? old_match->cp_next
|
|
4065 : old_match->cp_prev;
|
449
|
4066 if (compl_curr_match == NULL)
|
|
4067 compl_curr_match = old_match;
|
7
|
4068 return i;
|
|
4069 }
|
|
4070
|
|
4071 /* Delete the old text being completed. */
|
|
4072 static void
|
|
4073 ins_compl_delete()
|
|
4074 {
|
|
4075 int i;
|
|
4076
|
|
4077 /*
|
|
4078 * In insert mode: Delete the typed part.
|
|
4079 * In replace mode: Put the old characters back, if any.
|
|
4080 */
|
449
|
4081 i = compl_col + (compl_cont_status & CONT_ADDING ? compl_length : 0);
|
7
|
4082 backspace_until_column(i);
|
|
4083 changed_cline_bef_curs();
|
|
4084 }
|
|
4085
|
|
4086 /* Insert the new text being completed. */
|
|
4087 static void
|
|
4088 ins_compl_insert()
|
|
4089 {
|
464
|
4090 ins_bytes(compl_shown_match->cp_str + curwin->w_cursor.col - compl_col);
|
683
|
4091 if (compl_shown_match->cp_flags & ORIGINAL_TEXT)
|
|
4092 compl_used_match = FALSE;
|
|
4093 else
|
|
4094 compl_used_match = TRUE;
|
7
|
4095 }
|
|
4096
|
|
4097 /*
|
|
4098 * Fill in the next completion in the current direction.
|
464
|
4099 * If "allow_get_expansion" is TRUE, then we may call ins_compl_get_exp() to
|
|
4100 * get more completions. If it is FALSE, then we just do nothing when there
|
|
4101 * are no more completions in a given direction. The latter case is used when
|
|
4102 * we are still in the middle of finding completions, to allow browsing
|
|
4103 * through the ones found so far.
|
7
|
4104 * Return the total number of matches, or -1 if still unknown -- webb.
|
|
4105 *
|
449
|
4106 * compl_curr_match is currently being used by ins_compl_get_exp(), so we use
|
|
4107 * compl_shown_match here.
|
7
|
4108 *
|
|
4109 * Note that this function may be called recursively once only. First with
|
464
|
4110 * "allow_get_expansion" TRUE, which calls ins_compl_get_exp(), which in turn
|
|
4111 * calls this function with "allow_get_expansion" FALSE.
|
7
|
4112 */
|
|
4113 static int
|
665
|
4114 ins_compl_next(allow_get_expansion, count, insert_match)
|
7
|
4115 int allow_get_expansion;
|
610
|
4116 int count; /* repeat completion this many times; should
|
|
4117 be at least 1 */
|
665
|
4118 int insert_match; /* Insert the newly selected match */
|
7
|
4119 {
|
|
4120 int num_matches = -1;
|
|
4121 int i;
|
610
|
4122 int todo = count;
|
657
|
4123 compl_T *found_compl = NULL;
|
|
4124 int found_end = FALSE;
|
836
|
4125 int advance;
|
7
|
4126
|
665
|
4127 if (compl_leader != NULL
|
|
4128 && (compl_shown_match->cp_flags & ORIGINAL_TEXT) == 0)
|
|
4129 {
|
|
4130 /* Set "compl_shown_match" to the actually shown match, it may differ
|
|
4131 * when "compl_leader" is used to omit some of the matches. */
|
681
|
4132 while (!ins_compl_equal(compl_shown_match,
|
835
|
4133 compl_leader, (int)STRLEN(compl_leader))
|
665
|
4134 && compl_shown_match->cp_next != NULL
|
|
4135 && compl_shown_match->cp_next != compl_first_match)
|
|
4136 compl_shown_match = compl_shown_match->cp_next;
|
887
|
4137
|
|
4138 /* If we didn't find it searching forward, and compl_shows_dir is
|
|
4139 * backward, find the last match. */
|
|
4140 if (compl_shows_dir == BACKWARD
|
|
4141 && !ins_compl_equal(compl_shown_match,
|
|
4142 compl_leader, (int)STRLEN(compl_leader))
|
|
4143 && (compl_shown_match->cp_next == NULL
|
|
4144 || compl_shown_match->cp_next == compl_first_match))
|
|
4145 {
|
|
4146 while (!ins_compl_equal(compl_shown_match,
|
|
4147 compl_leader, (int)STRLEN(compl_leader))
|
|
4148 && compl_shown_match->cp_prev != NULL
|
|
4149 && compl_shown_match->cp_prev != compl_first_match)
|
|
4150 compl_shown_match = compl_shown_match->cp_prev;
|
|
4151 }
|
665
|
4152 }
|
|
4153
|
|
4154 if (allow_get_expansion && insert_match
|
874
|
4155 && (!(compl_get_longest || compl_restarting) || compl_used_match))
|
7
|
4156 /* Delete old text to be replaced */
|
|
4157 ins_compl_delete();
|
665
|
4158
|
836
|
4159 /* When finding the longest common text we stick at the original text,
|
|
4160 * don't let CTRL-N or CTRL-P move to the first match. */
|
|
4161 advance = count != 1 || !allow_get_expansion || !compl_get_longest;
|
|
4162
|
874
|
4163 /* When restarting the search don't insert the first match either. */
|
|
4164 if (compl_restarting)
|
|
4165 {
|
|
4166 advance = FALSE;
|
|
4167 compl_restarting = FALSE;
|
|
4168 }
|
|
4169
|
610
|
4170 /* Repeat this for when <PageUp> or <PageDown> is typed. But don't wrap
|
|
4171 * around. */
|
|
4172 while (--todo >= 0)
|
|
4173 {
|
|
4174 if (compl_shows_dir == FORWARD && compl_shown_match->cp_next != NULL)
|
|
4175 {
|
716
|
4176 if (compl_pending != 0)
|
|
4177 --compl_pending;
|
610
|
4178 compl_shown_match = compl_shown_match->cp_next;
|
657
|
4179 found_end = (compl_first_match != NULL
|
|
4180 && (compl_shown_match->cp_next == compl_first_match
|
|
4181 || compl_shown_match == compl_first_match));
|
610
|
4182 }
|
|
4183 else if (compl_shows_dir == BACKWARD
|
|
4184 && compl_shown_match->cp_prev != NULL)
|
|
4185 {
|
716
|
4186 if (compl_pending != 0)
|
|
4187 ++compl_pending;
|
657
|
4188 found_end = (compl_shown_match == compl_first_match);
|
610
|
4189 compl_shown_match = compl_shown_match->cp_prev;
|
657
|
4190 found_end |= (compl_shown_match == compl_first_match);
|
7
|
4191 }
|
|
4192 else
|
610
|
4193 {
|
836
|
4194 if (advance)
|
|
4195 {
|
|
4196 if (compl_shows_dir == BACKWARD)
|
|
4197 --compl_pending;
|
|
4198 else
|
|
4199 ++compl_pending;
|
|
4200 }
|
657
|
4201 if (!allow_get_expansion)
|
|
4202 return -1;
|
|
4203
|
874
|
4204 /* Find matches. */
|
659
|
4205 num_matches = ins_compl_get_exp(&compl_startpos);
|
836
|
4206 if (compl_pending != 0 && compl_direction == compl_shows_dir
|
|
4207 && advance)
|
657
|
4208 compl_shown_match = compl_curr_match;
|
|
4209 found_end = FALSE;
|
|
4210 }
|
|
4211 if ((compl_shown_match->cp_flags & ORIGINAL_TEXT) == 0
|
|
4212 && compl_leader != NULL
|
681
|
4213 && !ins_compl_equal(compl_shown_match,
|
835
|
4214 compl_leader, (int)STRLEN(compl_leader)))
|
657
|
4215 ++todo;
|
|
4216 else
|
|
4217 /* Remember a matching item. */
|
|
4218 found_compl = compl_shown_match;
|
|
4219
|
|
4220 /* Stop at the end of the list when we found a usable match. */
|
|
4221 if (found_end)
|
|
4222 {
|
|
4223 if (found_compl != NULL)
|
610
|
4224 {
|
657
|
4225 compl_shown_match = found_compl;
|
|
4226 break;
|
610
|
4227 }
|
657
|
4228 todo = 1; /* use first usable match after wrapping around */
|
610
|
4229 }
|
7
|
4230 }
|
|
4231
|
665
|
4232 /* Insert the text of the new completion, or the compl_leader. */
|
|
4233 if (insert_match)
|
|
4234 {
|
|
4235 if (!compl_get_longest || compl_used_match)
|
|
4236 ins_compl_insert();
|
|
4237 else
|
|
4238 ins_bytes(compl_leader + curwin->w_cursor.col - compl_col);
|
|
4239 }
|
|
4240 else
|
|
4241 compl_used_match = FALSE;
|
7
|
4242
|
|
4243 if (!allow_get_expansion)
|
|
4244 {
|
540
|
4245 /* may undisplay the popup menu first */
|
|
4246 ins_compl_upd_pum();
|
|
4247
|
665
|
4248 /* redraw to show the user what was inserted */
|
|
4249 update_screen(0);
|
|
4250
|
540
|
4251 /* display the updated popup menu */
|
|
4252 ins_compl_show_pum();
|
864
|
4253 #ifdef FEAT_GUI
|
|
4254 if (gui.in_use)
|
|
4255 {
|
|
4256 /* Show the cursor after the match, not after the redrawn text. */
|
|
4257 setcursor();
|
|
4258 out_flush();
|
|
4259 gui_update_cursor(FALSE, FALSE);
|
|
4260 }
|
|
4261 #endif
|
540
|
4262
|
7
|
4263 /* Delete old text to be replaced, since we're still searching and
|
|
4264 * don't want to match ourselves! */
|
|
4265 ins_compl_delete();
|
|
4266 }
|
|
4267
|
825
|
4268 /* Enter will select a match when the match wasn't inserted and the popup
|
|
4269 * menu is visislbe. */
|
|
4270 compl_enter_selects = !insert_match && compl_match_array != NULL;
|
|
4271
|
7
|
4272 /*
|
|
4273 * Show the file name for the match (if any)
|
|
4274 * Truncate the file name to avoid a wait for return.
|
|
4275 */
|
464
|
4276 if (compl_shown_match->cp_fname != NULL)
|
7
|
4277 {
|
|
4278 STRCPY(IObuff, "match in file ");
|
464
|
4279 i = (vim_strsize(compl_shown_match->cp_fname) + 16) - sc_col;
|
7
|
4280 if (i <= 0)
|
|
4281 i = 0;
|
|
4282 else
|
|
4283 STRCAT(IObuff, "<");
|
464
|
4284 STRCAT(IObuff, compl_shown_match->cp_fname + i);
|
7
|
4285 msg(IObuff);
|
|
4286 redraw_cmdline = FALSE; /* don't overwrite! */
|
|
4287 }
|
|
4288
|
|
4289 return num_matches;
|
|
4290 }
|
|
4291
|
|
4292 /*
|
|
4293 * Call this while finding completions, to check whether the user has hit a key
|
|
4294 * that should change the currently displayed completion, or exit completion
|
716
|
4295 * mode. Also, when compl_pending is not zero, show a completion as soon as
|
7
|
4296 * possible. -- webb
|
464
|
4297 * "frequency" specifies out of how many calls we actually check.
|
7
|
4298 */
|
|
4299 void
|
464
|
4300 ins_compl_check_keys(frequency)
|
|
4301 int frequency;
|
7
|
4302 {
|
|
4303 static int count = 0;
|
|
4304
|
|
4305 int c;
|
|
4306
|
|
4307 /* Don't check when reading keys from a script. That would break the test
|
|
4308 * scripts */
|
|
4309 if (using_script())
|
|
4310 return;
|
|
4311
|
|
4312 /* Only do this at regular intervals */
|
464
|
4313 if (++count < frequency)
|
7
|
4314 return;
|
|
4315 count = 0;
|
|
4316
|
|
4317 ++no_mapping;
|
|
4318 c = vpeekc_any();
|
|
4319 --no_mapping;
|
|
4320 if (c != NUL)
|
|
4321 {
|
|
4322 if (vim_is_ctrl_x_key(c) && c != Ctrl_X && c != Ctrl_R)
|
|
4323 {
|
|
4324 c = safe_vgetc(); /* Eat the character */
|
610
|
4325 compl_shows_dir = ins_compl_key2dir(c);
|
665
|
4326 (void)ins_compl_next(FALSE, ins_compl_key2count(c),
|
|
4327 c != K_UP && c != K_DOWN);
|
7
|
4328 }
|
|
4329 else if (c != Ctrl_R)
|
449
|
4330 compl_interrupted = TRUE;
|
|
4331 }
|
716
|
4332 if (compl_pending != 0 && !got_int)
|
|
4333 (void)ins_compl_next(FALSE, compl_pending > 0
|
|
4334 ? compl_pending : -compl_pending, TRUE);
|
610
|
4335 }
|
|
4336
|
|
4337 /*
|
|
4338 * Decide the direction of Insert mode complete from the key typed.
|
|
4339 * Returns BACKWARD or FORWARD.
|
|
4340 */
|
|
4341 static int
|
|
4342 ins_compl_key2dir(c)
|
|
4343 int c;
|
|
4344 {
|
665
|
4345 if (c == Ctrl_P || c == Ctrl_L
|
|
4346 || (pum_visible() && (c == K_PAGEUP || c == K_KPAGEUP
|
|
4347 || c == K_S_UP || c == K_UP)))
|
610
|
4348 return BACKWARD;
|
|
4349 return FORWARD;
|
|
4350 }
|
|
4351
|
|
4352 /*
|
644
|
4353 * Return TRUE for keys that are used for completion only when the popup menu
|
|
4354 * is visible.
|
|
4355 */
|
|
4356 static int
|
|
4357 ins_compl_pum_key(c)
|
|
4358 int c;
|
|
4359 {
|
|
4360 return pum_visible() && (c == K_PAGEUP || c == K_KPAGEUP || c == K_S_UP
|
665
|
4361 || c == K_PAGEDOWN || c == K_KPAGEDOWN || c == K_S_DOWN
|
|
4362 || c == K_UP || c == K_DOWN);
|
644
|
4363 }
|
|
4364
|
|
4365 /*
|
610
|
4366 * Decide the number of completions to move forward.
|
|
4367 * Returns 1 for most keys, height of the popup menu for page-up/down keys.
|
|
4368 */
|
|
4369 static int
|
|
4370 ins_compl_key2count(c)
|
|
4371 int c;
|
|
4372 {
|
|
4373 int h;
|
|
4374
|
665
|
4375 if (ins_compl_pum_key(c) && c != K_UP && c != K_DOWN)
|
610
|
4376 {
|
|
4377 h = pum_get_height();
|
|
4378 if (h > 3)
|
|
4379 h -= 2; /* keep some context */
|
|
4380 return h;
|
|
4381 }
|
|
4382 return 1;
|
7
|
4383 }
|
|
4384
|
|
4385 /*
|
681
|
4386 * Return TRUE if completion with "c" should insert the match, FALSE if only
|
|
4387 * to change the currently selected completion.
|
|
4388 */
|
|
4389 static int
|
|
4390 ins_compl_use_match(c)
|
|
4391 int c;
|
|
4392 {
|
|
4393 switch (c)
|
|
4394 {
|
|
4395 case K_UP:
|
|
4396 case K_DOWN:
|
|
4397 case K_PAGEDOWN:
|
|
4398 case K_KPAGEDOWN:
|
|
4399 case K_S_DOWN:
|
|
4400 case K_PAGEUP:
|
|
4401 case K_KPAGEUP:
|
|
4402 case K_S_UP:
|
|
4403 return FALSE;
|
|
4404 }
|
|
4405 return TRUE;
|
|
4406 }
|
|
4407
|
|
4408 /*
|
7
|
4409 * Do Insert mode completion.
|
|
4410 * Called when character "c" was typed, which has a meaning for completion.
|
|
4411 * Returns OK if completion was done, FAIL if something failed (out of mem).
|
|
4412 */
|
|
4413 static int
|
|
4414 ins_complete(c)
|
449
|
4415 int c;
|
7
|
4416 {
|
449
|
4417 char_u *line;
|
|
4418 int startcol = 0; /* column where searched text starts */
|
|
4419 colnr_T curs_col; /* cursor column */
|
|
4420 int n;
|
7
|
4421
|
610
|
4422 compl_direction = ins_compl_key2dir(c);
|
449
|
4423 if (!compl_started)
|
7
|
4424 {
|
|
4425 /* First time we hit ^N or ^P (in a row, I mean) */
|
|
4426
|
|
4427 did_ai = FALSE;
|
|
4428 #ifdef FEAT_SMARTINDENT
|
|
4429 did_si = FALSE;
|
|
4430 can_si = FALSE;
|
|
4431 can_si_back = FALSE;
|
|
4432 #endif
|
|
4433 if (stop_arrow() == FAIL)
|
|
4434 return FAIL;
|
|
4435
|
|
4436 line = ml_get(curwin->w_cursor.lnum);
|
449
|
4437 curs_col = curwin->w_cursor.col;
|
716
|
4438 compl_pending = 0;
|
7
|
4439
|
|
4440 /* if this same ctrl_x_mode has been interrupted use the text from
|
449
|
4441 * "compl_startpos" to the cursor as a pattern to add a new word
|
|
4442 * instead of expand the one before the cursor, in word-wise if
|
|
4443 * "compl_startpos"
|
7
|
4444 * is not in the same line as the cursor then fix it (the line has
|
|
4445 * been split because it was longer than 'tw'). if SOL is set then
|
|
4446 * skip the previous pattern, a word at the beginning of the line has
|
|
4447 * been inserted, we'll look for that -- Acevedo. */
|
665
|
4448 if ((compl_cont_status & CONT_INTRPT) == CONT_INTRPT
|
|
4449 && compl_cont_mode == ctrl_x_mode)
|
7
|
4450 {
|
|
4451 /*
|
|
4452 * it is a continued search
|
|
4453 */
|
449
|
4454 compl_cont_status &= ~CONT_INTRPT; /* remove INTRPT */
|
7
|
4455 if (ctrl_x_mode == 0 || ctrl_x_mode == CTRL_X_PATH_PATTERNS
|
|
4456 || ctrl_x_mode == CTRL_X_PATH_DEFINES)
|
|
4457 {
|
449
|
4458 if (compl_startpos.lnum != curwin->w_cursor.lnum)
|
7
|
4459 {
|
449
|
4460 /* line (probably) wrapped, set compl_startpos to the
|
|
4461 * first non_blank in the line, if it is not a wordchar
|
|
4462 * include it to get a better pattern, but then we don't
|
|
4463 * want the "\\<" prefix, check it bellow */
|
|
4464 compl_col = (colnr_T)(skipwhite(line) - line);
|
|
4465 compl_startpos.col = compl_col;
|
|
4466 compl_startpos.lnum = curwin->w_cursor.lnum;
|
|
4467 compl_cont_status &= ~CONT_SOL; /* clear SOL if present */
|
7
|
4468 }
|
|
4469 else
|
|
4470 {
|
|
4471 /* S_IPOS was set when we inserted a word that was at the
|
|
4472 * beginning of the line, which means that we'll go to SOL
|
449
|
4473 * mode but first we need to redefine compl_startpos */
|
|
4474 if (compl_cont_status & CONT_S_IPOS)
|
7
|
4475 {
|
449
|
4476 compl_cont_status |= CONT_SOL;
|
|
4477 compl_startpos.col = (colnr_T)(skipwhite(
|
|
4478 line + compl_length
|
|
4479 + compl_startpos.col) - line);
|
7
|
4480 }
|
449
|
4481 compl_col = compl_startpos.col;
|
7
|
4482 }
|
449
|
4483 compl_length = curwin->w_cursor.col - (int)compl_col;
|
502
|
4484 /* IObuff is used to add a "word from the next line" would we
|
7
|
4485 * have enough space? just being paranoic */
|
|
4486 #define MIN_SPACE 75
|
449
|
4487 if (compl_length > (IOSIZE - MIN_SPACE))
|
7
|
4488 {
|
449
|
4489 compl_cont_status &= ~CONT_SOL;
|
|
4490 compl_length = (IOSIZE - MIN_SPACE);
|
|
4491 compl_col = curwin->w_cursor.col - compl_length;
|
7
|
4492 }
|
449
|
4493 compl_cont_status |= CONT_ADDING | CONT_N_ADDS;
|
|
4494 if (compl_length < 1)
|
|
4495 compl_cont_status &= CONT_LOCAL;
|
7
|
4496 }
|
|
4497 else if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
|
449
|
4498 compl_cont_status = CONT_ADDING | CONT_N_ADDS;
|
7
|
4499 else
|
449
|
4500 compl_cont_status = 0;
|
7
|
4501 }
|
|
4502 else
|
449
|
4503 compl_cont_status &= CONT_LOCAL;
|
|
4504
|
|
4505 if (!(compl_cont_status & CONT_ADDING)) /* normal expansion */
|
|
4506 {
|
|
4507 compl_cont_mode = ctrl_x_mode;
|
7
|
4508 if (ctrl_x_mode != 0) /* Remove LOCAL if ctrl_x_mode != 0 */
|
449
|
4509 compl_cont_status = 0;
|
|
4510 compl_cont_status |= CONT_N_ADDS;
|
|
4511 compl_startpos = curwin->w_cursor;
|
|
4512 startcol = (int)curs_col;
|
|
4513 compl_col = 0;
|
7
|
4514 }
|
|
4515
|
|
4516 /* Work out completion pattern and original text -- webb */
|
|
4517 if (ctrl_x_mode == 0 || (ctrl_x_mode & CTRL_X_WANT_IDENT))
|
|
4518 {
|
449
|
4519 if ((compl_cont_status & CONT_SOL)
|
7
|
4520 || ctrl_x_mode == CTRL_X_PATH_DEFINES)
|
|
4521 {
|
449
|
4522 if (!(compl_cont_status & CONT_ADDING))
|
7
|
4523 {
|
449
|
4524 while (--startcol >= 0 && vim_isIDc(line[startcol]))
|
7
|
4525 ;
|
449
|
4526 compl_col += ++startcol;
|
|
4527 compl_length = curs_col - startcol;
|
7
|
4528 }
|
|
4529 if (p_ic)
|
449
|
4530 compl_pattern = str_foldcase(line + compl_col,
|
|
4531 compl_length, NULL, 0);
|
7
|
4532 else
|
449
|
4533 compl_pattern = vim_strnsave(line + compl_col,
|
|
4534 compl_length);
|
|
4535 if (compl_pattern == NULL)
|
7
|
4536 return FAIL;
|
|
4537 }
|
449
|
4538 else if (compl_cont_status & CONT_ADDING)
|
7
|
4539 {
|
|
4540 char_u *prefix = (char_u *)"\\<";
|
|
4541
|
|
4542 /* we need 3 extra chars, 1 for the NUL and
|
|
4543 * 2 >= strlen(prefix) -- Acevedo */
|
449
|
4544 compl_pattern = alloc(quote_meta(NULL, line + compl_col,
|
|
4545 compl_length) + 3);
|
|
4546 if (compl_pattern == NULL)
|
7
|
4547 return FAIL;
|
449
|
4548 if (!vim_iswordp(line + compl_col)
|
|
4549 || (compl_col > 0
|
7
|
4550 && (
|
|
4551 #ifdef FEAT_MBYTE
|
449
|
4552 vim_iswordp(mb_prevptr(line, line + compl_col))
|
7
|
4553 #else
|
449
|
4554 vim_iswordc(line[compl_col - 1])
|
7
|
4555 #endif
|
|
4556 )))
|
|
4557 prefix = (char_u *)"";
|
449
|
4558 STRCPY((char *)compl_pattern, prefix);
|
|
4559 (void)quote_meta(compl_pattern + STRLEN(prefix),
|
|
4560 line + compl_col, compl_length);
|
7
|
4561 }
|
449
|
4562 else if (--startcol < 0 ||
|
7
|
4563 #ifdef FEAT_MBYTE
|
449
|
4564 !vim_iswordp(mb_prevptr(line, line + startcol + 1))
|
7
|
4565 #else
|
449
|
4566 !vim_iswordc(line[startcol])
|
7
|
4567 #endif
|
|
4568 )
|
|
4569 {
|
|
4570 /* Match any word of at least two chars */
|
449
|
4571 compl_pattern = vim_strsave((char_u *)"\\<\\k\\k");
|
|
4572 if (compl_pattern == NULL)
|
7
|
4573 return FAIL;
|
449
|
4574 compl_col += curs_col;
|
|
4575 compl_length = 0;
|
7
|
4576 }
|
|
4577 else
|
|
4578 {
|
|
4579 #ifdef FEAT_MBYTE
|
|
4580 /* Search the point of change class of multibyte character
|
|
4581 * or not a word single byte character backward. */
|
|
4582 if (has_mbyte)
|
|
4583 {
|
|
4584 int base_class;
|
|
4585 int head_off;
|
|
4586
|
449
|
4587 startcol -= (*mb_head_off)(line, line + startcol);
|
|
4588 base_class = mb_get_class(line + startcol);
|
|
4589 while (--startcol >= 0)
|
7
|
4590 {
|
449
|
4591 head_off = (*mb_head_off)(line, line + startcol);
|
|
4592 if (base_class != mb_get_class(line + startcol
|
|
4593 - head_off))
|
7
|
4594 break;
|
449
|
4595 startcol -= head_off;
|
7
|
4596 }
|
|
4597 }
|
|
4598 else
|
|
4599 #endif
|
449
|
4600 while (--startcol >= 0 && vim_iswordc(line[startcol]))
|
7
|
4601 ;
|
449
|
4602 compl_col += ++startcol;
|
|
4603 compl_length = (int)curs_col - startcol;
|
|
4604 if (compl_length == 1)
|
7
|
4605 {
|
|
4606 /* Only match word with at least two chars -- webb
|
|
4607 * there's no need to call quote_meta,
|
|
4608 * alloc(7) is enough -- Acevedo
|
|
4609 */
|
449
|
4610 compl_pattern = alloc(7);
|
|
4611 if (compl_pattern == NULL)
|
7
|
4612 return FAIL;
|
449
|
4613 STRCPY((char *)compl_pattern, "\\<");
|
|
4614 (void)quote_meta(compl_pattern + 2, line + compl_col, 1);
|
|
4615 STRCAT((char *)compl_pattern, "\\k");
|
7
|
4616 }
|
|
4617 else
|
|
4618 {
|
449
|
4619 compl_pattern = alloc(quote_meta(NULL, line + compl_col,
|
|
4620 compl_length) + 3);
|
|
4621 if (compl_pattern == NULL)
|
7
|
4622 return FAIL;
|
449
|
4623 STRCPY((char *)compl_pattern, "\\<");
|
|
4624 (void)quote_meta(compl_pattern + 2, line + compl_col,
|
|
4625 compl_length);
|
7
|
4626 }
|
|
4627 }
|
|
4628 }
|
|
4629 else if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
|
|
4630 {
|
835
|
4631 compl_col = (colnr_T)(skipwhite(line) - line);
|
449
|
4632 compl_length = (int)curs_col - (int)compl_col;
|
|
4633 if (compl_length < 0) /* cursor in indent: empty pattern */
|
|
4634 compl_length = 0;
|
7
|
4635 if (p_ic)
|
449
|
4636 compl_pattern = str_foldcase(line + compl_col, compl_length,
|
|
4637 NULL, 0);
|
7
|
4638 else
|
449
|
4639 compl_pattern = vim_strnsave(line + compl_col, compl_length);
|
|
4640 if (compl_pattern == NULL)
|
7
|
4641 return FAIL;
|
|
4642 }
|
|
4643 else if (ctrl_x_mode == CTRL_X_FILES)
|
|
4644 {
|
449
|
4645 while (--startcol >= 0 && vim_isfilec(line[startcol]))
|
7
|
4646 ;
|
449
|
4647 compl_col += ++startcol;
|
|
4648 compl_length = (int)curs_col - startcol;
|
|
4649 compl_pattern = addstar(line + compl_col, compl_length,
|
|
4650 EXPAND_FILES);
|
|
4651 if (compl_pattern == NULL)
|
7
|
4652 return FAIL;
|
|
4653 }
|
|
4654 else if (ctrl_x_mode == CTRL_X_CMDLINE)
|
|
4655 {
|
449
|
4656 compl_pattern = vim_strnsave(line, curs_col);
|
|
4657 if (compl_pattern == NULL)
|
7
|
4658 return FAIL;
|
449
|
4659 set_cmd_context(&compl_xp, compl_pattern,
|
|
4660 (int)STRLEN(compl_pattern), curs_col);
|
|
4661 if (compl_xp.xp_context == EXPAND_UNSUCCESSFUL
|
|
4662 || compl_xp.xp_context == EXPAND_NOTHING)
|
897
|
4663 {
|
|
4664 compl_col = curs_col;
|
|
4665 compl_length = 0;
|
|
4666 vim_free(compl_pattern);
|
|
4667 compl_pattern = NULL;
|
|
4668 }
|
|
4669 else
|
|
4670 {
|
|
4671 startcol = (int)(compl_xp.xp_pattern - compl_pattern);
|
|
4672 compl_col = startcol;
|
|
4673 compl_length = curs_col - startcol;
|
|
4674 }
|
7
|
4675 }
|
523
|
4676 else if (ctrl_x_mode == CTRL_X_FUNCTION || ctrl_x_mode == CTRL_X_OMNI)
|
502
|
4677 {
|
12
|
4678 #ifdef FEAT_COMPL_FUNC
|
|
4679 /*
|
502
|
4680 * Call user defined function 'completefunc' with "a:findstart"
|
|
4681 * set to 1 to obtain the length of text to use for completion.
|
12
|
4682 */
|
502
|
4683 char_u *args[2];
|
452
|
4684 int col;
|
502
|
4685 char_u *funcname;
|
|
4686 pos_T pos;
|
|
4687
|
523
|
4688 /* Call 'completefunc' or 'omnifunc' and get pattern length as a
|
502
|
4689 * string */
|
|
4690 funcname = ctrl_x_mode == CTRL_X_FUNCTION
|
|
4691 ? curbuf->b_p_cfu : curbuf->b_p_ofu;
|
|
4692 if (*funcname == NUL)
|
523
|
4693 {
|
|
4694 EMSG2(_(e_notset), ctrl_x_mode == CTRL_X_FUNCTION
|
|
4695 ? "completefunc" : "omnifunc");
|
12
|
4696 return FAIL;
|
523
|
4697 }
|
452
|
4698
|
|
4699 args[0] = (char_u *)"1";
|
502
|
4700 args[1] = NULL;
|
|
4701 pos = curwin->w_cursor;
|
|
4702 col = call_func_retnr(funcname, 2, args, FALSE);
|
|
4703 curwin->w_cursor = pos; /* restore the cursor position */
|
|
4704
|
452
|
4705 if (col < 0)
|
523
|
4706 col = curs_col;
|
452
|
4707 compl_col = col;
|
|
4708 if ((colnr_T)compl_col > curs_col)
|
|
4709 compl_col = curs_col;
|
449
|
4710
|
|
4711 /* Setup variables for completion. Need to obtain "line" again,
|
|
4712 * it may have become invalid. */
|
|
4713 line = ml_get(curwin->w_cursor.lnum);
|
452
|
4714 compl_length = curs_col - compl_col;
|
449
|
4715 compl_pattern = vim_strnsave(line + compl_col, compl_length);
|
|
4716 if (compl_pattern == NULL)
|
502
|
4717 #endif
|
449
|
4718 return FAIL;
|
|
4719 }
|
477
|
4720 else if (ctrl_x_mode == CTRL_X_SPELL)
|
|
4721 {
|
744
|
4722 #ifdef FEAT_SPELL
|
497
|
4723 if (spell_bad_len > 0)
|
|
4724 compl_col = curs_col - spell_bad_len;
|
|
4725 else
|
|
4726 compl_col = spell_word_start(startcol);
|
|
4727 if (compl_col >= (colnr_T)startcol)
|
897
|
4728 {
|
|
4729 compl_length = 0;
|
|
4730 compl_col = curs_col;
|
|
4731 }
|
|
4732 else
|
|
4733 {
|
|
4734 spell_expand_check_cap(compl_col);
|
|
4735 compl_length = (int)curs_col - compl_col;
|
|
4736 }
|
818
|
4737 /* Need to obtain "line" again, it may have become invalid. */
|
|
4738 line = ml_get(curwin->w_cursor.lnum);
|
477
|
4739 compl_pattern = vim_strnsave(line + compl_col, compl_length);
|
|
4740 if (compl_pattern == NULL)
|
|
4741 #endif
|
|
4742 return FAIL;
|
|
4743 }
|
449
|
4744 else
|
|
4745 {
|
|
4746 EMSG2(_(e_intern2), "ins_complete()");
|
|
4747 return FAIL;
|
|
4748 }
|
|
4749
|
|
4750 if (compl_cont_status & CONT_ADDING)
|
7
|
4751 {
|
|
4752 edit_submode_pre = (char_u *)_(" Adding");
|
|
4753 if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
|
|
4754 {
|
|
4755 /* Insert a new line, keep indentation but ignore 'comments' */
|
|
4756 #ifdef FEAT_COMMENTS
|
|
4757 char_u *old = curbuf->b_p_com;
|
|
4758
|
|
4759 curbuf->b_p_com = (char_u *)"";
|
|
4760 #endif
|
449
|
4761 compl_startpos.lnum = curwin->w_cursor.lnum;
|
|
4762 compl_startpos.col = compl_col;
|
7
|
4763 ins_eol('\r');
|
|
4764 #ifdef FEAT_COMMENTS
|
|
4765 curbuf->b_p_com = old;
|
|
4766 #endif
|
449
|
4767 compl_length = 0;
|
|
4768 compl_col = curwin->w_cursor.col;
|
7
|
4769 }
|
|
4770 }
|
|
4771 else
|
|
4772 {
|
|
4773 edit_submode_pre = NULL;
|
449
|
4774 compl_startpos.col = compl_col;
|
|
4775 }
|
|
4776
|
|
4777 if (compl_cont_status & CONT_LOCAL)
|
|
4778 edit_submode = (char_u *)_(ctrl_x_msgs[CTRL_X_LOCAL_MSG]);
|
7
|
4779 else
|
|
4780 edit_submode = (char_u *)_(CTRL_X_MSG(ctrl_x_mode));
|
|
4781
|
694
|
4782 /* Always add completion for the original text. */
|
|
4783 vim_free(compl_orig_text);
|
449
|
4784 compl_orig_text = vim_strnsave(line + compl_col, compl_length);
|
|
4785 if (compl_orig_text == NULL || ins_compl_add(compl_orig_text,
|
841
|
4786 -1, FALSE, NULL, NULL, 0, ORIGINAL_TEXT, FALSE) != OK)
|
449
|
4787 {
|
|
4788 vim_free(compl_pattern);
|
|
4789 compl_pattern = NULL;
|
|
4790 vim_free(compl_orig_text);
|
|
4791 compl_orig_text = NULL;
|
7
|
4792 return FAIL;
|
|
4793 }
|
|
4794
|
|
4795 /* showmode might reset the internal line pointers, so it must
|
|
4796 * be called before line = ml_get(), or when this address is no
|
|
4797 * longer needed. -- Acevedo.
|
|
4798 */
|
|
4799 edit_submode_extra = (char_u *)_("-- Searching...");
|
|
4800 edit_submode_highl = HLF_COUNT;
|
|
4801 showmode();
|
|
4802 edit_submode_extra = NULL;
|
|
4803 out_flush();
|
|
4804 }
|
|
4805
|
449
|
4806 compl_shown_match = compl_curr_match;
|
|
4807 compl_shows_dir = compl_direction;
|
7
|
4808
|
|
4809 /*
|
665
|
4810 * Find next match (and following matches).
|
7
|
4811 */
|
681
|
4812 n = ins_compl_next(TRUE, ins_compl_key2count(c), ins_compl_use_match(c));
|
449
|
4813
|
540
|
4814 /* may undisplay the popup menu */
|
|
4815 ins_compl_upd_pum();
|
|
4816
|
449
|
4817 if (n > 1) /* all matches have been found */
|
|
4818 compl_matches = n;
|
|
4819 compl_curr_match = compl_shown_match;
|
|
4820 compl_direction = compl_shows_dir;
|
857
|
4821
|
|
4822 /* Eat the ESC that vgetc() returns after a CTRL-C to avoid leaving Insert
|
|
4823 * mode. */
|
7
|
4824 if (got_int && !global_busy)
|
|
4825 {
|
|
4826 (void)vgetc();
|
|
4827 got_int = FALSE;
|
|
4828 }
|
|
4829
|
449
|
4830 /* we found no match if the list has only the "compl_orig_text"-entry */
|
464
|
4831 if (compl_first_match == compl_first_match->cp_next)
|
449
|
4832 {
|
|
4833 edit_submode_extra = (compl_cont_status & CONT_ADDING)
|
|
4834 && compl_length > 1
|
7
|
4835 ? (char_u *)_(e_hitend) : (char_u *)_(e_patnotf);
|
|
4836 edit_submode_highl = HLF_E;
|
|
4837 /* remove N_ADDS flag, so next ^X<> won't try to go to ADDING mode,
|
|
4838 * because we couldn't expand anything at first place, but if we used
|
|
4839 * ^P, ^N, ^X^I or ^X^D we might want to add-expand a single-char-word
|
|
4840 * (such as M in M'exico) if not tried already. -- Acevedo */
|
449
|
4841 if ( compl_length > 1
|
|
4842 || (compl_cont_status & CONT_ADDING)
|
7
|
4843 || (ctrl_x_mode != 0
|
|
4844 && ctrl_x_mode != CTRL_X_PATH_PATTERNS
|
|
4845 && ctrl_x_mode != CTRL_X_PATH_DEFINES))
|
449
|
4846 compl_cont_status &= ~CONT_N_ADDS;
|
|
4847 }
|
|
4848
|
464
|
4849 if (compl_curr_match->cp_flags & CONT_S_IPOS)
|
449
|
4850 compl_cont_status |= CONT_S_IPOS;
|
7
|
4851 else
|
449
|
4852 compl_cont_status &= ~CONT_S_IPOS;
|
7
|
4853
|
|
4854 if (edit_submode_extra == NULL)
|
|
4855 {
|
464
|
4856 if (compl_curr_match->cp_flags & ORIGINAL_TEXT)
|
7
|
4857 {
|
|
4858 edit_submode_extra = (char_u *)_("Back at original");
|
|
4859 edit_submode_highl = HLF_W;
|
|
4860 }
|
449
|
4861 else if (compl_cont_status & CONT_S_IPOS)
|
7
|
4862 {
|
|
4863 edit_submode_extra = (char_u *)_("Word from other line");
|
|
4864 edit_submode_highl = HLF_COUNT;
|
|
4865 }
|
464
|
4866 else if (compl_curr_match->cp_next == compl_curr_match->cp_prev)
|
7
|
4867 {
|
|
4868 edit_submode_extra = (char_u *)_("The only match");
|
|
4869 edit_submode_highl = HLF_COUNT;
|
|
4870 }
|
|
4871 else
|
|
4872 {
|
|
4873 /* Update completion sequence number when needed. */
|
464
|
4874 if (compl_curr_match->cp_number == -1)
|
7
|
4875 {
|
464
|
4876 int number = 0;
|
|
4877 compl_T *match;
|
7
|
4878
|
449
|
4879 if (compl_direction == FORWARD)
|
7
|
4880 {
|
|
4881 /* search backwards for the first valid (!= -1) number.
|
|
4882 * This should normally succeed already at the first loop
|
|
4883 * cycle, so it's fast! */
|
464
|
4884 for (match = compl_curr_match->cp_prev; match != NULL
|
|
4885 && match != compl_first_match;
|
|
4886 match = match->cp_prev)
|
|
4887 if (match->cp_number != -1)
|
7
|
4888 {
|
464
|
4889 number = match->cp_number;
|
7
|
4890 break;
|
|
4891 }
|
|
4892 if (match != NULL)
|
|
4893 /* go up and assign all numbers which are not assigned
|
|
4894 * yet */
|
540
|
4895 for (match = match->cp_next;
|
|
4896 match != NULL && match->cp_number == -1;
|
464
|
4897 match = match->cp_next)
|
|
4898 match->cp_number = ++number;
|
7
|
4899 }
|
|
4900 else /* BACKWARD */
|
|
4901 {
|
|
4902 /* search forwards (upwards) for the first valid (!= -1)
|
|
4903 * number. This should normally succeed already at the
|
|
4904 * first loop cycle, so it's fast! */
|
464
|
4905 for (match = compl_curr_match->cp_next; match != NULL
|
|
4906 && match != compl_first_match;
|
|
4907 match = match->cp_next)
|
|
4908 if (match->cp_number != -1)
|
7
|
4909 {
|
464
|
4910 number = match->cp_number;
|
7
|
4911 break;
|
|
4912 }
|
|
4913 if (match != NULL)
|
|
4914 /* go down and assign all numbers which are not
|
|
4915 * assigned yet */
|
464
|
4916 for (match = match->cp_prev; match
|
|
4917 && match->cp_number == -1;
|
|
4918 match = match->cp_prev)
|
|
4919 match->cp_number = ++number;
|
7
|
4920 }
|
|
4921 }
|
|
4922
|
540
|
4923 /* The match should always have a sequence number now, this is
|
|
4924 * just a safety check. */
|
464
|
4925 if (compl_curr_match->cp_number != -1)
|
7
|
4926 {
|
|
4927 /* Space for 10 text chars. + 2x10-digit no.s */
|
|
4928 static char_u match_ref[31];
|
|
4929
|
449
|
4930 if (compl_matches > 0)
|
7
|
4931 sprintf((char *)IObuff, _("match %d of %d"),
|
464
|
4932 compl_curr_match->cp_number, compl_matches);
|
7
|
4933 else
|
449
|
4934 sprintf((char *)IObuff, _("match %d"),
|
464
|
4935 compl_curr_match->cp_number);
|
419
|
4936 vim_strncpy(match_ref, IObuff, 30);
|
7
|
4937 edit_submode_extra = match_ref;
|
|
4938 edit_submode_highl = HLF_R;
|
|
4939 if (dollar_vcol)
|
|
4940 curs_columns(FALSE);
|
|
4941 }
|
|
4942 }
|
|
4943 }
|
|
4944
|
|
4945 /* Show a message about what (completion) mode we're in. */
|
|
4946 showmode();
|
|
4947 if (edit_submode_extra != NULL)
|
|
4948 {
|
|
4949 if (!p_smd)
|
|
4950 msg_attr(edit_submode_extra,
|
|
4951 edit_submode_highl < HLF_COUNT
|
|
4952 ? hl_attr(edit_submode_highl) : 0);
|
|
4953 }
|
|
4954 else
|
|
4955 msg_clr_cmdline(); /* necessary for "noshowmode" */
|
|
4956
|
857
|
4957 /* Show the popup menu, unless we got interrupted. */
|
|
4958 if (!compl_interrupted)
|
|
4959 {
|
|
4960 /* RedrawingDisabled may be set when invoked through complete(). */
|
|
4961 n = RedrawingDisabled;
|
|
4962 RedrawingDisabled = 0;
|
|
4963 ins_compl_show_pum();
|
|
4964 setcursor();
|
|
4965 RedrawingDisabled = n;
|
|
4966 }
|
874
|
4967 compl_was_interrupted = compl_interrupted;
|
857
|
4968 compl_interrupted = FALSE;
|
540
|
4969
|
7
|
4970 return OK;
|
|
4971 }
|
|
4972
|
|
4973 /*
|
|
4974 * Looks in the first "len" chars. of "src" for search-metachars.
|
|
4975 * If dest is not NULL the chars. are copied there quoting (with
|
|
4976 * a backslash) the metachars, and dest would be NUL terminated.
|
|
4977 * Returns the length (needed) of dest
|
|
4978 */
|
|
4979 static int
|
|
4980 quote_meta(dest, src, len)
|
|
4981 char_u *dest;
|
|
4982 char_u *src;
|
|
4983 int len;
|
|
4984 {
|
|
4985 int m;
|
|
4986
|
|
4987 for (m = len; --len >= 0; src++)
|
|
4988 {
|
|
4989 switch (*src)
|
|
4990 {
|
|
4991 case '.':
|
|
4992 case '*':
|
|
4993 case '[':
|
|
4994 if (ctrl_x_mode == CTRL_X_DICTIONARY
|
|
4995 || ctrl_x_mode == CTRL_X_THESAURUS)
|
|
4996 break;
|
|
4997 case '~':
|
|
4998 if (!p_magic) /* quote these only if magic is set */
|
|
4999 break;
|
|
5000 case '\\':
|
|
5001 if (ctrl_x_mode == CTRL_X_DICTIONARY
|
|
5002 || ctrl_x_mode == CTRL_X_THESAURUS)
|
|
5003 break;
|
|
5004 case '^': /* currently it's not needed. */
|
|
5005 case '$':
|
|
5006 m++;
|
|
5007 if (dest != NULL)
|
|
5008 *dest++ = '\\';
|
|
5009 break;
|
|
5010 }
|
|
5011 if (dest != NULL)
|
|
5012 *dest++ = *src;
|
464
|
5013 # ifdef FEAT_MBYTE
|
7
|
5014 /* Copy remaining bytes of a multibyte character. */
|
|
5015 if (has_mbyte)
|
|
5016 {
|
|
5017 int i, mb_len;
|
|
5018
|
474
|
5019 mb_len = (*mb_ptr2len)(src) - 1;
|
7
|
5020 if (mb_len > 0 && len >= mb_len)
|
|
5021 for (i = 0; i < mb_len; ++i)
|
|
5022 {
|
|
5023 --len;
|
|
5024 ++src;
|
|
5025 if (dest != NULL)
|
|
5026 *dest++ = *src;
|
|
5027 }
|
|
5028 }
|
464
|
5029 # endif
|
7
|
5030 }
|
|
5031 if (dest != NULL)
|
|
5032 *dest = NUL;
|
|
5033
|
|
5034 return m;
|
|
5035 }
|
|
5036 #endif /* FEAT_INS_EXPAND */
|
|
5037
|
|
5038 /*
|
|
5039 * Next character is interpreted literally.
|
|
5040 * A one, two or three digit decimal number is interpreted as its byte value.
|
|
5041 * If one or two digits are entered, the next character is given to vungetc().
|
|
5042 * For Unicode a character > 255 may be returned.
|
|
5043 */
|
|
5044 int
|
|
5045 get_literal()
|
|
5046 {
|
|
5047 int cc;
|
|
5048 int nc;
|
|
5049 int i;
|
|
5050 int hex = FALSE;
|
|
5051 int octal = FALSE;
|
|
5052 #ifdef FEAT_MBYTE
|
|
5053 int unicode = 0;
|
|
5054 #endif
|
|
5055
|
|
5056 if (got_int)
|
|
5057 return Ctrl_C;
|
|
5058
|
|
5059 #ifdef FEAT_GUI
|
|
5060 /*
|
|
5061 * In GUI there is no point inserting the internal code for a special key.
|
|
5062 * It is more useful to insert the string "<KEY>" instead. This would
|
|
5063 * probably be useful in a text window too, but it would not be
|
|
5064 * vi-compatible (maybe there should be an option for it?) -- webb
|
|
5065 */
|
|
5066 if (gui.in_use)
|
|
5067 ++allow_keys;
|
|
5068 #endif
|
|
5069 #ifdef USE_ON_FLY_SCROLL
|
|
5070 dont_scroll = TRUE; /* disallow scrolling here */
|
|
5071 #endif
|
|
5072 ++no_mapping; /* don't map the next key hits */
|
|
5073 cc = 0;
|
|
5074 i = 0;
|
|
5075 for (;;)
|
|
5076 {
|
|
5077 do
|
|
5078 nc = safe_vgetc();
|
|
5079 while (nc == K_IGNORE || nc == K_VER_SCROLLBAR
|
|
5080 || nc == K_HOR_SCROLLBAR);
|
|
5081 #ifdef FEAT_CMDL_INFO
|
|
5082 if (!(State & CMDLINE)
|
|
5083 # ifdef FEAT_MBYTE
|
|
5084 && MB_BYTE2LEN_CHECK(nc) == 1
|
|
5085 # endif
|
|
5086 )
|
|
5087 add_to_showcmd(nc);
|
|
5088 #endif
|
|
5089 if (nc == 'x' || nc == 'X')
|
|
5090 hex = TRUE;
|
|
5091 else if (nc == 'o' || nc == 'O')
|
|
5092 octal = TRUE;
|
|
5093 #ifdef FEAT_MBYTE
|
|
5094 else if (nc == 'u' || nc == 'U')
|
|
5095 unicode = nc;
|
|
5096 #endif
|
|
5097 else
|
|
5098 {
|
|
5099 if (hex
|
|
5100 #ifdef FEAT_MBYTE
|
|
5101 || unicode != 0
|
|
5102 #endif
|
|
5103 )
|
|
5104 {
|
|
5105 if (!vim_isxdigit(nc))
|
|
5106 break;
|
|
5107 cc = cc * 16 + hex2nr(nc);
|
|
5108 }
|
|
5109 else if (octal)
|
|
5110 {
|
|
5111 if (nc < '0' || nc > '7')
|
|
5112 break;
|
|
5113 cc = cc * 8 + nc - '0';
|
|
5114 }
|
|
5115 else
|
|
5116 {
|
|
5117 if (!VIM_ISDIGIT(nc))
|
|
5118 break;
|
|
5119 cc = cc * 10 + nc - '0';
|
|
5120 }
|
|
5121
|
|
5122 ++i;
|
|
5123 }
|
|
5124
|
|
5125 if (cc > 255
|
|
5126 #ifdef FEAT_MBYTE
|
|
5127 && unicode == 0
|
|
5128 #endif
|
|
5129 )
|
|
5130 cc = 255; /* limit range to 0-255 */
|
|
5131 nc = 0;
|
|
5132
|
|
5133 if (hex) /* hex: up to two chars */
|
|
5134 {
|
|
5135 if (i >= 2)
|
|
5136 break;
|
|
5137 }
|
|
5138 #ifdef FEAT_MBYTE
|
|
5139 else if (unicode) /* Unicode: up to four or eight chars */
|
|
5140 {
|
|
5141 if ((unicode == 'u' && i >= 4) || (unicode == 'U' && i >= 8))
|
|
5142 break;
|
|
5143 }
|
|
5144 #endif
|
|
5145 else if (i >= 3) /* decimal or octal: up to three chars */
|
|
5146 break;
|
|
5147 }
|
|
5148 if (i == 0) /* no number entered */
|
|
5149 {
|
|
5150 if (nc == K_ZERO) /* NUL is stored as NL */
|
|
5151 {
|
|
5152 cc = '\n';
|
|
5153 nc = 0;
|
|
5154 }
|
|
5155 else
|
|
5156 {
|
|
5157 cc = nc;
|
|
5158 nc = 0;
|
|
5159 }
|
|
5160 }
|
|
5161
|
|
5162 if (cc == 0) /* NUL is stored as NL */
|
|
5163 cc = '\n';
|
221
|
5164 #ifdef FEAT_MBYTE
|
|
5165 if (enc_dbcs && (cc & 0xff) == 0)
|
|
5166 cc = '?'; /* don't accept an illegal DBCS char, the NUL in the
|
|
5167 second byte will cause trouble! */
|
|
5168 #endif
|
7
|
5169
|
|
5170 --no_mapping;
|
|
5171 #ifdef FEAT_GUI
|
|
5172 if (gui.in_use)
|
|
5173 --allow_keys;
|
|
5174 #endif
|
|
5175 if (nc)
|
|
5176 vungetc(nc);
|
|
5177 got_int = FALSE; /* CTRL-C typed after CTRL-V is not an interrupt */
|
|
5178 return cc;
|
|
5179 }
|
|
5180
|
|
5181 /*
|
|
5182 * Insert character, taking care of special keys and mod_mask
|
|
5183 */
|
|
5184 static void
|
|
5185 insert_special(c, allow_modmask, ctrlv)
|
|
5186 int c;
|
|
5187 int allow_modmask;
|
|
5188 int ctrlv; /* c was typed after CTRL-V */
|
|
5189 {
|
|
5190 char_u *p;
|
|
5191 int len;
|
|
5192
|
|
5193 /*
|
|
5194 * Special function key, translate into "<Key>". Up to the last '>' is
|
|
5195 * inserted with ins_str(), so as not to replace characters in replace
|
|
5196 * mode.
|
|
5197 * Only use mod_mask for special keys, to avoid things like <S-Space>,
|
|
5198 * unless 'allow_modmask' is TRUE.
|
|
5199 */
|
|
5200 #ifdef MACOS
|
|
5201 /* Command-key never produces a normal key */
|
|
5202 if (mod_mask & MOD_MASK_CMD)
|
|
5203 allow_modmask = TRUE;
|
|
5204 #endif
|
|
5205 if (IS_SPECIAL(c) || (mod_mask && allow_modmask))
|
|
5206 {
|
|
5207 p = get_special_key_name(c, mod_mask);
|
|
5208 len = (int)STRLEN(p);
|
|
5209 c = p[len - 1];
|
|
5210 if (len > 2)
|
|
5211 {
|
|
5212 if (stop_arrow() == FAIL)
|
|
5213 return;
|
|
5214 p[len - 1] = NUL;
|
|
5215 ins_str(p);
|
620
|
5216 AppendToRedobuffLit(p, -1);
|
7
|
5217 ctrlv = FALSE;
|
|
5218 }
|
|
5219 }
|
|
5220 if (stop_arrow() == OK)
|
|
5221 insertchar(c, ctrlv ? INSCHAR_CTRLV : 0, -1);
|
|
5222 }
|
|
5223
|
|
5224 /*
|
|
5225 * Special characters in this context are those that need processing other
|
|
5226 * than the simple insertion that can be performed here. This includes ESC
|
|
5227 * which terminates the insert, and CR/NL which need special processing to
|
|
5228 * open up a new line. This routine tries to optimize insertions performed by
|
|
5229 * the "redo", "undo" or "put" commands, so it needs to know when it should
|
|
5230 * stop and defer processing to the "normal" mechanism.
|
|
5231 * '0' and '^' are special, because they can be followed by CTRL-D.
|
|
5232 */
|
|
5233 #ifdef EBCDIC
|
|
5234 # define ISSPECIAL(c) ((c) < ' ' || (c) == '0' || (c) == '^')
|
|
5235 #else
|
|
5236 # define ISSPECIAL(c) ((c) < ' ' || (c) >= DEL || (c) == '0' || (c) == '^')
|
|
5237 #endif
|
|
5238
|
|
5239 #ifdef FEAT_MBYTE
|
|
5240 # define WHITECHAR(cc) (vim_iswhite(cc) && (!enc_utf8 || !utf_iscomposing(utf_ptr2char(ml_get_cursor() + 1))))
|
|
5241 #else
|
|
5242 # define WHITECHAR(cc) vim_iswhite(cc)
|
|
5243 #endif
|
|
5244
|
|
5245 void
|
|
5246 insertchar(c, flags, second_indent)
|
|
5247 int c; /* character to insert or NUL */
|
|
5248 int flags; /* INSCHAR_FORMAT, etc. */
|
|
5249 int second_indent; /* indent for second line if >= 0 */
|
|
5250 {
|
|
5251 int textwidth;
|
|
5252 #ifdef FEAT_COMMENTS
|
|
5253 char_u *p;
|
667
|
5254 #endif
|
7
|
5255 int fo_ins_blank;
|
|
5256
|
|
5257 textwidth = comp_textwidth(flags & INSCHAR_FORMAT);
|
|
5258 fo_ins_blank = has_format_option(FO_INS_BLANK);
|
|
5259
|
|
5260 /*
|
|
5261 * Try to break the line in two or more pieces when:
|
|
5262 * - Always do this if we have been called to do formatting only.
|
|
5263 * - Always do this when 'formatoptions' has the 'a' flag and the line
|
|
5264 * ends in white space.
|
|
5265 * - Otherwise:
|
|
5266 * - Don't do this if inserting a blank
|
|
5267 * - Don't do this if an existing character is being replaced, unless
|
|
5268 * we're in VREPLACE mode.
|
|
5269 * - Do this if the cursor is not on the line where insert started
|
|
5270 * or - 'formatoptions' doesn't have 'l' or the line was not too long
|
|
5271 * before the insert.
|
|
5272 * - 'formatoptions' doesn't have 'b' or a blank was inserted at or
|
|
5273 * before 'textwidth'
|
|
5274 */
|
667
|
5275 if (textwidth > 0
|
7
|
5276 && ((flags & INSCHAR_FORMAT)
|
|
5277 || (!vim_iswhite(c)
|
|
5278 && !((State & REPLACE_FLAG)
|
|
5279 #ifdef FEAT_VREPLACE
|
|
5280 && !(State & VREPLACE_FLAG)
|
|
5281 #endif
|
|
5282 && *ml_get_cursor() != NUL)
|
|
5283 && (curwin->w_cursor.lnum != Insstart.lnum
|
|
5284 || ((!has_format_option(FO_INS_LONG)
|
|
5285 || Insstart_textlen <= (colnr_T)textwidth)
|
|
5286 && (!fo_ins_blank
|
|
5287 || Insstart_blank_vcol <= (colnr_T)textwidth
|
|
5288 ))))))
|
|
5289 {
|
667
|
5290 /* Format with 'formatexpr' when it's set. Use internal formatting
|
|
5291 * when 'formatexpr' isn't set or it returns non-zero. */
|
|
5292 #if defined(FEAT_EVAL)
|
|
5293 if (*curbuf->b_p_fex == NUL
|
844
|
5294 || fex_format(curwin->w_cursor.lnum, 1L, c) != 0)
|
667
|
5295 #endif
|
|
5296 internal_format(textwidth, second_indent, flags, c == NUL);
|
|
5297 }
|
|
5298
|
7
|
5299 if (c == NUL) /* only formatting was wanted */
|
|
5300 return;
|
|
5301
|
|
5302 #ifdef FEAT_COMMENTS
|
|
5303 /* Check whether this character should end a comment. */
|
|
5304 if (did_ai && (int)c == end_comment_pending)
|
|
5305 {
|
|
5306 char_u *line;
|
|
5307 char_u lead_end[COM_MAX_LEN]; /* end-comment string */
|
|
5308 int middle_len, end_len;
|
|
5309 int i;
|
|
5310
|
|
5311 /*
|
|
5312 * Need to remove existing (middle) comment leader and insert end
|
|
5313 * comment leader. First, check what comment leader we can find.
|
|
5314 */
|
|
5315 i = get_leader_len(line = ml_get_curline(), &p, FALSE);
|
|
5316 if (i > 0 && vim_strchr(p, COM_MIDDLE) != NULL) /* Just checking */
|
|
5317 {
|
|
5318 /* Skip middle-comment string */
|
|
5319 while (*p && p[-1] != ':') /* find end of middle flags */
|
|
5320 ++p;
|
|
5321 middle_len = copy_option_part(&p, lead_end, COM_MAX_LEN, ",");
|
|
5322 /* Don't count trailing white space for middle_len */
|
|
5323 while (middle_len > 0 && vim_iswhite(lead_end[middle_len - 1]))
|
|
5324 --middle_len;
|
|
5325
|
|
5326 /* Find the end-comment string */
|
|
5327 while (*p && p[-1] != ':') /* find end of end flags */
|
|
5328 ++p;
|
|
5329 end_len = copy_option_part(&p, lead_end, COM_MAX_LEN, ",");
|
|
5330
|
|
5331 /* Skip white space before the cursor */
|
|
5332 i = curwin->w_cursor.col;
|
|
5333 while (--i >= 0 && vim_iswhite(line[i]))
|
|
5334 ;
|
|
5335 i++;
|
|
5336
|
|
5337 /* Skip to before the middle leader */
|
|
5338 i -= middle_len;
|
|
5339
|
|
5340 /* Check some expected things before we go on */
|
|
5341 if (i >= 0 && lead_end[end_len - 1] == end_comment_pending)
|
|
5342 {
|
|
5343 /* Backspace over all the stuff we want to replace */
|
|
5344 backspace_until_column(i);
|
|
5345
|
|
5346 /*
|
|
5347 * Insert the end-comment string, except for the last
|
|
5348 * character, which will get inserted as normal later.
|
|
5349 */
|
|
5350 ins_bytes_len(lead_end, end_len - 1);
|
|
5351 }
|
|
5352 }
|
|
5353 }
|
|
5354 end_comment_pending = NUL;
|
|
5355 #endif
|
|
5356
|
|
5357 did_ai = FALSE;
|
|
5358 #ifdef FEAT_SMARTINDENT
|
|
5359 did_si = FALSE;
|
|
5360 can_si = FALSE;
|
|
5361 can_si_back = FALSE;
|
|
5362 #endif
|
|
5363
|
|
5364 /*
|
|
5365 * If there's any pending input, grab up to INPUT_BUFLEN at once.
|
|
5366 * This speeds up normal text input considerably.
|
|
5367 * Don't do this when 'cindent' or 'indentexpr' is set, because we might
|
|
5368 * need to re-indent at a ':', or any other character (but not what
|
|
5369 * 'paste' is set)..
|
|
5370 */
|
|
5371 #ifdef USE_ON_FLY_SCROLL
|
|
5372 dont_scroll = FALSE; /* allow scrolling here */
|
|
5373 #endif
|
|
5374
|
|
5375 if ( !ISSPECIAL(c)
|
|
5376 #ifdef FEAT_MBYTE
|
|
5377 && (!has_mbyte || (*mb_char2len)(c) == 1)
|
|
5378 #endif
|
|
5379 && vpeekc() != NUL
|
|
5380 && !(State & REPLACE_FLAG)
|
|
5381 #ifdef FEAT_CINDENT
|
|
5382 && !cindent_on()
|
|
5383 #endif
|
|
5384 #ifdef FEAT_RIGHTLEFT
|
|
5385 && !p_ri
|
|
5386 #endif
|
|
5387 )
|
|
5388 {
|
|
5389 #define INPUT_BUFLEN 100
|
|
5390 char_u buf[INPUT_BUFLEN + 1];
|
|
5391 int i;
|
|
5392 colnr_T virtcol = 0;
|
|
5393
|
|
5394 buf[0] = c;
|
|
5395 i = 1;
|
667
|
5396 if (textwidth > 0)
|
7
|
5397 virtcol = get_nolist_virtcol();
|
|
5398 /*
|
|
5399 * Stop the string when:
|
|
5400 * - no more chars available
|
|
5401 * - finding a special character (command key)
|
|
5402 * - buffer is full
|
|
5403 * - running into the 'textwidth' boundary
|
|
5404 * - need to check for abbreviation: A non-word char after a word-char
|
|
5405 */
|
|
5406 while ( (c = vpeekc()) != NUL
|
|
5407 && !ISSPECIAL(c)
|
|
5408 #ifdef FEAT_MBYTE
|
|
5409 && (!has_mbyte || MB_BYTE2LEN_CHECK(c) == 1)
|
|
5410 #endif
|
|
5411 && i < INPUT_BUFLEN
|
|
5412 && (textwidth == 0
|
|
5413 || (virtcol += byte2cells(buf[i - 1])) < (colnr_T)textwidth)
|
|
5414 && !(!no_abbr && !vim_iswordc(c) && vim_iswordc(buf[i - 1])))
|
|
5415 {
|
|
5416 #ifdef FEAT_RIGHTLEFT
|
|
5417 c = vgetc();
|
|
5418 if (p_hkmap && KeyTyped)
|
|
5419 c = hkmap(c); /* Hebrew mode mapping */
|
|
5420 # ifdef FEAT_FKMAP
|
|
5421 if (p_fkmap && KeyTyped)
|
|
5422 c = fkmap(c); /* Farsi mode mapping */
|
|
5423 # endif
|
|
5424 buf[i++] = c;
|
|
5425 #else
|
|
5426 buf[i++] = vgetc();
|
|
5427 #endif
|
|
5428 }
|
|
5429
|
|
5430 #ifdef FEAT_DIGRAPHS
|
|
5431 do_digraph(-1); /* clear digraphs */
|
|
5432 do_digraph(buf[i-1]); /* may be the start of a digraph */
|
|
5433 #endif
|
|
5434 buf[i] = NUL;
|
|
5435 ins_str(buf);
|
|
5436 if (flags & INSCHAR_CTRLV)
|
|
5437 {
|
|
5438 redo_literal(*buf);
|
|
5439 i = 1;
|
|
5440 }
|
|
5441 else
|
|
5442 i = 0;
|
|
5443 if (buf[i] != NUL)
|
620
|
5444 AppendToRedobuffLit(buf + i, -1);
|
7
|
5445 }
|
|
5446 else
|
|
5447 {
|
|
5448 #ifdef FEAT_MBYTE
|
667
|
5449 int cc;
|
|
5450
|
7
|
5451 if (has_mbyte && (cc = (*mb_char2len)(c)) > 1)
|
|
5452 {
|
|
5453 char_u buf[MB_MAXBYTES + 1];
|
|
5454
|
|
5455 (*mb_char2bytes)(c, buf);
|
|
5456 buf[cc] = NUL;
|
|
5457 ins_char_bytes(buf, cc);
|
|
5458 AppendCharToRedobuff(c);
|
|
5459 }
|
|
5460 else
|
|
5461 #endif
|
|
5462 {
|
|
5463 ins_char(c);
|
|
5464 if (flags & INSCHAR_CTRLV)
|
|
5465 redo_literal(c);
|
|
5466 else
|
|
5467 AppendCharToRedobuff(c);
|
|
5468 }
|
|
5469 }
|
|
5470 }
|
|
5471
|
|
5472 /*
|
667
|
5473 * Format text at the current insert position.
|
|
5474 */
|
|
5475 static void
|
|
5476 internal_format(textwidth, second_indent, flags, format_only)
|
|
5477 int textwidth;
|
|
5478 int second_indent;
|
|
5479 int flags;
|
|
5480 int format_only;
|
|
5481 {
|
|
5482 int cc;
|
|
5483 int save_char = NUL;
|
|
5484 int haveto_redraw = FALSE;
|
|
5485 int fo_ins_blank = has_format_option(FO_INS_BLANK);
|
|
5486 #ifdef FEAT_MBYTE
|
|
5487 int fo_multibyte = has_format_option(FO_MBYTE_BREAK);
|
|
5488 #endif
|
|
5489 int fo_white_par = has_format_option(FO_WHITE_PAR);
|
|
5490 int first_line = TRUE;
|
|
5491 #ifdef FEAT_COMMENTS
|
|
5492 colnr_T leader_len;
|
|
5493 int no_leader = FALSE;
|
|
5494 int do_comments = (flags & INSCHAR_DO_COM);
|
|
5495 #endif
|
|
5496
|
|
5497 /*
|
|
5498 * When 'ai' is off we don't want a space under the cursor to be
|
|
5499 * deleted. Replace it with an 'x' temporarily.
|
|
5500 */
|
|
5501 if (!curbuf->b_p_ai)
|
|
5502 {
|
|
5503 cc = gchar_cursor();
|
|
5504 if (vim_iswhite(cc))
|
|
5505 {
|
|
5506 save_char = cc;
|
|
5507 pchar_cursor('x');
|
|
5508 }
|
|
5509 }
|
|
5510
|
|
5511 /*
|
|
5512 * Repeat breaking lines, until the current line is not too long.
|
|
5513 */
|
|
5514 while (!got_int)
|
|
5515 {
|
|
5516 int startcol; /* Cursor column at entry */
|
|
5517 int wantcol; /* column at textwidth border */
|
|
5518 int foundcol; /* column for start of spaces */
|
|
5519 int end_foundcol = 0; /* column for start of word */
|
|
5520 colnr_T len;
|
|
5521 colnr_T virtcol;
|
|
5522 #ifdef FEAT_VREPLACE
|
|
5523 int orig_col = 0;
|
|
5524 char_u *saved_text = NULL;
|
|
5525 #endif
|
|
5526 colnr_T col;
|
|
5527
|
|
5528 virtcol = get_nolist_virtcol();
|
|
5529 if (virtcol < (colnr_T)textwidth)
|
|
5530 break;
|
|
5531
|
|
5532 #ifdef FEAT_COMMENTS
|
|
5533 if (no_leader)
|
|
5534 do_comments = FALSE;
|
|
5535 else if (!(flags & INSCHAR_FORMAT)
|
|
5536 && has_format_option(FO_WRAP_COMS))
|
|
5537 do_comments = TRUE;
|
|
5538
|
|
5539 /* Don't break until after the comment leader */
|
|
5540 if (do_comments)
|
|
5541 leader_len = get_leader_len(ml_get_curline(), NULL, FALSE);
|
|
5542 else
|
|
5543 leader_len = 0;
|
|
5544
|
|
5545 /* If the line doesn't start with a comment leader, then don't
|
|
5546 * start one in a following broken line. Avoids that a %word
|
|
5547 * moved to the start of the next line causes all following lines
|
|
5548 * to start with %. */
|
|
5549 if (leader_len == 0)
|
|
5550 no_leader = TRUE;
|
|
5551 #endif
|
|
5552 if (!(flags & INSCHAR_FORMAT)
|
|
5553 #ifdef FEAT_COMMENTS
|
|
5554 && leader_len == 0
|
|
5555 #endif
|
|
5556 && !has_format_option(FO_WRAP))
|
|
5557
|
|
5558 {
|
|
5559 textwidth = 0;
|
|
5560 break;
|
|
5561 }
|
|
5562 if ((startcol = curwin->w_cursor.col) == 0)
|
|
5563 break;
|
|
5564
|
|
5565 /* find column of textwidth border */
|
|
5566 coladvance((colnr_T)textwidth);
|
|
5567 wantcol = curwin->w_cursor.col;
|
|
5568
|
|
5569 curwin->w_cursor.col = startcol - 1;
|
|
5570 #ifdef FEAT_MBYTE
|
|
5571 /* Correct cursor for multi-byte character. */
|
|
5572 if (has_mbyte)
|
|
5573 mb_adjust_cursor();
|
|
5574 #endif
|
|
5575 foundcol = 0;
|
|
5576
|
|
5577 /*
|
|
5578 * Find position to break at.
|
|
5579 * Stop at first entered white when 'formatoptions' has 'v'
|
|
5580 */
|
|
5581 while ((!fo_ins_blank && !has_format_option(FO_INS_VI))
|
|
5582 || curwin->w_cursor.lnum != Insstart.lnum
|
|
5583 || curwin->w_cursor.col >= Insstart.col)
|
|
5584 {
|
|
5585 cc = gchar_cursor();
|
|
5586 if (WHITECHAR(cc))
|
|
5587 {
|
|
5588 /* remember position of blank just before text */
|
|
5589 end_foundcol = curwin->w_cursor.col;
|
|
5590
|
|
5591 /* find start of sequence of blanks */
|
|
5592 while (curwin->w_cursor.col > 0 && WHITECHAR(cc))
|
|
5593 {
|
|
5594 dec_cursor();
|
|
5595 cc = gchar_cursor();
|
|
5596 }
|
|
5597 if (curwin->w_cursor.col == 0 && WHITECHAR(cc))
|
|
5598 break; /* only spaces in front of text */
|
|
5599 #ifdef FEAT_COMMENTS
|
|
5600 /* Don't break until after the comment leader */
|
|
5601 if (curwin->w_cursor.col < leader_len)
|
|
5602 break;
|
|
5603 #endif
|
|
5604 if (has_format_option(FO_ONE_LETTER))
|
|
5605 {
|
|
5606 /* do not break after one-letter words */
|
|
5607 if (curwin->w_cursor.col == 0)
|
|
5608 break; /* one-letter word at begin */
|
|
5609
|
|
5610 col = curwin->w_cursor.col;
|
|
5611 dec_cursor();
|
|
5612 cc = gchar_cursor();
|
|
5613
|
|
5614 if (WHITECHAR(cc))
|
|
5615 continue; /* one-letter, continue */
|
|
5616 curwin->w_cursor.col = col;
|
|
5617 }
|
|
5618 #ifdef FEAT_MBYTE
|
|
5619 if (has_mbyte)
|
|
5620 foundcol = curwin->w_cursor.col
|
|
5621 + (*mb_ptr2len)(ml_get_cursor());
|
|
5622 else
|
|
5623 #endif
|
|
5624 foundcol = curwin->w_cursor.col + 1;
|
|
5625 if (curwin->w_cursor.col < (colnr_T)wantcol)
|
|
5626 break;
|
|
5627 }
|
|
5628 #ifdef FEAT_MBYTE
|
|
5629 else if (cc >= 0x100 && fo_multibyte
|
|
5630 && curwin->w_cursor.col <= (colnr_T)wantcol)
|
|
5631 {
|
|
5632 /* Break after or before a multi-byte character. */
|
|
5633 foundcol = curwin->w_cursor.col;
|
|
5634 if (curwin->w_cursor.col < (colnr_T)wantcol)
|
|
5635 foundcol += (*mb_char2len)(cc);
|
|
5636 end_foundcol = foundcol;
|
|
5637 break;
|
|
5638 }
|
|
5639 #endif
|
|
5640 if (curwin->w_cursor.col == 0)
|
|
5641 break;
|
|
5642 dec_cursor();
|
|
5643 }
|
|
5644
|
|
5645 if (foundcol == 0) /* no spaces, cannot break line */
|
|
5646 {
|
|
5647 curwin->w_cursor.col = startcol;
|
|
5648 break;
|
|
5649 }
|
|
5650
|
|
5651 /* Going to break the line, remove any "$" now. */
|
|
5652 undisplay_dollar();
|
|
5653
|
|
5654 /*
|
|
5655 * Offset between cursor position and line break is used by replace
|
|
5656 * stack functions. VREPLACE does not use this, and backspaces
|
|
5657 * over the text instead.
|
|
5658 */
|
|
5659 #ifdef FEAT_VREPLACE
|
|
5660 if (State & VREPLACE_FLAG)
|
|
5661 orig_col = startcol; /* Will start backspacing from here */
|
|
5662 else
|
|
5663 #endif
|
|
5664 replace_offset = startcol - end_foundcol - 1;
|
|
5665
|
|
5666 /*
|
|
5667 * adjust startcol for spaces that will be deleted and
|
|
5668 * characters that will remain on top line
|
|
5669 */
|
|
5670 curwin->w_cursor.col = foundcol;
|
|
5671 while (cc = gchar_cursor(), WHITECHAR(cc))
|
|
5672 inc_cursor();
|
|
5673 startcol -= curwin->w_cursor.col;
|
|
5674 if (startcol < 0)
|
|
5675 startcol = 0;
|
|
5676
|
|
5677 #ifdef FEAT_VREPLACE
|
|
5678 if (State & VREPLACE_FLAG)
|
|
5679 {
|
|
5680 /*
|
|
5681 * In VREPLACE mode, we will backspace over the text to be
|
|
5682 * wrapped, so save a copy now to put on the next line.
|
|
5683 */
|
|
5684 saved_text = vim_strsave(ml_get_cursor());
|
|
5685 curwin->w_cursor.col = orig_col;
|
|
5686 if (saved_text == NULL)
|
|
5687 break; /* Can't do it, out of memory */
|
|
5688 saved_text[startcol] = NUL;
|
|
5689
|
|
5690 /* Backspace over characters that will move to the next line */
|
|
5691 if (!fo_white_par)
|
|
5692 backspace_until_column(foundcol);
|
|
5693 }
|
|
5694 else
|
|
5695 #endif
|
|
5696 {
|
|
5697 /* put cursor after pos. to break line */
|
|
5698 if (!fo_white_par)
|
|
5699 curwin->w_cursor.col = foundcol;
|
|
5700 }
|
|
5701
|
|
5702 /*
|
|
5703 * Split the line just before the margin.
|
|
5704 * Only insert/delete lines, but don't really redraw the window.
|
|
5705 */
|
|
5706 open_line(FORWARD, OPENLINE_DELSPACES + OPENLINE_MARKFIX
|
|
5707 + (fo_white_par ? OPENLINE_KEEPTRAIL : 0)
|
|
5708 #ifdef FEAT_COMMENTS
|
|
5709 + (do_comments ? OPENLINE_DO_COM : 0)
|
|
5710 #endif
|
|
5711 , old_indent);
|
|
5712 old_indent = 0;
|
|
5713
|
|
5714 replace_offset = 0;
|
|
5715 if (first_line)
|
|
5716 {
|
|
5717 if (second_indent < 0 && has_format_option(FO_Q_NUMBER))
|
|
5718 second_indent = get_number_indent(curwin->w_cursor.lnum -1);
|
|
5719 if (second_indent >= 0)
|
|
5720 {
|
|
5721 #ifdef FEAT_VREPLACE
|
|
5722 if (State & VREPLACE_FLAG)
|
|
5723 change_indent(INDENT_SET, second_indent, FALSE, NUL);
|
|
5724 else
|
|
5725 #endif
|
|
5726 (void)set_indent(second_indent, SIN_CHANGED);
|
|
5727 }
|
|
5728 first_line = FALSE;
|
|
5729 }
|
|
5730
|
|
5731 #ifdef FEAT_VREPLACE
|
|
5732 if (State & VREPLACE_FLAG)
|
|
5733 {
|
|
5734 /*
|
|
5735 * In VREPLACE mode we have backspaced over the text to be
|
|
5736 * moved, now we re-insert it into the new line.
|
|
5737 */
|
|
5738 ins_bytes(saved_text);
|
|
5739 vim_free(saved_text);
|
|
5740 }
|
|
5741 else
|
|
5742 #endif
|
|
5743 {
|
|
5744 /*
|
|
5745 * Check if cursor is not past the NUL off the line, cindent
|
|
5746 * may have added or removed indent.
|
|
5747 */
|
|
5748 curwin->w_cursor.col += startcol;
|
|
5749 len = (colnr_T)STRLEN(ml_get_curline());
|
|
5750 if (curwin->w_cursor.col > len)
|
|
5751 curwin->w_cursor.col = len;
|
|
5752 }
|
|
5753
|
|
5754 haveto_redraw = TRUE;
|
|
5755 #ifdef FEAT_CINDENT
|
|
5756 can_cindent = TRUE;
|
|
5757 #endif
|
|
5758 /* moved the cursor, don't autoindent or cindent now */
|
|
5759 did_ai = FALSE;
|
|
5760 #ifdef FEAT_SMARTINDENT
|
|
5761 did_si = FALSE;
|
|
5762 can_si = FALSE;
|
|
5763 can_si_back = FALSE;
|
|
5764 #endif
|
|
5765 line_breakcheck();
|
|
5766 }
|
|
5767
|
|
5768 if (save_char != NUL) /* put back space after cursor */
|
|
5769 pchar_cursor(save_char);
|
|
5770
|
|
5771 if (!format_only && haveto_redraw)
|
|
5772 {
|
|
5773 update_topline();
|
|
5774 redraw_curbuf_later(VALID);
|
|
5775 }
|
|
5776 }
|
|
5777
|
|
5778 /*
|
7
|
5779 * Called after inserting or deleting text: When 'formatoptions' includes the
|
|
5780 * 'a' flag format from the current line until the end of the paragraph.
|
|
5781 * Keep the cursor at the same position relative to the text.
|
|
5782 * The caller must have saved the cursor line for undo, following ones will be
|
|
5783 * saved here.
|
|
5784 */
|
|
5785 void
|
|
5786 auto_format(trailblank, prev_line)
|
|
5787 int trailblank; /* when TRUE also format with trailing blank */
|
|
5788 int prev_line; /* may start in previous line */
|
|
5789 {
|
|
5790 pos_T pos;
|
|
5791 colnr_T len;
|
|
5792 char_u *old;
|
|
5793 char_u *new, *pnew;
|
|
5794 int wasatend;
|
301
|
5795 int cc;
|
7
|
5796
|
|
5797 if (!has_format_option(FO_AUTO))
|
|
5798 return;
|
|
5799
|
|
5800 pos = curwin->w_cursor;
|
|
5801 old = ml_get_curline();
|
|
5802
|
|
5803 /* may remove added space */
|
|
5804 check_auto_format(FALSE);
|
|
5805
|
|
5806 /* Don't format in Insert mode when the cursor is on a trailing blank, the
|
|
5807 * user might insert normal text next. Also skip formatting when "1" is
|
|
5808 * in 'formatoptions' and there is a single character before the cursor.
|
|
5809 * Otherwise the line would be broken and when typing another non-white
|
|
5810 * next they are not joined back together. */
|
|
5811 wasatend = (pos.col == STRLEN(old));
|
|
5812 if (*old != NUL && !trailblank && wasatend)
|
|
5813 {
|
|
5814 dec_cursor();
|
301
|
5815 cc = gchar_cursor();
|
|
5816 if (!WHITECHAR(cc) && curwin->w_cursor.col > 0
|
|
5817 && has_format_option(FO_ONE_LETTER))
|
7
|
5818 dec_cursor();
|
301
|
5819 cc = gchar_cursor();
|
|
5820 if (WHITECHAR(cc))
|
7
|
5821 {
|
|
5822 curwin->w_cursor = pos;
|
|
5823 return;
|
|
5824 }
|
|
5825 curwin->w_cursor = pos;
|
|
5826 }
|
|
5827
|
|
5828 #ifdef FEAT_COMMENTS
|
|
5829 /* With the 'c' flag in 'formatoptions' and 't' missing: only format
|
|
5830 * comments. */
|
|
5831 if (has_format_option(FO_WRAP_COMS) && !has_format_option(FO_WRAP)
|
|
5832 && get_leader_len(old, NULL, FALSE) == 0)
|
|
5833 return;
|
|
5834 #endif
|
|
5835
|
|
5836 /*
|
|
5837 * May start formatting in a previous line, so that after "x" a word is
|
|
5838 * moved to the previous line if it fits there now. Only when this is not
|
|
5839 * the start of a paragraph.
|
|
5840 */
|
|
5841 if (prev_line && !paragraph_start(curwin->w_cursor.lnum))
|
|
5842 {
|
|
5843 --curwin->w_cursor.lnum;
|
|
5844 if (u_save_cursor() == FAIL)
|
|
5845 return;
|
|
5846 }
|
|
5847
|
|
5848 /*
|
|
5849 * Do the formatting and restore the cursor position. "saved_cursor" will
|
|
5850 * be adjusted for the text formatting.
|
|
5851 */
|
|
5852 saved_cursor = pos;
|
|
5853 format_lines((linenr_T)-1);
|
|
5854 curwin->w_cursor = saved_cursor;
|
|
5855 saved_cursor.lnum = 0;
|
|
5856
|
|
5857 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
|
|
5858 {
|
|
5859 /* "cannot happen" */
|
|
5860 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
|
5861 coladvance((colnr_T)MAXCOL);
|
|
5862 }
|
|
5863 else
|
|
5864 check_cursor_col();
|
|
5865
|
|
5866 /* Insert mode: If the cursor is now after the end of the line while it
|
|
5867 * previously wasn't, the line was broken. Because of the rule above we
|
|
5868 * need to add a space when 'w' is in 'formatoptions' to keep a paragraph
|
|
5869 * formatted. */
|
|
5870 if (!wasatend && has_format_option(FO_WHITE_PAR))
|
|
5871 {
|
|
5872 new = ml_get_curline();
|
835
|
5873 len = (colnr_T)STRLEN(new);
|
7
|
5874 if (curwin->w_cursor.col == len)
|
|
5875 {
|
|
5876 pnew = vim_strnsave(new, len + 2);
|
|
5877 pnew[len] = ' ';
|
|
5878 pnew[len + 1] = NUL;
|
|
5879 ml_replace(curwin->w_cursor.lnum, pnew, FALSE);
|
|
5880 /* remove the space later */
|
|
5881 did_add_space = TRUE;
|
|
5882 }
|
|
5883 else
|
|
5884 /* may remove added space */
|
|
5885 check_auto_format(FALSE);
|
|
5886 }
|
|
5887
|
|
5888 check_cursor();
|
|
5889 }
|
|
5890
|
|
5891 /*
|
|
5892 * When an extra space was added to continue a paragraph for auto-formatting,
|
|
5893 * delete it now. The space must be under the cursor, just after the insert
|
|
5894 * position.
|
|
5895 */
|
|
5896 static void
|
|
5897 check_auto_format(end_insert)
|
|
5898 int end_insert; /* TRUE when ending Insert mode */
|
|
5899 {
|
|
5900 int c = ' ';
|
301
|
5901 int cc;
|
7
|
5902
|
|
5903 if (did_add_space)
|
|
5904 {
|
301
|
5905 cc = gchar_cursor();
|
|
5906 if (!WHITECHAR(cc))
|
7
|
5907 /* Somehow the space was removed already. */
|
|
5908 did_add_space = FALSE;
|
|
5909 else
|
|
5910 {
|
|
5911 if (!end_insert)
|
|
5912 {
|
|
5913 inc_cursor();
|
|
5914 c = gchar_cursor();
|
|
5915 dec_cursor();
|
|
5916 }
|
|
5917 if (c != NUL)
|
|
5918 {
|
|
5919 /* The space is no longer at the end of the line, delete it. */
|
|
5920 del_char(FALSE);
|
|
5921 did_add_space = FALSE;
|
|
5922 }
|
|
5923 }
|
|
5924 }
|
|
5925 }
|
|
5926
|
|
5927 /*
|
|
5928 * Find out textwidth to be used for formatting:
|
|
5929 * if 'textwidth' option is set, use it
|
|
5930 * else if 'wrapmargin' option is set, use W_WIDTH(curwin) - 'wrapmargin'
|
|
5931 * if invalid value, use 0.
|
|
5932 * Set default to window width (maximum 79) for "gq" operator.
|
|
5933 */
|
|
5934 int
|
|
5935 comp_textwidth(ff)
|
867
|
5936 int ff; /* force formatting (for "gq" command) */
|
7
|
5937 {
|
|
5938 int textwidth;
|
|
5939
|
|
5940 textwidth = curbuf->b_p_tw;
|
|
5941 if (textwidth == 0 && curbuf->b_p_wm)
|
|
5942 {
|
|
5943 /* The width is the window width minus 'wrapmargin' minus all the
|
|
5944 * things that add to the margin. */
|
|
5945 textwidth = W_WIDTH(curwin) - curbuf->b_p_wm;
|
|
5946 #ifdef FEAT_CMDWIN
|
|
5947 if (cmdwin_type != 0)
|
|
5948 textwidth -= 1;
|
|
5949 #endif
|
|
5950 #ifdef FEAT_FOLDING
|
|
5951 textwidth -= curwin->w_p_fdc;
|
|
5952 #endif
|
|
5953 #ifdef FEAT_SIGNS
|
|
5954 if (curwin->w_buffer->b_signlist != NULL
|
|
5955 # ifdef FEAT_NETBEANS_INTG
|
|
5956 || usingNetbeans
|
|
5957 # endif
|
|
5958 )
|
|
5959 textwidth -= 1;
|
|
5960 #endif
|
|
5961 if (curwin->w_p_nu)
|
|
5962 textwidth -= 8;
|
|
5963 }
|
|
5964 if (textwidth < 0)
|
|
5965 textwidth = 0;
|
|
5966 if (ff && textwidth == 0)
|
|
5967 {
|
|
5968 textwidth = W_WIDTH(curwin) - 1;
|
|
5969 if (textwidth > 79)
|
|
5970 textwidth = 79;
|
|
5971 }
|
|
5972 return textwidth;
|
|
5973 }
|
|
5974
|
|
5975 /*
|
|
5976 * Put a character in the redo buffer, for when just after a CTRL-V.
|
|
5977 */
|
|
5978 static void
|
|
5979 redo_literal(c)
|
|
5980 int c;
|
|
5981 {
|
|
5982 char_u buf[10];
|
|
5983
|
|
5984 /* Only digits need special treatment. Translate them into a string of
|
|
5985 * three digits. */
|
|
5986 if (VIM_ISDIGIT(c))
|
|
5987 {
|
|
5988 sprintf((char *)buf, "%03d", c);
|
|
5989 AppendToRedobuff(buf);
|
|
5990 }
|
|
5991 else
|
|
5992 AppendCharToRedobuff(c);
|
|
5993 }
|
|
5994
|
|
5995 /*
|
|
5996 * start_arrow() is called when an arrow key is used in insert mode.
|
484
|
5997 * For undo/redo it resembles hitting the <ESC> key.
|
7
|
5998 */
|
|
5999 static void
|
|
6000 start_arrow(end_insert_pos)
|
840
|
6001 pos_T *end_insert_pos; /* can be NULL */
|
7
|
6002 {
|
|
6003 if (!arrow_used) /* something has been inserted */
|
|
6004 {
|
|
6005 AppendToRedobuff(ESC_STR);
|
|
6006 stop_insert(end_insert_pos, FALSE);
|
|
6007 arrow_used = TRUE; /* this means we stopped the current insert */
|
|
6008 }
|
744
|
6009 #ifdef FEAT_SPELL
|
221
|
6010 check_spell_redraw();
|
|
6011 #endif
|
7
|
6012 }
|
|
6013
|
744
|
6014 #ifdef FEAT_SPELL
|
221
|
6015 /*
|
|
6016 * If we skipped highlighting word at cursor, do it now.
|
|
6017 * It may be skipped again, thus reset spell_redraw_lnum first.
|
|
6018 */
|
|
6019 static void
|
|
6020 check_spell_redraw()
|
|
6021 {
|
|
6022 if (spell_redraw_lnum != 0)
|
|
6023 {
|
|
6024 linenr_T lnum = spell_redraw_lnum;
|
|
6025
|
|
6026 spell_redraw_lnum = 0;
|
|
6027 redrawWinline(lnum, FALSE);
|
|
6028 }
|
|
6029 }
|
484
|
6030
|
|
6031 /*
|
|
6032 * Called when starting CTRL_X_SPELL mode: Move backwards to a previous badly
|
|
6033 * spelled word, if there is one.
|
|
6034 */
|
|
6035 static void
|
|
6036 spell_back_to_badword()
|
|
6037 {
|
|
6038 pos_T tpos = curwin->w_cursor;
|
|
6039
|
499
|
6040 spell_bad_len = spell_move_to(curwin, BACKWARD, TRUE, TRUE, NULL);
|
484
|
6041 if (curwin->w_cursor.col != tpos.col)
|
|
6042 start_arrow(&tpos);
|
|
6043 }
|
221
|
6044 #endif
|
|
6045
|
7
|
6046 /*
|
|
6047 * stop_arrow() is called before a change is made in insert mode.
|
|
6048 * If an arrow key has been used, start a new insertion.
|
|
6049 * Returns FAIL if undo is impossible, shouldn't insert then.
|
|
6050 */
|
|
6051 int
|
|
6052 stop_arrow()
|
|
6053 {
|
|
6054 if (arrow_used)
|
|
6055 {
|
|
6056 if (u_save_cursor() == OK)
|
|
6057 {
|
|
6058 arrow_used = FALSE;
|
|
6059 ins_need_undo = FALSE;
|
|
6060 }
|
|
6061 Insstart = curwin->w_cursor; /* new insertion starts here */
|
|
6062 Insstart_textlen = linetabsize(ml_get_curline());
|
|
6063 ai_col = 0;
|
|
6064 #ifdef FEAT_VREPLACE
|
|
6065 if (State & VREPLACE_FLAG)
|
|
6066 {
|
|
6067 orig_line_count = curbuf->b_ml.ml_line_count;
|
|
6068 vr_lines_changed = 1;
|
|
6069 }
|
|
6070 #endif
|
|
6071 ResetRedobuff();
|
|
6072 AppendToRedobuff((char_u *)"1i"); /* pretend we start an insertion */
|
613
|
6073 new_insert_skip = 2;
|
7
|
6074 }
|
|
6075 else if (ins_need_undo)
|
|
6076 {
|
|
6077 if (u_save_cursor() == OK)
|
|
6078 ins_need_undo = FALSE;
|
|
6079 }
|
|
6080
|
|
6081 #ifdef FEAT_FOLDING
|
|
6082 /* Always open fold at the cursor line when inserting something. */
|
|
6083 foldOpenCursor();
|
|
6084 #endif
|
|
6085
|
|
6086 return (arrow_used || ins_need_undo ? FAIL : OK);
|
|
6087 }
|
|
6088
|
|
6089 /*
|
840
|
6090 * Do a few things to stop inserting.
|
|
6091 * "end_insert_pos" is where insert ended. It is NULL when we already jumped
|
|
6092 * to another window/buffer.
|
7
|
6093 */
|
|
6094 static void
|
|
6095 stop_insert(end_insert_pos, esc)
|
840
|
6096 pos_T *end_insert_pos;
|
603
|
6097 int esc; /* called by ins_esc() */
|
7
|
6098 {
|
603
|
6099 int cc;
|
|
6100 char_u *ptr;
|
7
|
6101
|
|
6102 stop_redo_ins();
|
|
6103 replace_flush(); /* abandon replace stack */
|
|
6104
|
|
6105 /*
|
603
|
6106 * Save the inserted text for later redo with ^@ and CTRL-A.
|
|
6107 * Don't do it when "restart_edit" was set and nothing was inserted,
|
|
6108 * otherwise CTRL-O w and then <Left> will clear "last_insert".
|
7
|
6109 */
|
603
|
6110 ptr = get_inserted();
|
615
|
6111 if (did_restart_edit == 0 || (ptr != NULL
|
|
6112 && (int)STRLEN(ptr) > new_insert_skip))
|
603
|
6113 {
|
|
6114 vim_free(last_insert);
|
|
6115 last_insert = ptr;
|
|
6116 last_insert_skip = new_insert_skip;
|
|
6117 }
|
|
6118 else
|
|
6119 vim_free(ptr);
|
7
|
6120
|
840
|
6121 if (!arrow_used && end_insert_pos != NULL)
|
7
|
6122 {
|
|
6123 /* Auto-format now. It may seem strange to do this when stopping an
|
|
6124 * insertion (or moving the cursor), but it's required when appending
|
|
6125 * a line and having it end in a space. But only do it when something
|
|
6126 * was actually inserted, otherwise undo won't work. */
|
10
|
6127 if (!ins_need_undo && has_format_option(FO_AUTO))
|
7
|
6128 {
|
10
|
6129 pos_T tpos = curwin->w_cursor;
|
|
6130
|
7
|
6131 /* When the cursor is at the end of the line after a space the
|
|
6132 * formatting will move it to the following word. Avoid that by
|
|
6133 * moving the cursor onto the space. */
|
|
6134 cc = 'x';
|
|
6135 if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL)
|
|
6136 {
|
|
6137 dec_cursor();
|
|
6138 cc = gchar_cursor();
|
|
6139 if (!vim_iswhite(cc))
|
10
|
6140 curwin->w_cursor = tpos;
|
7
|
6141 }
|
|
6142
|
|
6143 auto_format(TRUE, FALSE);
|
|
6144
|
10
|
6145 if (vim_iswhite(cc))
|
|
6146 {
|
|
6147 if (gchar_cursor() != NUL)
|
|
6148 inc_cursor();
|
|
6149 #ifdef FEAT_VIRTUALEDIT
|
|
6150 /* If the cursor is still at the same character, also keep
|
|
6151 * the "coladd". */
|
|
6152 if (gchar_cursor() == NUL
|
|
6153 && curwin->w_cursor.lnum == tpos.lnum
|
|
6154 && curwin->w_cursor.col == tpos.col)
|
|
6155 curwin->w_cursor.coladd = tpos.coladd;
|
|
6156 #endif
|
|
6157 }
|
7
|
6158 }
|
|
6159
|
|
6160 /* If a space was inserted for auto-formatting, remove it now. */
|
|
6161 check_auto_format(TRUE);
|
|
6162
|
|
6163 /* If we just did an auto-indent, remove the white space from the end
|
10
|
6164 * of the line, and put the cursor back.
|
|
6165 * Do this when ESC was used or moving the cursor up/down. */
|
|
6166 if (did_ai && (esc || (vim_strchr(p_cpo, CPO_INDENT) == NULL
|
840
|
6167 && curwin->w_cursor.lnum != end_insert_pos->lnum)))
|
7
|
6168 {
|
10
|
6169 pos_T tpos = curwin->w_cursor;
|
|
6170
|
|
6171 curwin->w_cursor = *end_insert_pos;
|
786
|
6172 for (;;)
|
|
6173 {
|
|
6174 if (gchar_cursor() == NUL && curwin->w_cursor.col > 0)
|
|
6175 --curwin->w_cursor.col;
|
|
6176 cc = gchar_cursor();
|
|
6177 if (!vim_iswhite(cc))
|
|
6178 break;
|
7
|
6179 (void)del_char(TRUE);
|
786
|
6180 }
|
10
|
6181 if (curwin->w_cursor.lnum != tpos.lnum)
|
|
6182 curwin->w_cursor = tpos;
|
|
6183 else if (cc != NUL)
|
7
|
6184 ++curwin->w_cursor.col; /* put cursor back on the NUL */
|
|
6185
|
|
6186 #ifdef FEAT_VISUAL
|
|
6187 /* <C-S-Right> may have started Visual mode, adjust the position for
|
|
6188 * deleted characters. */
|
|
6189 if (VIsual_active && VIsual.lnum == curwin->w_cursor.lnum)
|
|
6190 {
|
835
|
6191 cc = (int)STRLEN(ml_get_curline());
|
7
|
6192 if (VIsual.col > (colnr_T)cc)
|
|
6193 {
|
|
6194 VIsual.col = cc;
|
|
6195 # ifdef FEAT_VIRTUALEDIT
|
|
6196 VIsual.coladd = 0;
|
|
6197 # endif
|
|
6198 }
|
|
6199 }
|
|
6200 #endif
|
|
6201 }
|
|
6202 }
|
|
6203 did_ai = FALSE;
|
|
6204 #ifdef FEAT_SMARTINDENT
|
|
6205 did_si = FALSE;
|
|
6206 can_si = FALSE;
|
|
6207 can_si_back = FALSE;
|
|
6208 #endif
|
|
6209
|
840
|
6210 /* Set '[ and '] to the inserted text. When end_insert_pos is NULL we are
|
|
6211 * now in a different buffer. */
|
|
6212 if (end_insert_pos != NULL)
|
|
6213 {
|
|
6214 curbuf->b_op_start = Insstart;
|
|
6215 curbuf->b_op_end = *end_insert_pos;
|
|
6216 }
|
7
|
6217 }
|
|
6218
|
|
6219 /*
|
|
6220 * Set the last inserted text to a single character.
|
|
6221 * Used for the replace command.
|
|
6222 */
|
|
6223 void
|
|
6224 set_last_insert(c)
|
|
6225 int c;
|
|
6226 {
|
|
6227 char_u *s;
|
|
6228
|
|
6229 vim_free(last_insert);
|
|
6230 #ifdef FEAT_MBYTE
|
|
6231 last_insert = alloc(MB_MAXBYTES * 3 + 5);
|
|
6232 #else
|
|
6233 last_insert = alloc(6);
|
|
6234 #endif
|
|
6235 if (last_insert != NULL)
|
|
6236 {
|
|
6237 s = last_insert;
|
|
6238 /* Use the CTRL-V only when entering a special char */
|
|
6239 if (c < ' ' || c == DEL)
|
|
6240 *s++ = Ctrl_V;
|
|
6241 s = add_char2buf(c, s);
|
|
6242 *s++ = ESC;
|
|
6243 *s++ = NUL;
|
|
6244 last_insert_skip = 0;
|
|
6245 }
|
|
6246 }
|
|
6247
|
359
|
6248 #if defined(EXITFREE) || defined(PROTO)
|
|
6249 void
|
|
6250 free_last_insert()
|
|
6251 {
|
|
6252 vim_free(last_insert);
|
|
6253 last_insert = NULL;
|
694
|
6254 vim_free(compl_orig_text);
|
|
6255 compl_orig_text = NULL;
|
359
|
6256 }
|
|
6257 #endif
|
|
6258
|
7
|
6259 /*
|
|
6260 * Add character "c" to buffer "s". Escape the special meaning of K_SPECIAL
|
|
6261 * and CSI. Handle multi-byte characters.
|
|
6262 * Returns a pointer to after the added bytes.
|
|
6263 */
|
|
6264 char_u *
|
|
6265 add_char2buf(c, s)
|
|
6266 int c;
|
|
6267 char_u *s;
|
|
6268 {
|
|
6269 #ifdef FEAT_MBYTE
|
|
6270 char_u temp[MB_MAXBYTES];
|
|
6271 int i;
|
|
6272 int len;
|
|
6273
|
|
6274 len = (*mb_char2bytes)(c, temp);
|
|
6275 for (i = 0; i < len; ++i)
|
|
6276 {
|
|
6277 c = temp[i];
|
|
6278 #endif
|
|
6279 /* Need to escape K_SPECIAL and CSI like in the typeahead buffer. */
|
|
6280 if (c == K_SPECIAL)
|
|
6281 {
|
|
6282 *s++ = K_SPECIAL;
|
|
6283 *s++ = KS_SPECIAL;
|
|
6284 *s++ = KE_FILLER;
|
|
6285 }
|
|
6286 #ifdef FEAT_GUI
|
|
6287 else if (c == CSI)
|
|
6288 {
|
|
6289 *s++ = CSI;
|
|
6290 *s++ = KS_EXTRA;
|
|
6291 *s++ = (int)KE_CSI;
|
|
6292 }
|
|
6293 #endif
|
|
6294 else
|
|
6295 *s++ = c;
|
|
6296 #ifdef FEAT_MBYTE
|
|
6297 }
|
|
6298 #endif
|
|
6299 return s;
|
|
6300 }
|
|
6301
|
|
6302 /*
|
|
6303 * move cursor to start of line
|
|
6304 * if flags & BL_WHITE move to first non-white
|
|
6305 * if flags & BL_SOL move to first non-white if startofline is set,
|
|
6306 * otherwise keep "curswant" column
|
|
6307 * if flags & BL_FIX don't leave the cursor on a NUL.
|
|
6308 */
|
|
6309 void
|
|
6310 beginline(flags)
|
|
6311 int flags;
|
|
6312 {
|
|
6313 if ((flags & BL_SOL) && !p_sol)
|
|
6314 coladvance(curwin->w_curswant);
|
|
6315 else
|
|
6316 {
|
|
6317 curwin->w_cursor.col = 0;
|
|
6318 #ifdef FEAT_VIRTUALEDIT
|
|
6319 curwin->w_cursor.coladd = 0;
|
|
6320 #endif
|
|
6321
|
|
6322 if (flags & (BL_WHITE | BL_SOL))
|
|
6323 {
|
|
6324 char_u *ptr;
|
|
6325
|
|
6326 for (ptr = ml_get_curline(); vim_iswhite(*ptr)
|
|
6327 && !((flags & BL_FIX) && ptr[1] == NUL); ++ptr)
|
|
6328 ++curwin->w_cursor.col;
|
|
6329 }
|
|
6330 curwin->w_set_curswant = TRUE;
|
|
6331 }
|
|
6332 }
|
|
6333
|
|
6334 /*
|
|
6335 * oneright oneleft cursor_down cursor_up
|
|
6336 *
|
|
6337 * Move one char {right,left,down,up}.
|
773
|
6338 * Doesn't move onto the NUL past the end of the line, unless it is allowed.
|
7
|
6339 * Return OK when successful, FAIL when we hit a line of file boundary.
|
|
6340 */
|
|
6341
|
|
6342 int
|
|
6343 oneright()
|
|
6344 {
|
|
6345 char_u *ptr;
|
|
6346 int l;
|
|
6347
|
|
6348 #ifdef FEAT_VIRTUALEDIT
|
|
6349 if (virtual_active())
|
|
6350 {
|
|
6351 pos_T prevpos = curwin->w_cursor;
|
|
6352
|
|
6353 /* Adjust for multi-wide char (excluding TAB) */
|
|
6354 ptr = ml_get_cursor();
|
|
6355 coladvance(getviscol() + ((*ptr != TAB && vim_isprintc(
|
773
|
6356 # ifdef FEAT_MBYTE
|
7
|
6357 (*mb_ptr2char)(ptr)
|
773
|
6358 # else
|
7
|
6359 *ptr
|
773
|
6360 # endif
|
7
|
6361 ))
|
|
6362 ? ptr2cells(ptr) : 1));
|
|
6363 curwin->w_set_curswant = TRUE;
|
|
6364 /* Return OK if the cursor moved, FAIL otherwise (at window edge). */
|
|
6365 return (prevpos.col != curwin->w_cursor.col
|
|
6366 || prevpos.coladd != curwin->w_cursor.coladd) ? OK : FAIL;
|
|
6367 }
|
|
6368 #endif
|
|
6369
|
|
6370 ptr = ml_get_cursor();
|
773
|
6371 if (*ptr == NUL)
|
|
6372 return FAIL; /* already at the very end */
|
|
6373
|
7
|
6374 #ifdef FEAT_MBYTE
|
773
|
6375 if (has_mbyte)
|
|
6376 l = (*mb_ptr2len)(ptr);
|
7
|
6377 else
|
|
6378 #endif
|
773
|
6379 l = 1;
|
|
6380
|
|
6381 /* move "l" bytes right, but don't end up on the NUL, unless 'virtualedit'
|
|
6382 * contains "onemore". */
|
|
6383 if (ptr[l] == NUL
|
|
6384 #ifdef FEAT_VIRTUALEDIT
|
|
6385 && (ve_flags & VE_ONEMORE) == 0
|
|
6386 #endif
|
|
6387 )
|
|
6388 return FAIL;
|
|
6389 curwin->w_cursor.col += l;
|
7
|
6390
|
|
6391 curwin->w_set_curswant = TRUE;
|
|
6392 return OK;
|
|
6393 }
|
|
6394
|
|
6395 int
|
|
6396 oneleft()
|
|
6397 {
|
|
6398 #ifdef FEAT_VIRTUALEDIT
|
|
6399 if (virtual_active())
|
|
6400 {
|
|
6401 int width;
|
|
6402 int v = getviscol();
|
|
6403
|
|
6404 if (v == 0)
|
|
6405 return FAIL;
|
|
6406
|
|
6407 # ifdef FEAT_LINEBREAK
|
|
6408 /* We might get stuck on 'showbreak', skip over it. */
|
|
6409 width = 1;
|
|
6410 for (;;)
|
|
6411 {
|
|
6412 coladvance(v - width);
|
|
6413 /* getviscol() is slow, skip it when 'showbreak' is empty and
|
|
6414 * there are no multi-byte characters */
|
|
6415 if ((*p_sbr == NUL
|
|
6416 # ifdef FEAT_MBYTE
|
|
6417 && !has_mbyte
|
|
6418 # endif
|
|
6419 ) || getviscol() < v)
|
|
6420 break;
|
|
6421 ++width;
|
|
6422 }
|
|
6423 # else
|
|
6424 coladvance(v - 1);
|
|
6425 # endif
|
|
6426
|
|
6427 if (curwin->w_cursor.coladd == 1)
|
|
6428 {
|
|
6429 char_u *ptr;
|
|
6430
|
|
6431 /* Adjust for multi-wide char (not a TAB) */
|
|
6432 ptr = ml_get_cursor();
|
|
6433 if (*ptr != TAB && vim_isprintc(
|
|
6434 # ifdef FEAT_MBYTE
|
|
6435 (*mb_ptr2char)(ptr)
|
|
6436 # else
|
|
6437 *ptr
|
|
6438 # endif
|
|
6439 ) && ptr2cells(ptr) > 1)
|
|
6440 curwin->w_cursor.coladd = 0;
|
|
6441 }
|
|
6442
|
|
6443 curwin->w_set_curswant = TRUE;
|
|
6444 return OK;
|
|
6445 }
|
|
6446 #endif
|
|
6447
|
|
6448 if (curwin->w_cursor.col == 0)
|
|
6449 return FAIL;
|
|
6450
|
|
6451 curwin->w_set_curswant = TRUE;
|
|
6452 --curwin->w_cursor.col;
|
|
6453
|
|
6454 #ifdef FEAT_MBYTE
|
|
6455 /* if the character on the left of the current cursor is a multi-byte
|
|
6456 * character, move to its first byte */
|
|
6457 if (has_mbyte)
|
|
6458 mb_adjust_cursor();
|
|
6459 #endif
|
|
6460 return OK;
|
|
6461 }
|
|
6462
|
|
6463 int
|
|
6464 cursor_up(n, upd_topline)
|
|
6465 long n;
|
|
6466 int upd_topline; /* When TRUE: update topline */
|
|
6467 {
|
|
6468 linenr_T lnum;
|
|
6469
|
|
6470 if (n > 0)
|
|
6471 {
|
|
6472 lnum = curwin->w_cursor.lnum;
|
161
|
6473 /* This fails if the cursor is already in the first line or the count
|
|
6474 * is larger than the line number and '-' is in 'cpoptions' */
|
|
6475 if (lnum <= 1 || (n >= lnum && vim_strchr(p_cpo, CPO_MINUS) != NULL))
|
7
|
6476 return FAIL;
|
|
6477 if (n >= lnum)
|
|
6478 lnum = 1;
|
|
6479 else
|
|
6480 #ifdef FEAT_FOLDING
|
|
6481 if (hasAnyFolding(curwin))
|
|
6482 {
|
|
6483 /*
|
|
6484 * Count each sequence of folded lines as one logical line.
|
|
6485 */
|
|
6486 /* go to the the start of the current fold */
|
|
6487 (void)hasFolding(lnum, &lnum, NULL);
|
|
6488
|
|
6489 while (n--)
|
|
6490 {
|
|
6491 /* move up one line */
|
|
6492 --lnum;
|
|
6493 if (lnum <= 1)
|
|
6494 break;
|
|
6495 /* If we entered a fold, move to the beginning, unless in
|
|
6496 * Insert mode or when 'foldopen' contains "all": it will open
|
|
6497 * in a moment. */
|
|
6498 if (n > 0 || !((State & INSERT) || (fdo_flags & FDO_ALL)))
|
|
6499 (void)hasFolding(lnum, &lnum, NULL);
|
|
6500 }
|
|
6501 if (lnum < 1)
|
|
6502 lnum = 1;
|
|
6503 }
|
|
6504 else
|
|
6505 #endif
|
|
6506 lnum -= n;
|
|
6507 curwin->w_cursor.lnum = lnum;
|
|
6508 }
|
|
6509
|
|
6510 /* try to advance to the column we want to be at */
|
|
6511 coladvance(curwin->w_curswant);
|
|
6512
|
|
6513 if (upd_topline)
|
|
6514 update_topline(); /* make sure curwin->w_topline is valid */
|
|
6515
|
|
6516 return OK;
|
|
6517 }
|
|
6518
|
|
6519 /*
|
|
6520 * Cursor down a number of logical lines.
|
|
6521 */
|
|
6522 int
|
|
6523 cursor_down(n, upd_topline)
|
|
6524 long n;
|
|
6525 int upd_topline; /* When TRUE: update topline */
|
|
6526 {
|
|
6527 linenr_T lnum;
|
|
6528
|
|
6529 if (n > 0)
|
|
6530 {
|
|
6531 lnum = curwin->w_cursor.lnum;
|
|
6532 #ifdef FEAT_FOLDING
|
|
6533 /* Move to last line of fold, will fail if it's the end-of-file. */
|
|
6534 (void)hasFolding(lnum, NULL, &lnum);
|
|
6535 #endif
|
161
|
6536 /* This fails if the cursor is already in the last line or would move
|
|
6537 * beyound the last line and '-' is in 'cpoptions' */
|
|
6538 if (lnum >= curbuf->b_ml.ml_line_count
|
|
6539 || (lnum + n > curbuf->b_ml.ml_line_count
|
|
6540 && vim_strchr(p_cpo, CPO_MINUS) != NULL))
|
7
|
6541 return FAIL;
|
|
6542 if (lnum + n >= curbuf->b_ml.ml_line_count)
|
|
6543 lnum = curbuf->b_ml.ml_line_count;
|
|
6544 else
|
|
6545 #ifdef FEAT_FOLDING
|
|
6546 if (hasAnyFolding(curwin))
|
|
6547 {
|
|
6548 linenr_T last;
|
|
6549
|
|
6550 /* count each sequence of folded lines as one logical line */
|
|
6551 while (n--)
|
|
6552 {
|
|
6553 if (hasFolding(lnum, NULL, &last))
|
|
6554 lnum = last + 1;
|
|
6555 else
|
|
6556 ++lnum;
|
|
6557 if (lnum >= curbuf->b_ml.ml_line_count)
|
|
6558 break;
|
|
6559 }
|
|
6560 if (lnum > curbuf->b_ml.ml_line_count)
|
|
6561 lnum = curbuf->b_ml.ml_line_count;
|
|
6562 }
|
|
6563 else
|
|
6564 #endif
|
|
6565 lnum += n;
|
|
6566 curwin->w_cursor.lnum = lnum;
|
|
6567 }
|
|
6568
|
|
6569 /* try to advance to the column we want to be at */
|
|
6570 coladvance(curwin->w_curswant);
|
|
6571
|
|
6572 if (upd_topline)
|
|
6573 update_topline(); /* make sure curwin->w_topline is valid */
|
|
6574
|
|
6575 return OK;
|
|
6576 }
|
|
6577
|
|
6578 /*
|
|
6579 * Stuff the last inserted text in the read buffer.
|
|
6580 * Last_insert actually is a copy of the redo buffer, so we
|
|
6581 * first have to remove the command.
|
|
6582 */
|
|
6583 int
|
|
6584 stuff_inserted(c, count, no_esc)
|
|
6585 int c; /* Command character to be inserted */
|
|
6586 long count; /* Repeat this many times */
|
|
6587 int no_esc; /* Don't add an ESC at the end */
|
|
6588 {
|
|
6589 char_u *esc_ptr;
|
|
6590 char_u *ptr;
|
|
6591 char_u *last_ptr;
|
|
6592 char_u last = NUL;
|
|
6593
|
|
6594 ptr = get_last_insert();
|
|
6595 if (ptr == NULL)
|
|
6596 {
|
|
6597 EMSG(_(e_noinstext));
|
|
6598 return FAIL;
|
|
6599 }
|
|
6600
|
|
6601 /* may want to stuff the command character, to start Insert mode */
|
|
6602 if (c != NUL)
|
|
6603 stuffcharReadbuff(c);
|
|
6604 if ((esc_ptr = (char_u *)vim_strrchr(ptr, ESC)) != NULL)
|
|
6605 *esc_ptr = NUL; /* remove the ESC */
|
|
6606
|
|
6607 /* when the last char is either "0" or "^" it will be quoted if no ESC
|
|
6608 * comes after it OR if it will inserted more than once and "ptr"
|
|
6609 * starts with ^D. -- Acevedo
|
|
6610 */
|
|
6611 last_ptr = (esc_ptr ? esc_ptr : ptr + STRLEN(ptr)) - 1;
|
|
6612 if (last_ptr >= ptr && (*last_ptr == '0' || *last_ptr == '^')
|
|
6613 && (no_esc || (*ptr == Ctrl_D && count > 1)))
|
|
6614 {
|
|
6615 last = *last_ptr;
|
|
6616 *last_ptr = NUL;
|
|
6617 }
|
|
6618
|
|
6619 do
|
|
6620 {
|
|
6621 stuffReadbuff(ptr);
|
|
6622 /* a trailing "0" is inserted as "<C-V>048", "^" as "<C-V>^" */
|
|
6623 if (last)
|
|
6624 stuffReadbuff((char_u *)(last == '0'
|
|
6625 ? IF_EB("\026\060\064\070", CTRL_V_STR "xf0")
|
|
6626 : IF_EB("\026^", CTRL_V_STR "^")));
|
|
6627 }
|
|
6628 while (--count > 0);
|
|
6629
|
|
6630 if (last)
|
|
6631 *last_ptr = last;
|
|
6632
|
|
6633 if (esc_ptr != NULL)
|
|
6634 *esc_ptr = ESC; /* put the ESC back */
|
|
6635
|
|
6636 /* may want to stuff a trailing ESC, to get out of Insert mode */
|
|
6637 if (!no_esc)
|
|
6638 stuffcharReadbuff(ESC);
|
|
6639
|
|
6640 return OK;
|
|
6641 }
|
|
6642
|
|
6643 char_u *
|
|
6644 get_last_insert()
|
|
6645 {
|
|
6646 if (last_insert == NULL)
|
|
6647 return NULL;
|
|
6648 return last_insert + last_insert_skip;
|
|
6649 }
|
|
6650
|
|
6651 /*
|
|
6652 * Get last inserted string, and remove trailing <Esc>.
|
|
6653 * Returns pointer to allocated memory (must be freed) or NULL.
|
|
6654 */
|
|
6655 char_u *
|
|
6656 get_last_insert_save()
|
|
6657 {
|
|
6658 char_u *s;
|
|
6659 int len;
|
|
6660
|
|
6661 if (last_insert == NULL)
|
|
6662 return NULL;
|
|
6663 s = vim_strsave(last_insert + last_insert_skip);
|
|
6664 if (s != NULL)
|
|
6665 {
|
|
6666 len = (int)STRLEN(s);
|
|
6667 if (len > 0 && s[len - 1] == ESC) /* remove trailing ESC */
|
|
6668 s[len - 1] = NUL;
|
|
6669 }
|
|
6670 return s;
|
|
6671 }
|
|
6672
|
|
6673 /*
|
|
6674 * Check the word in front of the cursor for an abbreviation.
|
|
6675 * Called when the non-id character "c" has been entered.
|
|
6676 * When an abbreviation is recognized it is removed from the text and
|
|
6677 * the replacement string is inserted in typebuf.tb_buf[], followed by "c".
|
|
6678 */
|
|
6679 static int
|
|
6680 echeck_abbr(c)
|
|
6681 int c;
|
|
6682 {
|
|
6683 /* Don't check for abbreviation in paste mode, when disabled and just
|
|
6684 * after moving around with cursor keys. */
|
|
6685 if (p_paste || no_abbr || arrow_used)
|
|
6686 return FALSE;
|
|
6687
|
|
6688 return check_abbr(c, ml_get_curline(), curwin->w_cursor.col,
|
|
6689 curwin->w_cursor.lnum == Insstart.lnum ? Insstart.col : 0);
|
|
6690 }
|
|
6691
|
|
6692 /*
|
|
6693 * replace-stack functions
|
|
6694 *
|
|
6695 * When replacing characters, the replaced characters are remembered for each
|
|
6696 * new character. This is used to re-insert the old text when backspacing.
|
|
6697 *
|
|
6698 * There is a NUL headed list of characters for each character that is
|
|
6699 * currently in the file after the insertion point. When BS is used, one NUL
|
|
6700 * headed list is put back for the deleted character.
|
|
6701 *
|
|
6702 * For a newline, there are two NUL headed lists. One contains the characters
|
|
6703 * that the NL replaced. The extra one stores the characters after the cursor
|
|
6704 * that were deleted (always white space).
|
|
6705 *
|
|
6706 * Replace_offset is normally 0, in which case replace_push will add a new
|
|
6707 * character at the end of the stack. If replace_offset is not 0, that many
|
|
6708 * characters will be left on the stack above the newly inserted character.
|
|
6709 */
|
|
6710
|
298
|
6711 static char_u *replace_stack = NULL;
|
|
6712 static long replace_stack_nr = 0; /* next entry in replace stack */
|
|
6713 static long replace_stack_len = 0; /* max. number of entries */
|
7
|
6714
|
|
6715 void
|
|
6716 replace_push(c)
|
|
6717 int c; /* character that is replaced (NUL is none) */
|
|
6718 {
|
|
6719 char_u *p;
|
|
6720
|
|
6721 if (replace_stack_nr < replace_offset) /* nothing to do */
|
|
6722 return;
|
|
6723 if (replace_stack_len <= replace_stack_nr)
|
|
6724 {
|
|
6725 replace_stack_len += 50;
|
|
6726 p = lalloc(sizeof(char_u) * replace_stack_len, TRUE);
|
|
6727 if (p == NULL) /* out of memory */
|
|
6728 {
|
|
6729 replace_stack_len -= 50;
|
|
6730 return;
|
|
6731 }
|
|
6732 if (replace_stack != NULL)
|
|
6733 {
|
|
6734 mch_memmove(p, replace_stack,
|
|
6735 (size_t)(replace_stack_nr * sizeof(char_u)));
|
|
6736 vim_free(replace_stack);
|
|
6737 }
|
|
6738 replace_stack = p;
|
|
6739 }
|
|
6740 p = replace_stack + replace_stack_nr - replace_offset;
|
|
6741 if (replace_offset)
|
|
6742 mch_memmove(p + 1, p, (size_t)(replace_offset * sizeof(char_u)));
|
|
6743 *p = c;
|
|
6744 ++replace_stack_nr;
|
|
6745 }
|
|
6746
|
840
|
6747 #if 0
|
7
|
6748 /*
|
|
6749 * call replace_push(c) with replace_offset set to the first NUL.
|
|
6750 */
|
|
6751 static void
|
|
6752 replace_push_off(c)
|
|
6753 int c;
|
|
6754 {
|
|
6755 char_u *p;
|
|
6756
|
|
6757 p = replace_stack + replace_stack_nr;
|
|
6758 for (replace_offset = 1; replace_offset < replace_stack_nr;
|
|
6759 ++replace_offset)
|
|
6760 if (*--p == NUL)
|
|
6761 break;
|
|
6762 replace_push(c);
|
|
6763 replace_offset = 0;
|
|
6764 }
|
840
|
6765 #endif
|
7
|
6766
|
|
6767 /*
|
|
6768 * Pop one item from the replace stack.
|
|
6769 * return -1 if stack empty
|
|
6770 * return replaced character or NUL otherwise
|
|
6771 */
|
|
6772 static int
|
|
6773 replace_pop()
|
|
6774 {
|
|
6775 if (replace_stack_nr == 0)
|
|
6776 return -1;
|
|
6777 return (int)replace_stack[--replace_stack_nr];
|
|
6778 }
|
|
6779
|
|
6780 /*
|
|
6781 * Join the top two items on the replace stack. This removes to "off"'th NUL
|
|
6782 * encountered.
|
|
6783 */
|
|
6784 static void
|
|
6785 replace_join(off)
|
|
6786 int off; /* offset for which NUL to remove */
|
|
6787 {
|
|
6788 int i;
|
|
6789
|
|
6790 for (i = replace_stack_nr; --i >= 0; )
|
|
6791 if (replace_stack[i] == NUL && off-- <= 0)
|
|
6792 {
|
|
6793 --replace_stack_nr;
|
|
6794 mch_memmove(replace_stack + i, replace_stack + i + 1,
|
|
6795 (size_t)(replace_stack_nr - i));
|
|
6796 return;
|
|
6797 }
|
|
6798 }
|
|
6799
|
|
6800 /*
|
|
6801 * Pop bytes from the replace stack until a NUL is found, and insert them
|
|
6802 * before the cursor. Can only be used in REPLACE or VREPLACE mode.
|
|
6803 */
|
|
6804 static void
|
|
6805 replace_pop_ins()
|
|
6806 {
|
|
6807 int cc;
|
|
6808 int oldState = State;
|
|
6809
|
|
6810 State = NORMAL; /* don't want REPLACE here */
|
|
6811 while ((cc = replace_pop()) > 0)
|
|
6812 {
|
|
6813 #ifdef FEAT_MBYTE
|
|
6814 mb_replace_pop_ins(cc);
|
|
6815 #else
|
|
6816 ins_char(cc);
|
|
6817 #endif
|
|
6818 dec_cursor();
|
|
6819 }
|
|
6820 State = oldState;
|
|
6821 }
|
|
6822
|
|
6823 #ifdef FEAT_MBYTE
|
|
6824 /*
|
|
6825 * Insert bytes popped from the replace stack. "cc" is the first byte. If it
|
|
6826 * indicates a multi-byte char, pop the other bytes too.
|
|
6827 */
|
|
6828 static void
|
|
6829 mb_replace_pop_ins(cc)
|
|
6830 int cc;
|
|
6831 {
|
|
6832 int n;
|
|
6833 char_u buf[MB_MAXBYTES];
|
|
6834 int i;
|
|
6835 int c;
|
|
6836
|
|
6837 if (has_mbyte && (n = MB_BYTE2LEN(cc)) > 1)
|
|
6838 {
|
|
6839 buf[0] = cc;
|
|
6840 for (i = 1; i < n; ++i)
|
|
6841 buf[i] = replace_pop();
|
|
6842 ins_bytes_len(buf, n);
|
|
6843 }
|
|
6844 else
|
|
6845 ins_char(cc);
|
|
6846
|
|
6847 if (enc_utf8)
|
|
6848 /* Handle composing chars. */
|
|
6849 for (;;)
|
|
6850 {
|
|
6851 c = replace_pop();
|
|
6852 if (c == -1) /* stack empty */
|
|
6853 break;
|
|
6854 if ((n = MB_BYTE2LEN(c)) == 1)
|
|
6855 {
|
|
6856 /* Not a multi-byte char, put it back. */
|
|
6857 replace_push(c);
|
|
6858 break;
|
|
6859 }
|
|
6860 else
|
|
6861 {
|
|
6862 buf[0] = c;
|
|
6863 for (i = 1; i < n; ++i)
|
|
6864 buf[i] = replace_pop();
|
|
6865 if (utf_iscomposing(utf_ptr2char(buf)))
|
|
6866 ins_bytes_len(buf, n);
|
|
6867 else
|
|
6868 {
|
|
6869 /* Not a composing char, put it back. */
|
|
6870 for (i = n - 1; i >= 0; --i)
|
|
6871 replace_push(buf[i]);
|
|
6872 break;
|
|
6873 }
|
|
6874 }
|
|
6875 }
|
|
6876 }
|
|
6877 #endif
|
|
6878
|
|
6879 /*
|
|
6880 * make the replace stack empty
|
|
6881 * (called when exiting replace mode)
|
|
6882 */
|
|
6883 static void
|
|
6884 replace_flush()
|
|
6885 {
|
|
6886 vim_free(replace_stack);
|
|
6887 replace_stack = NULL;
|
|
6888 replace_stack_len = 0;
|
|
6889 replace_stack_nr = 0;
|
|
6890 }
|
|
6891
|
|
6892 /*
|
|
6893 * Handle doing a BS for one character.
|
|
6894 * cc < 0: replace stack empty, just move cursor
|
|
6895 * cc == 0: character was inserted, delete it
|
|
6896 * cc > 0: character was replaced, put cc (first byte of original char) back
|
|
6897 * and check for more characters to be put back
|
|
6898 */
|
|
6899 static void
|
|
6900 replace_do_bs()
|
|
6901 {
|
|
6902 int cc;
|
|
6903 #ifdef FEAT_VREPLACE
|
|
6904 int orig_len = 0;
|
|
6905 int ins_len;
|
|
6906 int orig_vcols = 0;
|
|
6907 colnr_T start_vcol;
|
|
6908 char_u *p;
|
|
6909 int i;
|
|
6910 int vcol;
|
|
6911 #endif
|
|
6912
|
|
6913 cc = replace_pop();
|
|
6914 if (cc > 0)
|
|
6915 {
|
|
6916 #ifdef FEAT_VREPLACE
|
|
6917 if (State & VREPLACE_FLAG)
|
|
6918 {
|
|
6919 /* Get the number of screen cells used by the character we are
|
|
6920 * going to delete. */
|
|
6921 getvcol(curwin, &curwin->w_cursor, NULL, &start_vcol, NULL);
|
|
6922 orig_vcols = chartabsize(ml_get_cursor(), start_vcol);
|
|
6923 }
|
|
6924 #endif
|
|
6925 #ifdef FEAT_MBYTE
|
|
6926 if (has_mbyte)
|
|
6927 {
|
|
6928 del_char(FALSE);
|
|
6929 # ifdef FEAT_VREPLACE
|
|
6930 if (State & VREPLACE_FLAG)
|
835
|
6931 orig_len = (int)STRLEN(ml_get_cursor());
|
7
|
6932 # endif
|
|
6933 replace_push(cc);
|
|
6934 }
|
|
6935 else
|
|
6936 #endif
|
|
6937 {
|
|
6938 pchar_cursor(cc);
|
|
6939 #ifdef FEAT_VREPLACE
|
|
6940 if (State & VREPLACE_FLAG)
|
835
|
6941 orig_len = (int)STRLEN(ml_get_cursor()) - 1;
|
7
|
6942 #endif
|
|
6943 }
|
|
6944 replace_pop_ins();
|
|
6945
|
|
6946 #ifdef FEAT_VREPLACE
|
|
6947 if (State & VREPLACE_FLAG)
|
|
6948 {
|
|
6949 /* Get the number of screen cells used by the inserted characters */
|
|
6950 p = ml_get_cursor();
|
835
|
6951 ins_len = (int)STRLEN(p) - orig_len;
|
7
|
6952 vcol = start_vcol;
|
|
6953 for (i = 0; i < ins_len; ++i)
|
|
6954 {
|
|
6955 vcol += chartabsize(p + i, vcol);
|
|
6956 #ifdef FEAT_MBYTE
|
474
|
6957 i += (*mb_ptr2len)(p) - 1;
|
7
|
6958 #endif
|
|
6959 }
|
|
6960 vcol -= start_vcol;
|
|
6961
|
|
6962 /* Delete spaces that were inserted after the cursor to keep the
|
|
6963 * text aligned. */
|
|
6964 curwin->w_cursor.col += ins_len;
|
|
6965 while (vcol > orig_vcols && gchar_cursor() == ' ')
|
|
6966 {
|
|
6967 del_char(FALSE);
|
|
6968 ++orig_vcols;
|
|
6969 }
|
|
6970 curwin->w_cursor.col -= ins_len;
|
|
6971 }
|
|
6972 #endif
|
|
6973
|
|
6974 /* mark the buffer as changed and prepare for displaying */
|
|
6975 changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col);
|
|
6976 }
|
|
6977 else if (cc == 0)
|
|
6978 (void)del_char(FALSE);
|
|
6979 }
|
|
6980
|
|
6981 #ifdef FEAT_CINDENT
|
|
6982 /*
|
|
6983 * Return TRUE if C-indenting is on.
|
|
6984 */
|
|
6985 static int
|
|
6986 cindent_on()
|
|
6987 {
|
|
6988 return (!p_paste && (curbuf->b_p_cin
|
|
6989 # ifdef FEAT_EVAL
|
|
6990 || *curbuf->b_p_inde != NUL
|
|
6991 # endif
|
|
6992 ));
|
|
6993 }
|
|
6994 #endif
|
|
6995
|
|
6996 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) || defined(PROTO)
|
|
6997 /*
|
|
6998 * Re-indent the current line, based on the current contents of it and the
|
|
6999 * surrounding lines. Fixing the cursor position seems really easy -- I'm very
|
|
7000 * confused what all the part that handles Control-T is doing that I'm not.
|
|
7001 * "get_the_indent" should be get_c_indent, get_expr_indent or get_lisp_indent.
|
|
7002 */
|
|
7003
|
|
7004 void
|
|
7005 fixthisline(get_the_indent)
|
|
7006 int (*get_the_indent) __ARGS((void));
|
|
7007 {
|
|
7008 change_indent(INDENT_SET, get_the_indent(), FALSE, 0);
|
|
7009 if (linewhite(curwin->w_cursor.lnum))
|
|
7010 did_ai = TRUE; /* delete the indent if the line stays empty */
|
|
7011 }
|
|
7012
|
|
7013 void
|
|
7014 fix_indent()
|
|
7015 {
|
|
7016 if (p_paste)
|
|
7017 return;
|
|
7018 # ifdef FEAT_LISP
|
|
7019 if (curbuf->b_p_lisp && curbuf->b_p_ai)
|
|
7020 fixthisline(get_lisp_indent);
|
|
7021 # endif
|
|
7022 # if defined(FEAT_LISP) && defined(FEAT_CINDENT)
|
|
7023 else
|
|
7024 # endif
|
|
7025 # ifdef FEAT_CINDENT
|
|
7026 if (cindent_on())
|
|
7027 do_c_expr_indent();
|
|
7028 # endif
|
|
7029 }
|
|
7030
|
|
7031 #endif
|
|
7032
|
|
7033 #ifdef FEAT_CINDENT
|
|
7034 /*
|
|
7035 * return TRUE if 'cinkeys' contains the key "keytyped",
|
|
7036 * when == '*': Only if key is preceded with '*' (indent before insert)
|
|
7037 * when == '!': Only if key is prededed with '!' (don't insert)
|
|
7038 * when == ' ': Only if key is not preceded with '*'(indent afterwards)
|
|
7039 *
|
|
7040 * "keytyped" can have a few special values:
|
|
7041 * KEY_OPEN_FORW
|
|
7042 * KEY_OPEN_BACK
|
|
7043 * KEY_COMPLETE just finished completion.
|
|
7044 *
|
|
7045 * If line_is_empty is TRUE accept keys with '0' before them.
|
|
7046 */
|
|
7047 int
|
|
7048 in_cinkeys(keytyped, when, line_is_empty)
|
|
7049 int keytyped;
|
|
7050 int when;
|
|
7051 int line_is_empty;
|
|
7052 {
|
|
7053 char_u *look;
|
|
7054 int try_match;
|
|
7055 int try_match_word;
|
|
7056 char_u *p;
|
|
7057 char_u *line;
|
|
7058 int icase;
|
|
7059 int i;
|
|
7060
|
|
7061 #ifdef FEAT_EVAL
|
|
7062 if (*curbuf->b_p_inde != NUL)
|
|
7063 look = curbuf->b_p_indk; /* 'indentexpr' set: use 'indentkeys' */
|
|
7064 else
|
|
7065 #endif
|
|
7066 look = curbuf->b_p_cink; /* 'indentexpr' empty: use 'cinkeys' */
|
|
7067 while (*look)
|
|
7068 {
|
|
7069 /*
|
|
7070 * Find out if we want to try a match with this key, depending on
|
|
7071 * 'when' and a '*' or '!' before the key.
|
|
7072 */
|
|
7073 switch (when)
|
|
7074 {
|
|
7075 case '*': try_match = (*look == '*'); break;
|
|
7076 case '!': try_match = (*look == '!'); break;
|
|
7077 default: try_match = (*look != '*'); break;
|
|
7078 }
|
|
7079 if (*look == '*' || *look == '!')
|
|
7080 ++look;
|
|
7081
|
|
7082 /*
|
|
7083 * If there is a '0', only accept a match if the line is empty.
|
|
7084 * But may still match when typing last char of a word.
|
|
7085 */
|
|
7086 if (*look == '0')
|
|
7087 {
|
|
7088 try_match_word = try_match;
|
|
7089 if (!line_is_empty)
|
|
7090 try_match = FALSE;
|
|
7091 ++look;
|
|
7092 }
|
|
7093 else
|
|
7094 try_match_word = FALSE;
|
|
7095
|
|
7096 /*
|
|
7097 * does it look like a control character?
|
|
7098 */
|
|
7099 if (*look == '^'
|
|
7100 #ifdef EBCDIC
|
|
7101 && (Ctrl_chr(look[1]) != 0)
|
|
7102 #else
|
|
7103 && look[1] >= '?' && look[1] <= '_'
|
|
7104 #endif
|
|
7105 )
|
|
7106 {
|
|
7107 if (try_match && keytyped == Ctrl_chr(look[1]))
|
|
7108 return TRUE;
|
|
7109 look += 2;
|
|
7110 }
|
|
7111 /*
|
|
7112 * 'o' means "o" command, open forward.
|
|
7113 * 'O' means "O" command, open backward.
|
|
7114 */
|
|
7115 else if (*look == 'o')
|
|
7116 {
|
|
7117 if (try_match && keytyped == KEY_OPEN_FORW)
|
|
7118 return TRUE;
|
|
7119 ++look;
|
|
7120 }
|
|
7121 else if (*look == 'O')
|
|
7122 {
|
|
7123 if (try_match && keytyped == KEY_OPEN_BACK)
|
|
7124 return TRUE;
|
|
7125 ++look;
|
|
7126 }
|
|
7127
|
|
7128 /*
|
|
7129 * 'e' means to check for "else" at start of line and just before the
|
|
7130 * cursor.
|
|
7131 */
|
|
7132 else if (*look == 'e')
|
|
7133 {
|
|
7134 if (try_match && keytyped == 'e' && curwin->w_cursor.col >= 4)
|
|
7135 {
|
|
7136 p = ml_get_curline();
|
|
7137 if (skipwhite(p) == p + curwin->w_cursor.col - 4 &&
|
|
7138 STRNCMP(p + curwin->w_cursor.col - 4, "else", 4) == 0)
|
|
7139 return TRUE;
|
|
7140 }
|
|
7141 ++look;
|
|
7142 }
|
|
7143
|
|
7144 /*
|
|
7145 * ':' only causes an indent if it is at the end of a label or case
|
|
7146 * statement, or when it was before typing the ':' (to fix
|
|
7147 * class::method for C++).
|
|
7148 */
|
|
7149 else if (*look == ':')
|
|
7150 {
|
|
7151 if (try_match && keytyped == ':')
|
|
7152 {
|
|
7153 p = ml_get_curline();
|
|
7154 if (cin_iscase(p) || cin_isscopedecl(p) || cin_islabel(30))
|
|
7155 return TRUE;
|
|
7156 if (curwin->w_cursor.col > 2
|
|
7157 && p[curwin->w_cursor.col - 1] == ':'
|
|
7158 && p[curwin->w_cursor.col - 2] == ':')
|
|
7159 {
|
|
7160 p[curwin->w_cursor.col - 1] = ' ';
|
|
7161 i = (cin_iscase(p) || cin_isscopedecl(p)
|
|
7162 || cin_islabel(30));
|
|
7163 p = ml_get_curline();
|
|
7164 p[curwin->w_cursor.col - 1] = ':';
|
|
7165 if (i)
|
|
7166 return TRUE;
|
|
7167 }
|
|
7168 }
|
|
7169 ++look;
|
|
7170 }
|
|
7171
|
|
7172
|
|
7173 /*
|
|
7174 * Is it a key in <>, maybe?
|
|
7175 */
|
|
7176 else if (*look == '<')
|
|
7177 {
|
|
7178 if (try_match)
|
|
7179 {
|
|
7180 /*
|
|
7181 * make up some named keys <o>, <O>, <e>, <0>, <>>, <<>, <*>,
|
|
7182 * <:> and <!> so that people can re-indent on o, O, e, 0, <,
|
|
7183 * >, *, : and ! keys if they really really want to.
|
|
7184 */
|
|
7185 if (vim_strchr((char_u *)"<>!*oOe0:", look[1]) != NULL
|
|
7186 && keytyped == look[1])
|
|
7187 return TRUE;
|
|
7188
|
|
7189 if (keytyped == get_special_key_code(look + 1))
|
|
7190 return TRUE;
|
|
7191 }
|
|
7192 while (*look && *look != '>')
|
|
7193 look++;
|
|
7194 while (*look == '>')
|
|
7195 look++;
|
|
7196 }
|
|
7197
|
|
7198 /*
|
|
7199 * Is it a word: "=word"?
|
|
7200 */
|
|
7201 else if (*look == '=' && look[1] != ',' && look[1] != NUL)
|
|
7202 {
|
|
7203 ++look;
|
|
7204 if (*look == '~')
|
|
7205 {
|
|
7206 icase = TRUE;
|
|
7207 ++look;
|
|
7208 }
|
|
7209 else
|
|
7210 icase = FALSE;
|
|
7211 p = vim_strchr(look, ',');
|
|
7212 if (p == NULL)
|
|
7213 p = look + STRLEN(look);
|
|
7214 if ((try_match || try_match_word)
|
|
7215 && curwin->w_cursor.col >= (colnr_T)(p - look))
|
|
7216 {
|
|
7217 int match = FALSE;
|
|
7218
|
|
7219 #ifdef FEAT_INS_EXPAND
|
|
7220 if (keytyped == KEY_COMPLETE)
|
|
7221 {
|
|
7222 char_u *s;
|
|
7223
|
|
7224 /* Just completed a word, check if it starts with "look".
|
|
7225 * search back for the start of a word. */
|
|
7226 line = ml_get_curline();
|
|
7227 # ifdef FEAT_MBYTE
|
|
7228 if (has_mbyte)
|
|
7229 {
|
|
7230 char_u *n;
|
|
7231
|
|
7232 for (s = line + curwin->w_cursor.col; s > line; s = n)
|
|
7233 {
|
|
7234 n = mb_prevptr(line, s);
|
|
7235 if (!vim_iswordp(n))
|
|
7236 break;
|
|
7237 }
|
|
7238 }
|
|
7239 else
|
|
7240 # endif
|
|
7241 for (s = line + curwin->w_cursor.col; s > line; --s)
|
|
7242 if (!vim_iswordc(s[-1]))
|
|
7243 break;
|
|
7244 if (s + (p - look) <= line + curwin->w_cursor.col
|
|
7245 && (icase
|
|
7246 ? MB_STRNICMP(s, look, p - look)
|
|
7247 : STRNCMP(s, look, p - look)) == 0)
|
|
7248 match = TRUE;
|
|
7249 }
|
|
7250 else
|
|
7251 #endif
|
|
7252 /* TODO: multi-byte */
|
|
7253 if (keytyped == (int)p[-1] || (icase && keytyped < 256
|
|
7254 && TOLOWER_LOC(keytyped) == TOLOWER_LOC((int)p[-1])))
|
|
7255 {
|
|
7256 line = ml_get_cursor();
|
|
7257 if ((curwin->w_cursor.col == (colnr_T)(p - look)
|
|
7258 || !vim_iswordc(line[-(p - look) - 1]))
|
|
7259 && (icase
|
|
7260 ? MB_STRNICMP(line - (p - look), look, p - look)
|
|
7261 : STRNCMP(line - (p - look), look, p - look))
|
|
7262 == 0)
|
|
7263 match = TRUE;
|
|
7264 }
|
|
7265 if (match && try_match_word && !try_match)
|
|
7266 {
|
|
7267 /* "0=word": Check if there are only blanks before the
|
|
7268 * word. */
|
|
7269 line = ml_get_curline();
|
|
7270 if ((int)(skipwhite(line) - line) !=
|
|
7271 (int)(curwin->w_cursor.col - (p - look)))
|
|
7272 match = FALSE;
|
|
7273 }
|
|
7274 if (match)
|
|
7275 return TRUE;
|
|
7276 }
|
|
7277 look = p;
|
|
7278 }
|
|
7279
|
|
7280 /*
|
|
7281 * ok, it's a boring generic character.
|
|
7282 */
|
|
7283 else
|
|
7284 {
|
|
7285 if (try_match && *look == keytyped)
|
|
7286 return TRUE;
|
|
7287 ++look;
|
|
7288 }
|
|
7289
|
|
7290 /*
|
|
7291 * Skip over ", ".
|
|
7292 */
|
|
7293 look = skip_to_option_part(look);
|
|
7294 }
|
|
7295 return FALSE;
|
|
7296 }
|
|
7297 #endif /* FEAT_CINDENT */
|
|
7298
|
|
7299 #if defined(FEAT_RIGHTLEFT) || defined(PROTO)
|
|
7300 /*
|
|
7301 * Map Hebrew keyboard when in hkmap mode.
|
|
7302 */
|
|
7303 int
|
|
7304 hkmap(c)
|
|
7305 int c;
|
|
7306 {
|
|
7307 if (p_hkmapp) /* phonetic mapping, by Ilya Dogolazky */
|
|
7308 {
|
|
7309 enum {hALEF=0, BET, GIMEL, DALET, HEI, VAV, ZAIN, HET, TET, IUD,
|
|
7310 KAFsofit, hKAF, LAMED, MEMsofit, MEM, NUNsofit, NUN, SAMEH, AIN,
|
|
7311 PEIsofit, PEI, ZADIsofit, ZADI, KOF, RESH, hSHIN, TAV};
|
|
7312 static char_u map[26] =
|
|
7313 {(char_u)hALEF/*a*/, (char_u)BET /*b*/, (char_u)hKAF /*c*/,
|
|
7314 (char_u)DALET/*d*/, (char_u)-1 /*e*/, (char_u)PEIsofit/*f*/,
|
|
7315 (char_u)GIMEL/*g*/, (char_u)HEI /*h*/, (char_u)IUD /*i*/,
|
|
7316 (char_u)HET /*j*/, (char_u)KOF /*k*/, (char_u)LAMED /*l*/,
|
|
7317 (char_u)MEM /*m*/, (char_u)NUN /*n*/, (char_u)SAMEH /*o*/,
|
|
7318 (char_u)PEI /*p*/, (char_u)-1 /*q*/, (char_u)RESH /*r*/,
|
|
7319 (char_u)ZAIN /*s*/, (char_u)TAV /*t*/, (char_u)TET /*u*/,
|
|
7320 (char_u)VAV /*v*/, (char_u)hSHIN/*w*/, (char_u)-1 /*x*/,
|
|
7321 (char_u)AIN /*y*/, (char_u)ZADI /*z*/};
|
|
7322
|
|
7323 if (c == 'N' || c == 'M' || c == 'P' || c == 'C' || c == 'Z')
|
|
7324 return (int)(map[CharOrd(c)] - 1 + p_aleph);
|
|
7325 /* '-1'='sofit' */
|
|
7326 else if (c == 'x')
|
|
7327 return 'X';
|
|
7328 else if (c == 'q')
|
|
7329 return '\''; /* {geresh}={'} */
|
|
7330 else if (c == 246)
|
|
7331 return ' '; /* \"o --> ' ' for a german keyboard */
|
|
7332 else if (c == 228)
|
|
7333 return ' '; /* \"a --> ' ' -- / -- */
|
|
7334 else if (c == 252)
|
|
7335 return ' '; /* \"u --> ' ' -- / -- */
|
|
7336 #ifdef EBCDIC
|
|
7337 else if (islower(c))
|
|
7338 #else
|
|
7339 /* NOTE: islower() does not do the right thing for us on Linux so we
|
|
7340 * do this the same was as 5.7 and previous, so it works correctly on
|
|
7341 * all systems. Specifically, the e.g. Delete and Arrow keys are
|
|
7342 * munged and won't work if e.g. searching for Hebrew text.
|
|
7343 */
|
|
7344 else if (c >= 'a' && c <= 'z')
|
|
7345 #endif
|
|
7346 return (int)(map[CharOrdLow(c)] + p_aleph);
|
|
7347 else
|
|
7348 return c;
|
|
7349 }
|
|
7350 else
|
|
7351 {
|
|
7352 switch (c)
|
|
7353 {
|
|
7354 case '`': return ';';
|
|
7355 case '/': return '.';
|
|
7356 case '\'': return ',';
|
|
7357 case 'q': return '/';
|
|
7358 case 'w': return '\'';
|
|
7359
|
|
7360 /* Hebrew letters - set offset from 'a' */
|
|
7361 case ',': c = '{'; break;
|
|
7362 case '.': c = 'v'; break;
|
|
7363 case ';': c = 't'; break;
|
|
7364 default: {
|
|
7365 static char str[] = "zqbcxlsjphmkwonu ydafe rig";
|
|
7366
|
|
7367 #ifdef EBCDIC
|
|
7368 /* see note about islower() above */
|
|
7369 if (!islower(c))
|
|
7370 #else
|
|
7371 if (c < 'a' || c > 'z')
|
|
7372 #endif
|
|
7373 return c;
|
|
7374 c = str[CharOrdLow(c)];
|
|
7375 break;
|
|
7376 }
|
|
7377 }
|
|
7378
|
|
7379 return (int)(CharOrdLow(c) + p_aleph);
|
|
7380 }
|
|
7381 }
|
|
7382 #endif
|
|
7383
|
|
7384 static void
|
|
7385 ins_reg()
|
|
7386 {
|
|
7387 int need_redraw = FALSE;
|
|
7388 int regname;
|
|
7389 int literally = 0;
|
844
|
7390 #ifdef FEAT_VISUAL
|
|
7391 int vis_active = VIsual_active;
|
|
7392 #endif
|
7
|
7393
|
|
7394 /*
|
|
7395 * If we are going to wait for a character, show a '"'.
|
|
7396 */
|
|
7397 pc_status = PC_STATUS_UNSET;
|
|
7398 if (redrawing() && !char_avail())
|
|
7399 {
|
|
7400 /* may need to redraw when no more chars available now */
|
661
|
7401 ins_redraw(FALSE);
|
7
|
7402
|
|
7403 edit_putchar('"', TRUE);
|
|
7404 #ifdef FEAT_CMDL_INFO
|
|
7405 add_to_showcmd_c(Ctrl_R);
|
|
7406 #endif
|
|
7407 }
|
|
7408
|
|
7409 #ifdef USE_ON_FLY_SCROLL
|
|
7410 dont_scroll = TRUE; /* disallow scrolling here */
|
|
7411 #endif
|
|
7412
|
|
7413 /*
|
|
7414 * Don't map the register name. This also prevents the mode message to be
|
|
7415 * deleted when ESC is hit.
|
|
7416 */
|
|
7417 ++no_mapping;
|
|
7418 regname = safe_vgetc();
|
|
7419 #ifdef FEAT_LANGMAP
|
|
7420 LANGMAP_ADJUST(regname, TRUE);
|
|
7421 #endif
|
|
7422 if (regname == Ctrl_R || regname == Ctrl_O || regname == Ctrl_P)
|
|
7423 {
|
|
7424 /* Get a third key for literal register insertion */
|
|
7425 literally = regname;
|
|
7426 #ifdef FEAT_CMDL_INFO
|
|
7427 add_to_showcmd_c(literally);
|
|
7428 #endif
|
|
7429 regname = safe_vgetc();
|
|
7430 #ifdef FEAT_LANGMAP
|
|
7431 LANGMAP_ADJUST(regname, TRUE);
|
|
7432 #endif
|
|
7433 }
|
|
7434 --no_mapping;
|
|
7435
|
|
7436 #ifdef FEAT_EVAL
|
|
7437 /*
|
|
7438 * Don't call u_sync() while getting the expression,
|
|
7439 * evaluating it or giving an error message for it!
|
|
7440 */
|
|
7441 ++no_u_sync;
|
|
7442 if (regname == '=')
|
|
7443 {
|
133
|
7444 # ifdef USE_IM_CONTROL
|
7
|
7445 int im_on = im_get_status();
|
133
|
7446 # endif
|
7
|
7447 regname = get_expr_register();
|
133
|
7448 # ifdef USE_IM_CONTROL
|
7
|
7449 /* Restore the Input Method. */
|
|
7450 if (im_on)
|
|
7451 im_set_active(TRUE);
|
133
|
7452 # endif
|
7
|
7453 }
|
140
|
7454 if (regname == NUL || !valid_yank_reg(regname, FALSE))
|
|
7455 {
|
|
7456 vim_beep();
|
7
|
7457 need_redraw = TRUE; /* remove the '"' */
|
140
|
7458 }
|
7
|
7459 else
|
|
7460 {
|
|
7461 #endif
|
|
7462 if (literally == Ctrl_O || literally == Ctrl_P)
|
|
7463 {
|
|
7464 /* Append the command to the redo buffer. */
|
|
7465 AppendCharToRedobuff(Ctrl_R);
|
|
7466 AppendCharToRedobuff(literally);
|
|
7467 AppendCharToRedobuff(regname);
|
|
7468
|
|
7469 do_put(regname, BACKWARD, 1L,
|
|
7470 (literally == Ctrl_P ? PUT_FIXINDENT : 0) | PUT_CURSEND);
|
|
7471 }
|
|
7472 else if (insert_reg(regname, literally) == FAIL)
|
|
7473 {
|
|
7474 vim_beep();
|
|
7475 need_redraw = TRUE; /* remove the '"' */
|
|
7476 }
|
133
|
7477 else if (stop_insert_mode)
|
|
7478 /* When the '=' register was used and a function was invoked that
|
|
7479 * did ":stopinsert" then stuff_empty() returns FALSE but we won't
|
|
7480 * insert anything, need to remove the '"' */
|
|
7481 need_redraw = TRUE;
|
|
7482
|
7
|
7483 #ifdef FEAT_EVAL
|
|
7484 }
|
|
7485 --no_u_sync;
|
|
7486 #endif
|
|
7487 #ifdef FEAT_CMDL_INFO
|
|
7488 clear_showcmd();
|
|
7489 #endif
|
|
7490
|
|
7491 /* If the inserted register is empty, we need to remove the '"' */
|
|
7492 if (need_redraw || stuff_empty())
|
|
7493 edit_unputchar();
|
844
|
7494
|
|
7495 #ifdef FEAT_VISUAL
|
|
7496 /* Disallow starting Visual mode here, would get a weird mode. */
|
|
7497 if (!vis_active && VIsual_active)
|
|
7498 end_visual_mode();
|
|
7499 #endif
|
7
|
7500 }
|
|
7501
|
|
7502 /*
|
|
7503 * CTRL-G commands in Insert mode.
|
|
7504 */
|
|
7505 static void
|
|
7506 ins_ctrl_g()
|
|
7507 {
|
|
7508 int c;
|
|
7509
|
|
7510 #ifdef FEAT_INS_EXPAND
|
|
7511 /* Right after CTRL-X the cursor will be after the ruler. */
|
|
7512 setcursor();
|
|
7513 #endif
|
|
7514
|
|
7515 /*
|
|
7516 * Don't map the second key. This also prevents the mode message to be
|
|
7517 * deleted when ESC is hit.
|
|
7518 */
|
|
7519 ++no_mapping;
|
|
7520 c = safe_vgetc();
|
|
7521 --no_mapping;
|
|
7522 switch (c)
|
|
7523 {
|
|
7524 /* CTRL-G k and CTRL-G <Up>: cursor up to Insstart.col */
|
|
7525 case K_UP:
|
|
7526 case Ctrl_K:
|
|
7527 case 'k': ins_up(TRUE);
|
|
7528 break;
|
|
7529
|
|
7530 /* CTRL-G j and CTRL-G <Down>: cursor down to Insstart.col */
|
|
7531 case K_DOWN:
|
|
7532 case Ctrl_J:
|
|
7533 case 'j': ins_down(TRUE);
|
|
7534 break;
|
|
7535
|
|
7536 /* CTRL-G u: start new undoable edit */
|
825
|
7537 case 'u': u_sync(TRUE);
|
7
|
7538 ins_need_undo = TRUE;
|
626
|
7539
|
|
7540 /* Need to reset Insstart, esp. because a BS that joins
|
|
7541 * aline to the previous one must save for undo. */
|
|
7542 Insstart = curwin->w_cursor;
|
7
|
7543 break;
|
|
7544
|
|
7545 /* Unknown CTRL-G command, reserved for future expansion. */
|
|
7546 default: vim_beep();
|
|
7547 }
|
|
7548 }
|
|
7549
|
|
7550 /*
|
449
|
7551 * CTRL-^ in Insert mode.
|
|
7552 */
|
|
7553 static void
|
|
7554 ins_ctrl_hat()
|
|
7555 {
|
782
|
7556 if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE))
|
449
|
7557 {
|
|
7558 /* ":lmap" mappings exists, Toggle use of ":lmap" mappings. */
|
|
7559 if (State & LANGMAP)
|
|
7560 {
|
|
7561 curbuf->b_p_iminsert = B_IMODE_NONE;
|
|
7562 State &= ~LANGMAP;
|
|
7563 }
|
|
7564 else
|
|
7565 {
|
|
7566 curbuf->b_p_iminsert = B_IMODE_LMAP;
|
|
7567 State |= LANGMAP;
|
|
7568 #ifdef USE_IM_CONTROL
|
|
7569 im_set_active(FALSE);
|
|
7570 #endif
|
|
7571 }
|
|
7572 }
|
|
7573 #ifdef USE_IM_CONTROL
|
|
7574 else
|
|
7575 {
|
|
7576 /* There are no ":lmap" mappings, toggle IM */
|
|
7577 if (im_get_status())
|
|
7578 {
|
|
7579 curbuf->b_p_iminsert = B_IMODE_NONE;
|
|
7580 im_set_active(FALSE);
|
|
7581 }
|
|
7582 else
|
|
7583 {
|
|
7584 curbuf->b_p_iminsert = B_IMODE_IM;
|
|
7585 State &= ~LANGMAP;
|
|
7586 im_set_active(TRUE);
|
|
7587 }
|
|
7588 }
|
|
7589 #endif
|
|
7590 set_iminsert_global();
|
|
7591 showmode();
|
|
7592 #ifdef FEAT_GUI
|
|
7593 /* may show different cursor shape or color */
|
|
7594 if (gui.in_use)
|
|
7595 gui_update_cursor(TRUE, FALSE);
|
|
7596 #endif
|
|
7597 #if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
|
|
7598 /* Show/unshow value of 'keymap' in status lines. */
|
|
7599 status_redraw_curbuf();
|
|
7600 #endif
|
|
7601 }
|
|
7602
|
|
7603 /*
|
7
|
7604 * Handle ESC in insert mode.
|
|
7605 * Returns TRUE when leaving insert mode, FALSE when going to repeat the
|
|
7606 * insert.
|
|
7607 */
|
|
7608 static int
|
477
|
7609 ins_esc(count, cmdchar, nomove)
|
7
|
7610 long *count;
|
|
7611 int cmdchar;
|
477
|
7612 int nomove; /* don't move cursor */
|
7
|
7613 {
|
|
7614 int temp;
|
|
7615 static int disabled_redraw = FALSE;
|
|
7616
|
744
|
7617 #ifdef FEAT_SPELL
|
449
|
7618 check_spell_redraw();
|
|
7619 #endif
|
7
|
7620 #if defined(FEAT_HANGULIN)
|
|
7621 # if defined(ESC_CHG_TO_ENG_MODE)
|
|
7622 hangul_input_state_set(0);
|
|
7623 # endif
|
|
7624 if (composing_hangul)
|
|
7625 {
|
|
7626 push_raw_key(composing_hangul_buffer, 2);
|
|
7627 composing_hangul = 0;
|
|
7628 }
|
|
7629 #endif
|
|
7630
|
|
7631 temp = curwin->w_cursor.col;
|
|
7632 if (disabled_redraw)
|
|
7633 {
|
|
7634 --RedrawingDisabled;
|
|
7635 disabled_redraw = FALSE;
|
|
7636 }
|
|
7637 if (!arrow_used)
|
|
7638 {
|
|
7639 /*
|
|
7640 * Don't append the ESC for "r<CR>" and "grx".
|
75
|
7641 * When 'insertmode' is set only CTRL-L stops Insert mode. Needed for
|
|
7642 * when "count" is non-zero.
|
7
|
7643 */
|
|
7644 if (cmdchar != 'r' && cmdchar != 'v')
|
75
|
7645 AppendToRedobuff(p_im ? (char_u *)"\014" : ESC_STR);
|
7
|
7646
|
|
7647 /*
|
|
7648 * Repeating insert may take a long time. Check for
|
|
7649 * interrupt now and then.
|
|
7650 */
|
|
7651 if (*count > 0)
|
|
7652 {
|
|
7653 line_breakcheck();
|
|
7654 if (got_int)
|
|
7655 *count = 0;
|
|
7656 }
|
|
7657
|
|
7658 if (--*count > 0) /* repeat what was typed */
|
|
7659 {
|
164
|
7660 /* Vi repeats the insert without replacing characters. */
|
|
7661 if (vim_strchr(p_cpo, CPO_REPLCNT) != NULL)
|
|
7662 State &= ~REPLACE_FLAG;
|
|
7663
|
7
|
7664 (void)start_redo_ins();
|
|
7665 if (cmdchar == 'r' || cmdchar == 'v')
|
|
7666 stuffReadbuff(ESC_STR); /* no ESC in redo buffer */
|
|
7667 ++RedrawingDisabled;
|
|
7668 disabled_redraw = TRUE;
|
|
7669 return FALSE; /* repeat the insert */
|
|
7670 }
|
|
7671 stop_insert(&curwin->w_cursor, TRUE);
|
|
7672 undisplay_dollar();
|
|
7673 }
|
|
7674
|
|
7675 /* When an autoindent was removed, curswant stays after the
|
|
7676 * indent */
|
|
7677 if (restart_edit == NUL && (colnr_T)temp == curwin->w_cursor.col)
|
|
7678 curwin->w_set_curswant = TRUE;
|
|
7679
|
|
7680 /* Remember the last Insert position in the '^ mark. */
|
|
7681 if (!cmdmod.keepjumps)
|
|
7682 curbuf->b_last_insert = curwin->w_cursor;
|
|
7683
|
|
7684 /*
|
|
7685 * The cursor should end up on the last inserted character.
|
477
|
7686 * Don't do it for CTRL-O, unless past the end of the line.
|
7
|
7687 */
|
477
|
7688 if (!nomove
|
|
7689 && (curwin->w_cursor.col != 0
|
7
|
7690 #ifdef FEAT_VIRTUALEDIT
|
|
7691 || curwin->w_cursor.coladd > 0
|
|
7692 #endif
|
477
|
7693 )
|
|
7694 && (restart_edit == NUL
|
|
7695 || (gchar_cursor() == NUL
|
7
|
7696 #ifdef FEAT_VISUAL
|
477
|
7697 && !VIsual_active
|
|
7698 #endif
|
|
7699 ))
|
7
|
7700 #ifdef FEAT_RIGHTLEFT
|
|
7701 && !revins_on
|
|
7702 #endif
|
|
7703 )
|
|
7704 {
|
|
7705 #ifdef FEAT_VIRTUALEDIT
|
|
7706 if (curwin->w_cursor.coladd > 0 || ve_flags == VE_ALL)
|
|
7707 {
|
|
7708 oneleft();
|
|
7709 if (restart_edit != NUL)
|
|
7710 ++curwin->w_cursor.coladd;
|
|
7711 }
|
|
7712 else
|
|
7713 #endif
|
|
7714 {
|
|
7715 --curwin->w_cursor.col;
|
|
7716 #ifdef FEAT_MBYTE
|
|
7717 /* Correct cursor for multi-byte character. */
|
|
7718 if (has_mbyte)
|
|
7719 mb_adjust_cursor();
|
|
7720 #endif
|
|
7721 }
|
|
7722 }
|
|
7723
|
|
7724 #ifdef USE_IM_CONTROL
|
|
7725 /* Disable IM to allow typing English directly for Normal mode commands.
|
|
7726 * When ":lmap" is enabled don't change 'iminsert' (IM can be enabled as
|
|
7727 * well). */
|
|
7728 if (!(State & LANGMAP))
|
|
7729 im_save_status(&curbuf->b_p_iminsert);
|
|
7730 im_set_active(FALSE);
|
|
7731 #endif
|
|
7732
|
|
7733 State = NORMAL;
|
|
7734 /* need to position cursor again (e.g. when on a TAB ) */
|
|
7735 changed_cline_bef_curs();
|
|
7736
|
|
7737 #ifdef FEAT_MOUSE
|
|
7738 setmouse();
|
|
7739 #endif
|
|
7740 #ifdef CURSOR_SHAPE
|
|
7741 ui_cursor_shape(); /* may show different cursor shape */
|
|
7742 #endif
|
|
7743
|
|
7744 /*
|
|
7745 * When recording or for CTRL-O, need to display the new mode.
|
|
7746 * Otherwise remove the mode message.
|
|
7747 */
|
|
7748 if (Recording || restart_edit != NUL)
|
|
7749 showmode();
|
|
7750 else if (p_smd)
|
|
7751 MSG("");
|
|
7752
|
|
7753 return TRUE; /* exit Insert mode */
|
|
7754 }
|
|
7755
|
|
7756 #ifdef FEAT_RIGHTLEFT
|
|
7757 /*
|
|
7758 * Toggle language: hkmap and revins_on.
|
|
7759 * Move to end of reverse inserted text.
|
|
7760 */
|
|
7761 static void
|
|
7762 ins_ctrl_()
|
|
7763 {
|
|
7764 if (revins_on && revins_chars && revins_scol >= 0)
|
|
7765 {
|
|
7766 while (gchar_cursor() != NUL && revins_chars--)
|
|
7767 ++curwin->w_cursor.col;
|
|
7768 }
|
|
7769 p_ri = !p_ri;
|
|
7770 revins_on = (State == INSERT && p_ri);
|
|
7771 if (revins_on)
|
|
7772 {
|
|
7773 revins_scol = curwin->w_cursor.col;
|
|
7774 revins_legal++;
|
|
7775 revins_chars = 0;
|
|
7776 undisplay_dollar();
|
|
7777 }
|
|
7778 else
|
|
7779 revins_scol = -1;
|
|
7780 #ifdef FEAT_FKMAP
|
|
7781 if (p_altkeymap)
|
|
7782 {
|
|
7783 /*
|
|
7784 * to be consistent also for redo command, using '.'
|
|
7785 * set arrow_used to true and stop it - causing to redo
|
|
7786 * characters entered in one mode (normal/reverse insert).
|
|
7787 */
|
|
7788 arrow_used = TRUE;
|
|
7789 (void)stop_arrow();
|
|
7790 p_fkmap = curwin->w_p_rl ^ p_ri;
|
|
7791 if (p_fkmap && p_ri)
|
|
7792 State = INSERT;
|
|
7793 }
|
|
7794 else
|
|
7795 #endif
|
|
7796 p_hkmap = curwin->w_p_rl ^ p_ri; /* be consistent! */
|
|
7797 showmode();
|
|
7798 }
|
|
7799 #endif
|
|
7800
|
|
7801 #ifdef FEAT_VISUAL
|
|
7802 /*
|
|
7803 * If 'keymodel' contains "startsel", may start selection.
|
|
7804 * Returns TRUE when a CTRL-O and other keys stuffed.
|
|
7805 */
|
|
7806 static int
|
|
7807 ins_start_select(c)
|
|
7808 int c;
|
|
7809 {
|
|
7810 if (km_startsel)
|
|
7811 switch (c)
|
|
7812 {
|
|
7813 case K_KHOME:
|
|
7814 case K_KEND:
|
|
7815 case K_PAGEUP:
|
|
7816 case K_KPAGEUP:
|
|
7817 case K_PAGEDOWN:
|
|
7818 case K_KPAGEDOWN:
|
|
7819 # ifdef MACOS
|
|
7820 case K_LEFT:
|
|
7821 case K_RIGHT:
|
|
7822 case K_UP:
|
|
7823 case K_DOWN:
|
|
7824 case K_END:
|
|
7825 case K_HOME:
|
|
7826 # endif
|
|
7827 if (!(mod_mask & MOD_MASK_SHIFT))
|
|
7828 break;
|
|
7829 /* FALLTHROUGH */
|
|
7830 case K_S_LEFT:
|
|
7831 case K_S_RIGHT:
|
|
7832 case K_S_UP:
|
|
7833 case K_S_DOWN:
|
|
7834 case K_S_END:
|
|
7835 case K_S_HOME:
|
|
7836 /* Start selection right away, the cursor can move with
|
|
7837 * CTRL-O when beyond the end of the line. */
|
|
7838 start_selection();
|
|
7839
|
|
7840 /* Execute the key in (insert) Select mode. */
|
|
7841 stuffcharReadbuff(Ctrl_O);
|
|
7842 if (mod_mask)
|
|
7843 {
|
|
7844 char_u buf[4];
|
|
7845
|
|
7846 buf[0] = K_SPECIAL;
|
|
7847 buf[1] = KS_MODIFIER;
|
|
7848 buf[2] = mod_mask;
|
|
7849 buf[3] = NUL;
|
|
7850 stuffReadbuff(buf);
|
|
7851 }
|
|
7852 stuffcharReadbuff(c);
|
|
7853 return TRUE;
|
|
7854 }
|
|
7855 return FALSE;
|
|
7856 }
|
|
7857 #endif
|
|
7858
|
|
7859 /*
|
449
|
7860 * <Insert> key in Insert mode: toggle insert/remplace mode.
|
|
7861 */
|
|
7862 static void
|
|
7863 ins_insert(replaceState)
|
|
7864 int replaceState;
|
|
7865 {
|
|
7866 #ifdef FEAT_FKMAP
|
|
7867 if (p_fkmap && p_ri)
|
|
7868 {
|
|
7869 beep_flush();
|
|
7870 EMSG(farsi_text_3); /* encoded in Farsi */
|
|
7871 return;
|
|
7872 }
|
|
7873 #endif
|
|
7874
|
|
7875 #ifdef FEAT_AUTOCMD
|
532
|
7876 # ifdef FEAT_EVAL
|
449
|
7877 set_vim_var_string(VV_INSERTMODE,
|
|
7878 (char_u *)((State & REPLACE_FLAG) ? "i" :
|
667
|
7879 # ifdef FEAT_VREPLACE
|
|
7880 replaceState == VREPLACE ? "v" :
|
|
7881 # endif
|
|
7882 "r"), 1);
|
532
|
7883 # endif
|
449
|
7884 apply_autocmds(EVENT_INSERTCHANGE, NULL, NULL, FALSE, curbuf);
|
|
7885 #endif
|
|
7886 if (State & REPLACE_FLAG)
|
|
7887 State = INSERT | (State & LANGMAP);
|
|
7888 else
|
|
7889 State = replaceState | (State & LANGMAP);
|
|
7890 AppendCharToRedobuff(K_INS);
|
|
7891 showmode();
|
|
7892 #ifdef CURSOR_SHAPE
|
|
7893 ui_cursor_shape(); /* may show different cursor shape */
|
|
7894 #endif
|
|
7895 }
|
|
7896
|
|
7897 /*
|
|
7898 * Pressed CTRL-O in Insert mode.
|
|
7899 */
|
|
7900 static void
|
|
7901 ins_ctrl_o()
|
|
7902 {
|
|
7903 #ifdef FEAT_VREPLACE
|
|
7904 if (State & VREPLACE_FLAG)
|
|
7905 restart_edit = 'V';
|
|
7906 else
|
|
7907 #endif
|
|
7908 if (State & REPLACE_FLAG)
|
|
7909 restart_edit = 'R';
|
|
7910 else
|
|
7911 restart_edit = 'I';
|
|
7912 #ifdef FEAT_VIRTUALEDIT
|
|
7913 if (virtual_active())
|
|
7914 ins_at_eol = FALSE; /* cursor always keeps its column */
|
|
7915 else
|
|
7916 #endif
|
|
7917 ins_at_eol = (gchar_cursor() == NUL);
|
|
7918 }
|
|
7919
|
|
7920 /*
|
7
|
7921 * If the cursor is on an indent, ^T/^D insert/delete one
|
|
7922 * shiftwidth. Otherwise ^T/^D behave like a "<<" or ">>".
|
|
7923 * Always round the indent to 'shiftwith', this is compatible
|
|
7924 * with vi. But vi only supports ^T and ^D after an
|
|
7925 * autoindent, we support it everywhere.
|
|
7926 */
|
|
7927 static void
|
|
7928 ins_shift(c, lastc)
|
|
7929 int c;
|
|
7930 int lastc;
|
|
7931 {
|
|
7932 if (stop_arrow() == FAIL)
|
|
7933 return;
|
|
7934 AppendCharToRedobuff(c);
|
|
7935
|
|
7936 /*
|
|
7937 * 0^D and ^^D: remove all indent.
|
|
7938 */
|
|
7939 if ((lastc == '0' || lastc == '^') && curwin->w_cursor.col)
|
|
7940 {
|
|
7941 --curwin->w_cursor.col;
|
|
7942 (void)del_char(FALSE); /* delete the '^' or '0' */
|
|
7943 /* In Replace mode, restore the characters that '^' or '0' replaced. */
|
|
7944 if (State & REPLACE_FLAG)
|
|
7945 replace_pop_ins();
|
|
7946 if (lastc == '^')
|
|
7947 old_indent = get_indent(); /* remember curr. indent */
|
|
7948 change_indent(INDENT_SET, 0, TRUE, 0);
|
|
7949 }
|
|
7950 else
|
|
7951 change_indent(c == Ctrl_D ? INDENT_DEC : INDENT_INC, 0, TRUE, 0);
|
|
7952
|
|
7953 if (did_ai && *skipwhite(ml_get_curline()) != NUL)
|
|
7954 did_ai = FALSE;
|
|
7955 #ifdef FEAT_SMARTINDENT
|
|
7956 did_si = FALSE;
|
|
7957 can_si = FALSE;
|
|
7958 can_si_back = FALSE;
|
|
7959 #endif
|
|
7960 #ifdef FEAT_CINDENT
|
|
7961 can_cindent = FALSE; /* no cindenting after ^D or ^T */
|
|
7962 #endif
|
|
7963 }
|
|
7964
|
|
7965 static void
|
|
7966 ins_del()
|
|
7967 {
|
|
7968 int temp;
|
|
7969
|
|
7970 if (stop_arrow() == FAIL)
|
|
7971 return;
|
|
7972 if (gchar_cursor() == NUL) /* delete newline */
|
|
7973 {
|
|
7974 temp = curwin->w_cursor.col;
|
|
7975 if (!can_bs(BS_EOL) /* only if "eol" included */
|
|
7976 || u_save((linenr_T)(curwin->w_cursor.lnum - 1),
|
|
7977 (linenr_T)(curwin->w_cursor.lnum + 2)) == FAIL
|
|
7978 || do_join(FALSE) == FAIL)
|
|
7979 vim_beep();
|
|
7980 else
|
|
7981 curwin->w_cursor.col = temp;
|
|
7982 }
|
|
7983 else if (del_char(FALSE) == FAIL) /* delete char under cursor */
|
|
7984 vim_beep();
|
|
7985 did_ai = FALSE;
|
|
7986 #ifdef FEAT_SMARTINDENT
|
|
7987 did_si = FALSE;
|
|
7988 can_si = FALSE;
|
|
7989 can_si_back = FALSE;
|
|
7990 #endif
|
|
7991 AppendCharToRedobuff(K_DEL);
|
|
7992 }
|
|
7993
|
|
7994 /*
|
|
7995 * Handle Backspace, delete-word and delete-line in Insert mode.
|
|
7996 * Return TRUE when backspace was actually used.
|
|
7997 */
|
|
7998 static int
|
|
7999 ins_bs(c, mode, inserted_space_p)
|
|
8000 int c;
|
|
8001 int mode;
|
|
8002 int *inserted_space_p;
|
|
8003 {
|
|
8004 linenr_T lnum;
|
|
8005 int cc;
|
|
8006 int temp = 0; /* init for GCC */
|
|
8007 colnr_T mincol;
|
|
8008 int did_backspace = FALSE;
|
|
8009 int in_indent;
|
|
8010 int oldState;
|
|
8011 #ifdef FEAT_MBYTE
|
714
|
8012 int cpc[MAX_MCO]; /* composing characters */
|
7
|
8013 #endif
|
|
8014
|
|
8015 /*
|
|
8016 * can't delete anything in an empty file
|
|
8017 * can't backup past first character in buffer
|
|
8018 * can't backup past starting point unless 'backspace' > 1
|
|
8019 * can backup to a previous line if 'backspace' == 0
|
|
8020 */
|
|
8021 if ( bufempty()
|
|
8022 || (
|
|
8023 #ifdef FEAT_RIGHTLEFT
|
|
8024 !revins_on &&
|
|
8025 #endif
|
|
8026 ((curwin->w_cursor.lnum == 1 && curwin->w_cursor.col == 0)
|
|
8027 || (!can_bs(BS_START)
|
|
8028 && (arrow_used
|
|
8029 || (curwin->w_cursor.lnum == Insstart.lnum
|
|
8030 && curwin->w_cursor.col <= Insstart.col)))
|
|
8031 || (!can_bs(BS_INDENT) && !arrow_used && ai_col > 0
|
|
8032 && curwin->w_cursor.col <= ai_col)
|
|
8033 || (!can_bs(BS_EOL) && curwin->w_cursor.col == 0))))
|
|
8034 {
|
|
8035 vim_beep();
|
|
8036 return FALSE;
|
|
8037 }
|
|
8038
|
|
8039 if (stop_arrow() == FAIL)
|
|
8040 return FALSE;
|
|
8041 in_indent = inindent(0);
|
|
8042 #ifdef FEAT_CINDENT
|
|
8043 if (in_indent)
|
|
8044 can_cindent = FALSE;
|
|
8045 #endif
|
|
8046 #ifdef FEAT_COMMENTS
|
|
8047 end_comment_pending = NUL; /* After BS, don't auto-end comment */
|
|
8048 #endif
|
|
8049 #ifdef FEAT_RIGHTLEFT
|
|
8050 if (revins_on) /* put cursor after last inserted char */
|
|
8051 inc_cursor();
|
|
8052 #endif
|
|
8053
|
|
8054 #ifdef FEAT_VIRTUALEDIT
|
|
8055 /* Virtualedit:
|
|
8056 * BACKSPACE_CHAR eats a virtual space
|
|
8057 * BACKSPACE_WORD eats all coladd
|
|
8058 * BACKSPACE_LINE eats all coladd and keeps going
|
|
8059 */
|
|
8060 if (curwin->w_cursor.coladd > 0)
|
|
8061 {
|
|
8062 if (mode == BACKSPACE_CHAR)
|
|
8063 {
|
|
8064 --curwin->w_cursor.coladd;
|
|
8065 return TRUE;
|
|
8066 }
|
|
8067 if (mode == BACKSPACE_WORD)
|
|
8068 {
|
|
8069 curwin->w_cursor.coladd = 0;
|
|
8070 return TRUE;
|
|
8071 }
|
|
8072 curwin->w_cursor.coladd = 0;
|
|
8073 }
|
|
8074 #endif
|
|
8075
|
|
8076 /*
|
|
8077 * delete newline!
|
|
8078 */
|
|
8079 if (curwin->w_cursor.col == 0)
|
|
8080 {
|
|
8081 lnum = Insstart.lnum;
|
|
8082 if (curwin->w_cursor.lnum == Insstart.lnum
|
|
8083 #ifdef FEAT_RIGHTLEFT
|
|
8084 || revins_on
|
|
8085 #endif
|
|
8086 )
|
|
8087 {
|
|
8088 if (u_save((linenr_T)(curwin->w_cursor.lnum - 2),
|
|
8089 (linenr_T)(curwin->w_cursor.lnum + 1)) == FAIL)
|
|
8090 return FALSE;
|
|
8091 --Insstart.lnum;
|
|
8092 Insstart.col = MAXCOL;
|
|
8093 }
|
|
8094 /*
|
|
8095 * In replace mode:
|
|
8096 * cc < 0: NL was inserted, delete it
|
|
8097 * cc >= 0: NL was replaced, put original characters back
|
|
8098 */
|
|
8099 cc = -1;
|
|
8100 if (State & REPLACE_FLAG)
|
|
8101 cc = replace_pop(); /* returns -1 if NL was inserted */
|
|
8102 /*
|
|
8103 * In replace mode, in the line we started replacing, we only move the
|
|
8104 * cursor.
|
|
8105 */
|
|
8106 if ((State & REPLACE_FLAG) && curwin->w_cursor.lnum <= lnum)
|
|
8107 {
|
|
8108 dec_cursor();
|
|
8109 }
|
|
8110 else
|
|
8111 {
|
|
8112 #ifdef FEAT_VREPLACE
|
|
8113 if (!(State & VREPLACE_FLAG)
|
|
8114 || curwin->w_cursor.lnum > orig_line_count)
|
|
8115 #endif
|
|
8116 {
|
|
8117 temp = gchar_cursor(); /* remember current char */
|
|
8118 --curwin->w_cursor.lnum;
|
278
|
8119
|
|
8120 /* When "aw" is in 'formatoptions' we must delete the space at
|
|
8121 * the end of the line, otherwise the line will be broken
|
|
8122 * again when auto-formatting. */
|
|
8123 if (has_format_option(FO_AUTO)
|
|
8124 && has_format_option(FO_WHITE_PAR))
|
|
8125 {
|
|
8126 char_u *ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum,
|
|
8127 TRUE);
|
|
8128 int len;
|
|
8129
|
835
|
8130 len = (int)STRLEN(ptr);
|
278
|
8131 if (len > 0 && ptr[len - 1] == ' ')
|
|
8132 ptr[len - 1] = NUL;
|
|
8133 }
|
|
8134
|
7
|
8135 (void)do_join(FALSE);
|
|
8136 if (temp == NUL && gchar_cursor() != NUL)
|
|
8137 inc_cursor();
|
|
8138 }
|
|
8139 #ifdef FEAT_VREPLACE
|
|
8140 else
|
|
8141 dec_cursor();
|
|
8142 #endif
|
|
8143
|
|
8144 /*
|
|
8145 * In REPLACE mode we have to put back the text that was replaced
|
|
8146 * by the NL. On the replace stack is first a NUL-terminated
|
|
8147 * sequence of characters that were deleted and then the
|
|
8148 * characters that NL replaced.
|
|
8149 */
|
|
8150 if (State & REPLACE_FLAG)
|
|
8151 {
|
|
8152 /*
|
|
8153 * Do the next ins_char() in NORMAL state, to
|
|
8154 * prevent ins_char() from replacing characters and
|
|
8155 * avoiding showmatch().
|
|
8156 */
|
|
8157 oldState = State;
|
|
8158 State = NORMAL;
|
|
8159 /*
|
|
8160 * restore characters (blanks) deleted after cursor
|
|
8161 */
|
|
8162 while (cc > 0)
|
|
8163 {
|
|
8164 temp = curwin->w_cursor.col;
|
|
8165 #ifdef FEAT_MBYTE
|
|
8166 mb_replace_pop_ins(cc);
|
|
8167 #else
|
|
8168 ins_char(cc);
|
|
8169 #endif
|
|
8170 curwin->w_cursor.col = temp;
|
|
8171 cc = replace_pop();
|
|
8172 }
|
|
8173 /* restore the characters that NL replaced */
|
|
8174 replace_pop_ins();
|
|
8175 State = oldState;
|
|
8176 }
|
|
8177 }
|
|
8178 did_ai = FALSE;
|
|
8179 }
|
|
8180 else
|
|
8181 {
|
|
8182 /*
|
|
8183 * Delete character(s) before the cursor.
|
|
8184 */
|
|
8185 #ifdef FEAT_RIGHTLEFT
|
|
8186 if (revins_on) /* put cursor on last inserted char */
|
|
8187 dec_cursor();
|
|
8188 #endif
|
|
8189 mincol = 0;
|
|
8190 /* keep indent */
|
|
8191 if (mode == BACKSPACE_LINE && curbuf->b_p_ai
|
|
8192 #ifdef FEAT_RIGHTLEFT
|
|
8193 && !revins_on
|
|
8194 #endif
|
|
8195 )
|
|
8196 {
|
|
8197 temp = curwin->w_cursor.col;
|
|
8198 beginline(BL_WHITE);
|
|
8199 if (curwin->w_cursor.col < (colnr_T)temp)
|
|
8200 mincol = curwin->w_cursor.col;
|
|
8201 curwin->w_cursor.col = temp;
|
|
8202 }
|
|
8203
|
|
8204 /*
|
|
8205 * Handle deleting one 'shiftwidth' or 'softtabstop'.
|
|
8206 */
|
|
8207 if ( mode == BACKSPACE_CHAR
|
|
8208 && ((p_sta && in_indent)
|
648
|
8209 || (curbuf->b_p_sts != 0
|
7
|
8210 && (*(ml_get_cursor() - 1) == TAB
|
|
8211 || (*(ml_get_cursor() - 1) == ' '
|
|
8212 && (!*inserted_space_p
|
|
8213 || arrow_used))))))
|
|
8214 {
|
|
8215 int ts;
|
|
8216 colnr_T vcol;
|
|
8217 colnr_T want_vcol;
|
840
|
8218 #if 0
|
7
|
8219 int extra = 0;
|
840
|
8220 #endif
|
7
|
8221
|
|
8222 *inserted_space_p = FALSE;
|
648
|
8223 if (p_sta && in_indent)
|
7
|
8224 ts = curbuf->b_p_sw;
|
|
8225 else
|
|
8226 ts = curbuf->b_p_sts;
|
|
8227 /* Compute the virtual column where we want to be. Since
|
|
8228 * 'showbreak' may get in the way, need to get the last column of
|
|
8229 * the previous character. */
|
|
8230 getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
|
|
8231 dec_cursor();
|
|
8232 getvcol(curwin, &curwin->w_cursor, NULL, NULL, &want_vcol);
|
|
8233 inc_cursor();
|
|
8234 want_vcol = (want_vcol / ts) * ts;
|
|
8235
|
|
8236 /* delete characters until we are at or before want_vcol */
|
|
8237 while (vcol > want_vcol
|
|
8238 && (cc = *(ml_get_cursor() - 1), vim_iswhite(cc)))
|
|
8239 {
|
|
8240 dec_cursor();
|
|
8241 getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
|
|
8242 if (State & REPLACE_FLAG)
|
|
8243 {
|
|
8244 /* Don't delete characters before the insert point when in
|
|
8245 * Replace mode */
|
|
8246 if (curwin->w_cursor.lnum != Insstart.lnum
|
|
8247 || curwin->w_cursor.col >= Insstart.col)
|
|
8248 {
|
|
8249 #if 0 /* what was this for? It causes problems when sw != ts. */
|
|
8250 if (State == REPLACE && (int)vcol < want_vcol)
|
|
8251 {
|
|
8252 (void)del_char(FALSE);
|
|
8253 extra = 2; /* don't pop too much */
|
|
8254 }
|
|
8255 else
|
|
8256 #endif
|
|
8257 replace_do_bs();
|
|
8258 }
|
|
8259 }
|
|
8260 else
|
|
8261 (void)del_char(FALSE);
|
|
8262 }
|
|
8263
|
|
8264 /* insert extra spaces until we are at want_vcol */
|
|
8265 while (vcol < want_vcol)
|
|
8266 {
|
|
8267 /* Remember the first char we inserted */
|
|
8268 if (curwin->w_cursor.lnum == Insstart.lnum
|
|
8269 && curwin->w_cursor.col < Insstart.col)
|
|
8270 Insstart.col = curwin->w_cursor.col;
|
|
8271
|
|
8272 #ifdef FEAT_VREPLACE
|
|
8273 if (State & VREPLACE_FLAG)
|
|
8274 ins_char(' ');
|
|
8275 else
|
|
8276 #endif
|
|
8277 {
|
|
8278 ins_str((char_u *)" ");
|
840
|
8279 if ((State & REPLACE_FLAG) /* && extra <= 1 */)
|
7
|
8280 {
|
840
|
8281 #if 0
|
7
|
8282 if (extra)
|
|
8283 replace_push_off(NUL);
|
|
8284 else
|
840
|
8285 #endif
|
7
|
8286 replace_push(NUL);
|
|
8287 }
|
840
|
8288 #if 0
|
7
|
8289 if (extra == 2)
|
|
8290 extra = 1;
|
840
|
8291 #endif
|
7
|
8292 }
|
|
8293 getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
|
|
8294 }
|
|
8295 }
|
|
8296
|
|
8297 /*
|
|
8298 * Delete upto starting point, start of line or previous word.
|
|
8299 */
|
|
8300 else do
|
|
8301 {
|
|
8302 #ifdef FEAT_RIGHTLEFT
|
|
8303 if (!revins_on) /* put cursor on char to be deleted */
|
|
8304 #endif
|
|
8305 dec_cursor();
|
|
8306
|
|
8307 /* start of word? */
|
|
8308 if (mode == BACKSPACE_WORD && !vim_isspace(gchar_cursor()))
|
|
8309 {
|
|
8310 mode = BACKSPACE_WORD_NOT_SPACE;
|
|
8311 temp = vim_iswordc(gchar_cursor());
|
|
8312 }
|
|
8313 /* end of word? */
|
|
8314 else if (mode == BACKSPACE_WORD_NOT_SPACE
|
|
8315 && (vim_isspace(cc = gchar_cursor())
|
|
8316 || vim_iswordc(cc) != temp))
|
|
8317 {
|
|
8318 #ifdef FEAT_RIGHTLEFT
|
|
8319 if (!revins_on)
|
|
8320 #endif
|
|
8321 inc_cursor();
|
|
8322 #ifdef FEAT_RIGHTLEFT
|
|
8323 else if (State & REPLACE_FLAG)
|
|
8324 dec_cursor();
|
|
8325 #endif
|
|
8326 break;
|
|
8327 }
|
|
8328 if (State & REPLACE_FLAG)
|
|
8329 replace_do_bs();
|
|
8330 else
|
|
8331 {
|
|
8332 #ifdef FEAT_MBYTE
|
|
8333 if (enc_utf8 && p_deco)
|
714
|
8334 (void)utfc_ptr2char(ml_get_cursor(), cpc);
|
7
|
8335 #endif
|
|
8336 (void)del_char(FALSE);
|
|
8337 #ifdef FEAT_MBYTE
|
|
8338 /*
|
714
|
8339 * If there are combining characters and 'delcombine' is set
|
|
8340 * move the cursor back. Don't back up before the base
|
7
|
8341 * character.
|
|
8342 */
|
714
|
8343 if (enc_utf8 && p_deco && cpc[0] != NUL)
|
7
|
8344 inc_cursor();
|
|
8345 #endif
|
|
8346 #ifdef FEAT_RIGHTLEFT
|
|
8347 if (revins_chars)
|
|
8348 {
|
|
8349 revins_chars--;
|
|
8350 revins_legal++;
|
|
8351 }
|
|
8352 if (revins_on && gchar_cursor() == NUL)
|
|
8353 break;
|
|
8354 #endif
|
|
8355 }
|
|
8356 /* Just a single backspace?: */
|
|
8357 if (mode == BACKSPACE_CHAR)
|
|
8358 break;
|
|
8359 } while (
|
|
8360 #ifdef FEAT_RIGHTLEFT
|
|
8361 revins_on ||
|
|
8362 #endif
|
|
8363 (curwin->w_cursor.col > mincol
|
|
8364 && (curwin->w_cursor.lnum != Insstart.lnum
|
|
8365 || curwin->w_cursor.col != Insstart.col)));
|
|
8366 did_backspace = TRUE;
|
|
8367 }
|
|
8368 #ifdef FEAT_SMARTINDENT
|
|
8369 did_si = FALSE;
|
|
8370 can_si = FALSE;
|
|
8371 can_si_back = FALSE;
|
|
8372 #endif
|
|
8373 if (curwin->w_cursor.col <= 1)
|
|
8374 did_ai = FALSE;
|
|
8375 /*
|
|
8376 * It's a little strange to put backspaces into the redo
|
|
8377 * buffer, but it makes auto-indent a lot easier to deal
|
|
8378 * with.
|
|
8379 */
|
|
8380 AppendCharToRedobuff(c);
|
|
8381
|
|
8382 /* If deleted before the insertion point, adjust it */
|
|
8383 if (curwin->w_cursor.lnum == Insstart.lnum
|
|
8384 && curwin->w_cursor.col < Insstart.col)
|
|
8385 Insstart.col = curwin->w_cursor.col;
|
|
8386
|
|
8387 /* vi behaviour: the cursor moves backward but the character that
|
|
8388 * was there remains visible
|
|
8389 * Vim behaviour: the cursor moves backward and the character that
|
|
8390 * was there is erased from the screen.
|
|
8391 * We can emulate the vi behaviour by pretending there is a dollar
|
|
8392 * displayed even when there isn't.
|
|
8393 * --pkv Sun Jan 19 01:56:40 EST 2003 */
|
|
8394 if (vim_strchr(p_cpo, CPO_BACKSPACE) != NULL && dollar_vcol == 0)
|
|
8395 dollar_vcol = curwin->w_virtcol;
|
|
8396
|
|
8397 return did_backspace;
|
|
8398 }
|
|
8399
|
|
8400 #ifdef FEAT_MOUSE
|
|
8401 static void
|
|
8402 ins_mouse(c)
|
|
8403 int c;
|
|
8404 {
|
|
8405 pos_T tpos;
|
840
|
8406 win_T *old_curwin = curwin;
|
7
|
8407
|
|
8408 # ifdef FEAT_GUI
|
|
8409 /* When GUI is active, also move/paste when 'mouse' is empty */
|
|
8410 if (!gui.in_use)
|
|
8411 # endif
|
|
8412 if (!mouse_has(MOUSE_INSERT))
|
|
8413 return;
|
|
8414
|
|
8415 undisplay_dollar();
|
|
8416 tpos = curwin->w_cursor;
|
|
8417 if (do_mouse(NULL, c, BACKWARD, 1L, 0))
|
|
8418 {
|
840
|
8419 #ifdef FEAT_WINDOWS
|
|
8420 win_T *new_curwin = curwin;
|
|
8421
|
|
8422 if (curwin != old_curwin && win_valid(old_curwin))
|
|
8423 {
|
|
8424 /* Mouse took us to another window. We need to go back to the
|
|
8425 * previous one to stop insert there properly. */
|
|
8426 curwin = old_curwin;
|
|
8427 curbuf = curwin->w_buffer;
|
|
8428 }
|
|
8429 #endif
|
|
8430 start_arrow(curwin == old_curwin ? &tpos : NULL);
|
|
8431 #ifdef FEAT_WINDOWS
|
|
8432 if (curwin != new_curwin && win_valid(new_curwin))
|
|
8433 {
|
|
8434 curwin = new_curwin;
|
|
8435 curbuf = curwin->w_buffer;
|
|
8436 }
|
|
8437 #endif
|
7
|
8438 # ifdef FEAT_CINDENT
|
|
8439 can_cindent = TRUE;
|
|
8440 # endif
|
|
8441 }
|
|
8442
|
|
8443 #ifdef FEAT_WINDOWS
|
|
8444 /* redraw status lines (in case another window became active) */
|
|
8445 redraw_statuslines();
|
|
8446 #endif
|
|
8447 }
|
|
8448
|
|
8449 static void
|
|
8450 ins_mousescroll(up)
|
|
8451 int up;
|
|
8452 {
|
|
8453 pos_T tpos;
|
|
8454 # if defined(FEAT_GUI) && defined(FEAT_WINDOWS)
|
|
8455 win_T *old_curwin;
|
|
8456 # endif
|
|
8457
|
|
8458 tpos = curwin->w_cursor;
|
|
8459
|
|
8460 # if defined(FEAT_GUI) && defined(FEAT_WINDOWS)
|
|
8461 old_curwin = curwin;
|
|
8462
|
|
8463 /* Currently the mouse coordinates are only known in the GUI. */
|
|
8464 if (gui.in_use && mouse_row >= 0 && mouse_col >= 0)
|
|
8465 {
|
|
8466 int row, col;
|
|
8467
|
|
8468 row = mouse_row;
|
|
8469 col = mouse_col;
|
|
8470
|
|
8471 /* find the window at the pointer coordinates */
|
|
8472 curwin = mouse_find_win(&row, &col);
|
|
8473 curbuf = curwin->w_buffer;
|
|
8474 }
|
|
8475 if (curwin == old_curwin)
|
|
8476 # endif
|
|
8477 undisplay_dollar();
|
|
8478
|
|
8479 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))
|
|
8480 scroll_redraw(up, (long)(curwin->w_botline - curwin->w_topline));
|
|
8481 else
|
|
8482 scroll_redraw(up, 3L);
|
|
8483
|
|
8484 # if defined(FEAT_GUI) && defined(FEAT_WINDOWS)
|
|
8485 curwin->w_redr_status = TRUE;
|
|
8486
|
|
8487 curwin = old_curwin;
|
|
8488 curbuf = curwin->w_buffer;
|
|
8489 # endif
|
|
8490
|
|
8491 if (!equalpos(curwin->w_cursor, tpos))
|
|
8492 {
|
|
8493 start_arrow(&tpos);
|
|
8494 # ifdef FEAT_CINDENT
|
|
8495 can_cindent = TRUE;
|
|
8496 # endif
|
|
8497 }
|
|
8498 }
|
|
8499 #endif
|
|
8500
|
692
|
8501 #if defined(FEAT_GUI_TABLINE) || defined(PROTO)
|
724
|
8502 static void
|
692
|
8503 ins_tabline(c)
|
|
8504 int c;
|
|
8505 {
|
|
8506 /* We will be leaving the current window, unless closing another tab. */
|
|
8507 if (c != K_TABMENU || current_tabmenu != TABLINE_MENU_CLOSE
|
|
8508 || (current_tab != 0 && current_tab != tabpage_index(curtab)))
|
|
8509 {
|
|
8510 undisplay_dollar();
|
|
8511 start_arrow(&curwin->w_cursor);
|
|
8512 # ifdef FEAT_CINDENT
|
|
8513 can_cindent = TRUE;
|
|
8514 # endif
|
|
8515 }
|
|
8516
|
|
8517 if (c == K_TABLINE)
|
|
8518 goto_tabpage(current_tab);
|
|
8519 else
|
846
|
8520 {
|
692
|
8521 handle_tabmenu();
|
846
|
8522 redraw_statuslines(); /* will redraw the tabline when needed */
|
|
8523 }
|
692
|
8524 }
|
|
8525 #endif
|
|
8526
|
|
8527 #if defined(FEAT_GUI) || defined(PROTO)
|
7
|
8528 void
|
|
8529 ins_scroll()
|
|
8530 {
|
|
8531 pos_T tpos;
|
|
8532
|
|
8533 undisplay_dollar();
|
|
8534 tpos = curwin->w_cursor;
|
|
8535 if (gui_do_scroll())
|
|
8536 {
|
|
8537 start_arrow(&tpos);
|
|
8538 # ifdef FEAT_CINDENT
|
|
8539 can_cindent = TRUE;
|
|
8540 # endif
|
|
8541 }
|
|
8542 }
|
|
8543
|
|
8544 void
|
|
8545 ins_horscroll()
|
|
8546 {
|
|
8547 pos_T tpos;
|
|
8548
|
|
8549 undisplay_dollar();
|
|
8550 tpos = curwin->w_cursor;
|
|
8551 if (gui_do_horiz_scroll())
|
|
8552 {
|
|
8553 start_arrow(&tpos);
|
|
8554 # ifdef FEAT_CINDENT
|
|
8555 can_cindent = TRUE;
|
|
8556 # endif
|
|
8557 }
|
|
8558 }
|
|
8559 #endif
|
|
8560
|
|
8561 static void
|
|
8562 ins_left()
|
|
8563 {
|
|
8564 pos_T tpos;
|
|
8565
|
|
8566 #ifdef FEAT_FOLDING
|
|
8567 if ((fdo_flags & FDO_HOR) && KeyTyped)
|
|
8568 foldOpenCursor();
|
|
8569 #endif
|
|
8570 undisplay_dollar();
|
|
8571 tpos = curwin->w_cursor;
|
|
8572 if (oneleft() == OK)
|
|
8573 {
|
|
8574 start_arrow(&tpos);
|
|
8575 #ifdef FEAT_RIGHTLEFT
|
|
8576 /* If exit reversed string, position is fixed */
|
|
8577 if (revins_scol != -1 && (int)curwin->w_cursor.col >= revins_scol)
|
|
8578 revins_legal++;
|
|
8579 revins_chars++;
|
|
8580 #endif
|
|
8581 }
|
|
8582
|
|
8583 /*
|
|
8584 * if 'whichwrap' set for cursor in insert mode may go to
|
|
8585 * previous line
|
|
8586 */
|
|
8587 else if (vim_strchr(p_ww, '[') != NULL && curwin->w_cursor.lnum > 1)
|
|
8588 {
|
|
8589 start_arrow(&tpos);
|
|
8590 --(curwin->w_cursor.lnum);
|
|
8591 coladvance((colnr_T)MAXCOL);
|
|
8592 curwin->w_set_curswant = TRUE; /* so we stay at the end */
|
|
8593 }
|
|
8594 else
|
|
8595 vim_beep();
|
|
8596 }
|
|
8597
|
|
8598 static void
|
|
8599 ins_home(c)
|
|
8600 int c;
|
|
8601 {
|
|
8602 pos_T tpos;
|
|
8603
|
|
8604 #ifdef FEAT_FOLDING
|
|
8605 if ((fdo_flags & FDO_HOR) && KeyTyped)
|
|
8606 foldOpenCursor();
|
|
8607 #endif
|
|
8608 undisplay_dollar();
|
|
8609 tpos = curwin->w_cursor;
|
|
8610 if (c == K_C_HOME)
|
|
8611 curwin->w_cursor.lnum = 1;
|
|
8612 curwin->w_cursor.col = 0;
|
|
8613 #ifdef FEAT_VIRTUALEDIT
|
|
8614 curwin->w_cursor.coladd = 0;
|
|
8615 #endif
|
|
8616 curwin->w_curswant = 0;
|
|
8617 start_arrow(&tpos);
|
|
8618 }
|
|
8619
|
|
8620 static void
|
|
8621 ins_end(c)
|
|
8622 int c;
|
|
8623 {
|
|
8624 pos_T tpos;
|
|
8625
|
|
8626 #ifdef FEAT_FOLDING
|
|
8627 if ((fdo_flags & FDO_HOR) && KeyTyped)
|
|
8628 foldOpenCursor();
|
|
8629 #endif
|
|
8630 undisplay_dollar();
|
|
8631 tpos = curwin->w_cursor;
|
|
8632 if (c == K_C_END)
|
|
8633 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
|
8634 coladvance((colnr_T)MAXCOL);
|
|
8635 curwin->w_curswant = MAXCOL;
|
|
8636
|
|
8637 start_arrow(&tpos);
|
|
8638 }
|
|
8639
|
|
8640 static void
|
|
8641 ins_s_left()
|
|
8642 {
|
|
8643 #ifdef FEAT_FOLDING
|
|
8644 if ((fdo_flags & FDO_HOR) && KeyTyped)
|
|
8645 foldOpenCursor();
|
|
8646 #endif
|
|
8647 undisplay_dollar();
|
|
8648 if (curwin->w_cursor.lnum > 1 || curwin->w_cursor.col > 0)
|
|
8649 {
|
|
8650 start_arrow(&curwin->w_cursor);
|
|
8651 (void)bck_word(1L, FALSE, FALSE);
|
|
8652 curwin->w_set_curswant = TRUE;
|
|
8653 }
|
|
8654 else
|
|
8655 vim_beep();
|
|
8656 }
|
|
8657
|
|
8658 static void
|
|
8659 ins_right()
|
|
8660 {
|
|
8661 #ifdef FEAT_FOLDING
|
|
8662 if ((fdo_flags & FDO_HOR) && KeyTyped)
|
|
8663 foldOpenCursor();
|
|
8664 #endif
|
|
8665 undisplay_dollar();
|
|
8666 if (gchar_cursor() != NUL || virtual_active()
|
|
8667 )
|
|
8668 {
|
|
8669 start_arrow(&curwin->w_cursor);
|
|
8670 curwin->w_set_curswant = TRUE;
|
|
8671 #ifdef FEAT_VIRTUALEDIT
|
|
8672 if (virtual_active())
|
|
8673 oneright();
|
|
8674 else
|
|
8675 #endif
|
|
8676 {
|
|
8677 #ifdef FEAT_MBYTE
|
|
8678 if (has_mbyte)
|
474
|
8679 curwin->w_cursor.col += (*mb_ptr2len)(ml_get_cursor());
|
7
|
8680 else
|
|
8681 #endif
|
|
8682 ++curwin->w_cursor.col;
|
|
8683 }
|
|
8684
|
|
8685 #ifdef FEAT_RIGHTLEFT
|
|
8686 revins_legal++;
|
|
8687 if (revins_chars)
|
|
8688 revins_chars--;
|
|
8689 #endif
|
|
8690 }
|
|
8691 /* if 'whichwrap' set for cursor in insert mode, may move the
|
|
8692 * cursor to the next line */
|
|
8693 else if (vim_strchr(p_ww, ']') != NULL
|
|
8694 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count)
|
|
8695 {
|
|
8696 start_arrow(&curwin->w_cursor);
|
|
8697 curwin->w_set_curswant = TRUE;
|
|
8698 ++curwin->w_cursor.lnum;
|
|
8699 curwin->w_cursor.col = 0;
|
|
8700 }
|
|
8701 else
|
|
8702 vim_beep();
|
|
8703 }
|
|
8704
|
|
8705 static void
|
|
8706 ins_s_right()
|
|
8707 {
|
|
8708 #ifdef FEAT_FOLDING
|
|
8709 if ((fdo_flags & FDO_HOR) && KeyTyped)
|
|
8710 foldOpenCursor();
|
|
8711 #endif
|
|
8712 undisplay_dollar();
|
|
8713 if (curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count
|
|
8714 || gchar_cursor() != NUL)
|
|
8715 {
|
|
8716 start_arrow(&curwin->w_cursor);
|
|
8717 (void)fwd_word(1L, FALSE, 0);
|
|
8718 curwin->w_set_curswant = TRUE;
|
|
8719 }
|
|
8720 else
|
|
8721 vim_beep();
|
|
8722 }
|
|
8723
|
|
8724 static void
|
|
8725 ins_up(startcol)
|
|
8726 int startcol; /* when TRUE move to Insstart.col */
|
|
8727 {
|
|
8728 pos_T tpos;
|
|
8729 linenr_T old_topline = curwin->w_topline;
|
|
8730 #ifdef FEAT_DIFF
|
|
8731 int old_topfill = curwin->w_topfill;
|
|
8732 #endif
|
|
8733
|
|
8734 undisplay_dollar();
|
|
8735 tpos = curwin->w_cursor;
|
|
8736 if (cursor_up(1L, TRUE) == OK)
|
|
8737 {
|
|
8738 if (startcol)
|
|
8739 coladvance(getvcol_nolist(&Insstart));
|
|
8740 if (old_topline != curwin->w_topline
|
|
8741 #ifdef FEAT_DIFF
|
|
8742 || old_topfill != curwin->w_topfill
|
|
8743 #endif
|
|
8744 )
|
|
8745 redraw_later(VALID);
|
|
8746 start_arrow(&tpos);
|
|
8747 #ifdef FEAT_CINDENT
|
|
8748 can_cindent = TRUE;
|
|
8749 #endif
|
|
8750 }
|
|
8751 else
|
|
8752 vim_beep();
|
|
8753 }
|
|
8754
|
|
8755 static void
|
|
8756 ins_pageup()
|
|
8757 {
|
|
8758 pos_T tpos;
|
|
8759
|
|
8760 undisplay_dollar();
|
828
|
8761
|
|
8762 #ifdef FEAT_WINDOWS
|
|
8763 if (mod_mask & MOD_MASK_CTRL)
|
|
8764 {
|
|
8765 /* <C-PageUp>: tab page back */
|
|
8766 goto_tabpage(-1);
|
|
8767 return;
|
|
8768 }
|
|
8769 #endif
|
|
8770
|
7
|
8771 tpos = curwin->w_cursor;
|
|
8772 if (onepage(BACKWARD, 1L) == OK)
|
|
8773 {
|
|
8774 start_arrow(&tpos);
|
|
8775 #ifdef FEAT_CINDENT
|
|
8776 can_cindent = TRUE;
|
|
8777 #endif
|
|
8778 }
|
|
8779 else
|
|
8780 vim_beep();
|
|
8781 }
|
|
8782
|
|
8783 static void
|
|
8784 ins_down(startcol)
|
|
8785 int startcol; /* when TRUE move to Insstart.col */
|
|
8786 {
|
|
8787 pos_T tpos;
|
|
8788 linenr_T old_topline = curwin->w_topline;
|
|
8789 #ifdef FEAT_DIFF
|
|
8790 int old_topfill = curwin->w_topfill;
|
|
8791 #endif
|
|
8792
|
|
8793 undisplay_dollar();
|
|
8794 tpos = curwin->w_cursor;
|
|
8795 if (cursor_down(1L, TRUE) == OK)
|
|
8796 {
|
|
8797 if (startcol)
|
|
8798 coladvance(getvcol_nolist(&Insstart));
|
|
8799 if (old_topline != curwin->w_topline
|
|
8800 #ifdef FEAT_DIFF
|
|
8801 || old_topfill != curwin->w_topfill
|
|
8802 #endif
|
|
8803 )
|
|
8804 redraw_later(VALID);
|
|
8805 start_arrow(&tpos);
|
|
8806 #ifdef FEAT_CINDENT
|
|
8807 can_cindent = TRUE;
|
|
8808 #endif
|
|
8809 }
|
|
8810 else
|
|
8811 vim_beep();
|
|
8812 }
|
|
8813
|
|
8814 static void
|
|
8815 ins_pagedown()
|
|
8816 {
|
|
8817 pos_T tpos;
|
|
8818
|
|
8819 undisplay_dollar();
|
828
|
8820
|
|
8821 #ifdef FEAT_WINDOWS
|
|
8822 if (mod_mask & MOD_MASK_CTRL)
|
|
8823 {
|
|
8824 /* <C-PageDown>: tab page forward */
|
|
8825 goto_tabpage(0);
|
|
8826 return;
|
|
8827 }
|
|
8828 #endif
|
|
8829
|
7
|
8830 tpos = curwin->w_cursor;
|
|
8831 if (onepage(FORWARD, 1L) == OK)
|
|
8832 {
|
|
8833 start_arrow(&tpos);
|
|
8834 #ifdef FEAT_CINDENT
|
|
8835 can_cindent = TRUE;
|
|
8836 #endif
|
|
8837 }
|
|
8838 else
|
|
8839 vim_beep();
|
|
8840 }
|
|
8841
|
|
8842 #ifdef FEAT_DND
|
|
8843 static void
|
|
8844 ins_drop()
|
|
8845 {
|
|
8846 do_put('~', BACKWARD, 1L, PUT_CURSEND);
|
|
8847 }
|
|
8848 #endif
|
|
8849
|
|
8850 /*
|
|
8851 * Handle TAB in Insert or Replace mode.
|
|
8852 * Return TRUE when the TAB needs to be inserted like a normal character.
|
|
8853 */
|
|
8854 static int
|
|
8855 ins_tab()
|
|
8856 {
|
|
8857 int ind;
|
|
8858 int i;
|
|
8859 int temp;
|
|
8860
|
|
8861 if (Insstart_blank_vcol == MAXCOL && curwin->w_cursor.lnum == Insstart.lnum)
|
|
8862 Insstart_blank_vcol = get_nolist_virtcol();
|
|
8863 if (echeck_abbr(TAB + ABBR_OFF))
|
|
8864 return FALSE;
|
|
8865
|
|
8866 ind = inindent(0);
|
|
8867 #ifdef FEAT_CINDENT
|
|
8868 if (ind)
|
|
8869 can_cindent = FALSE;
|
|
8870 #endif
|
|
8871
|
|
8872 /*
|
|
8873 * When nothing special, insert TAB like a normal character
|
|
8874 */
|
|
8875 if (!curbuf->b_p_et
|
|
8876 && !(p_sta && ind && curbuf->b_p_ts != curbuf->b_p_sw)
|
|
8877 && curbuf->b_p_sts == 0)
|
|
8878 return TRUE;
|
|
8879
|
|
8880 if (stop_arrow() == FAIL)
|
|
8881 return TRUE;
|
|
8882
|
|
8883 did_ai = FALSE;
|
|
8884 #ifdef FEAT_SMARTINDENT
|
|
8885 did_si = FALSE;
|
|
8886 can_si = FALSE;
|
|
8887 can_si_back = FALSE;
|
|
8888 #endif
|
|
8889 AppendToRedobuff((char_u *)"\t");
|
|
8890
|
|
8891 if (p_sta && ind) /* insert tab in indent, use 'shiftwidth' */
|
|
8892 temp = (int)curbuf->b_p_sw;
|
|
8893 else if (curbuf->b_p_sts > 0) /* use 'softtabstop' when set */
|
|
8894 temp = (int)curbuf->b_p_sts;
|
|
8895 else /* otherwise use 'tabstop' */
|
|
8896 temp = (int)curbuf->b_p_ts;
|
|
8897 temp -= get_nolist_virtcol() % temp;
|
|
8898
|
|
8899 /*
|
|
8900 * Insert the first space with ins_char(). It will delete one char in
|
|
8901 * replace mode. Insert the rest with ins_str(); it will not delete any
|
|
8902 * chars. For VREPLACE mode, we use ins_char() for all characters.
|
|
8903 */
|
|
8904 ins_char(' ');
|
|
8905 while (--temp > 0)
|
|
8906 {
|
|
8907 #ifdef FEAT_VREPLACE
|
|
8908 if (State & VREPLACE_FLAG)
|
|
8909 ins_char(' ');
|
|
8910 else
|
|
8911 #endif
|
|
8912 {
|
|
8913 ins_str((char_u *)" ");
|
|
8914 if (State & REPLACE_FLAG) /* no char replaced */
|
|
8915 replace_push(NUL);
|
|
8916 }
|
|
8917 }
|
|
8918
|
|
8919 /*
|
|
8920 * When 'expandtab' not set: Replace spaces by TABs where possible.
|
|
8921 */
|
|
8922 if (!curbuf->b_p_et && (curbuf->b_p_sts || (p_sta && ind)))
|
|
8923 {
|
|
8924 char_u *ptr;
|
|
8925 #ifdef FEAT_VREPLACE
|
|
8926 char_u *saved_line = NULL; /* init for GCC */
|
|
8927 pos_T pos;
|
|
8928 #endif
|
|
8929 pos_T fpos;
|
|
8930 pos_T *cursor;
|
|
8931 colnr_T want_vcol, vcol;
|
|
8932 int change_col = -1;
|
|
8933 int save_list = curwin->w_p_list;
|
|
8934
|
|
8935 /*
|
|
8936 * Get the current line. For VREPLACE mode, don't make real changes
|
|
8937 * yet, just work on a copy of the line.
|
|
8938 */
|
|
8939 #ifdef FEAT_VREPLACE
|
|
8940 if (State & VREPLACE_FLAG)
|
|
8941 {
|
|
8942 pos = curwin->w_cursor;
|
|
8943 cursor = &pos;
|
|
8944 saved_line = vim_strsave(ml_get_curline());
|
|
8945 if (saved_line == NULL)
|
|
8946 return FALSE;
|
|
8947 ptr = saved_line + pos.col;
|
|
8948 }
|
|
8949 else
|
|
8950 #endif
|
|
8951 {
|
|
8952 ptr = ml_get_cursor();
|
|
8953 cursor = &curwin->w_cursor;
|
|
8954 }
|
|
8955
|
|
8956 /* When 'L' is not in 'cpoptions' a tab always takes up 'ts' spaces. */
|
|
8957 if (vim_strchr(p_cpo, CPO_LISTWM) == NULL)
|
|
8958 curwin->w_p_list = FALSE;
|
|
8959
|
|
8960 /* Find first white before the cursor */
|
|
8961 fpos = curwin->w_cursor;
|
|
8962 while (fpos.col > 0 && vim_iswhite(ptr[-1]))
|
|
8963 {
|
|
8964 --fpos.col;
|
|
8965 --ptr;
|
|
8966 }
|
|
8967
|
|
8968 /* In Replace mode, don't change characters before the insert point. */
|
|
8969 if ((State & REPLACE_FLAG)
|
|
8970 && fpos.lnum == Insstart.lnum
|
|
8971 && fpos.col < Insstart.col)
|
|
8972 {
|
|
8973 ptr += Insstart.col - fpos.col;
|
|
8974 fpos.col = Insstart.col;
|
|
8975 }
|
|
8976
|
|
8977 /* compute virtual column numbers of first white and cursor */
|
|
8978 getvcol(curwin, &fpos, &vcol, NULL, NULL);
|
|
8979 getvcol(curwin, cursor, &want_vcol, NULL, NULL);
|
|
8980
|
|
8981 /* Use as many TABs as possible. Beware of 'showbreak' and
|
|
8982 * 'linebreak' adding extra virtual columns. */
|
|
8983 while (vim_iswhite(*ptr))
|
|
8984 {
|
|
8985 i = lbr_chartabsize((char_u *)"\t", vcol);
|
|
8986 if (vcol + i > want_vcol)
|
|
8987 break;
|
|
8988 if (*ptr != TAB)
|
|
8989 {
|
|
8990 *ptr = TAB;
|
|
8991 if (change_col < 0)
|
|
8992 {
|
|
8993 change_col = fpos.col; /* Column of first change */
|
|
8994 /* May have to adjust Insstart */
|
|
8995 if (fpos.lnum == Insstart.lnum && fpos.col < Insstart.col)
|
|
8996 Insstart.col = fpos.col;
|
|
8997 }
|
|
8998 }
|
|
8999 ++fpos.col;
|
|
9000 ++ptr;
|
|
9001 vcol += i;
|
|
9002 }
|
|
9003
|
|
9004 if (change_col >= 0)
|
|
9005 {
|
|
9006 int repl_off = 0;
|
|
9007
|
|
9008 /* Skip over the spaces we need. */
|
|
9009 while (vcol < want_vcol && *ptr == ' ')
|
|
9010 {
|
|
9011 vcol += lbr_chartabsize(ptr, vcol);
|
|
9012 ++ptr;
|
|
9013 ++repl_off;
|
|
9014 }
|
|
9015 if (vcol > want_vcol)
|
|
9016 {
|
|
9017 /* Must have a char with 'showbreak' just before it. */
|
|
9018 --ptr;
|
|
9019 --repl_off;
|
|
9020 }
|
|
9021 fpos.col += repl_off;
|
|
9022
|
|
9023 /* Delete following spaces. */
|
|
9024 i = cursor->col - fpos.col;
|
|
9025 if (i > 0)
|
|
9026 {
|
|
9027 mch_memmove(ptr, ptr + i, STRLEN(ptr + i) + 1);
|
|
9028 /* correct replace stack. */
|
|
9029 if ((State & REPLACE_FLAG)
|
|
9030 #ifdef FEAT_VREPLACE
|
|
9031 && !(State & VREPLACE_FLAG)
|
|
9032 #endif
|
|
9033 )
|
|
9034 for (temp = i; --temp >= 0; )
|
|
9035 replace_join(repl_off);
|
|
9036 }
|
33
|
9037 #ifdef FEAT_NETBEANS_INTG
|
|
9038 if (usingNetbeans)
|
|
9039 {
|
|
9040 netbeans_removed(curbuf, fpos.lnum, cursor->col,
|
|
9041 (long)(i + 1));
|
|
9042 netbeans_inserted(curbuf, fpos.lnum, cursor->col,
|
|
9043 (char_u *)"\t", 1);
|
|
9044 }
|
|
9045 #endif
|
7
|
9046 cursor->col -= i;
|
|
9047
|
|
9048 #ifdef FEAT_VREPLACE
|
|
9049 /*
|
|
9050 * In VREPLACE mode, we haven't changed anything yet. Do it now by
|
|
9051 * backspacing over the changed spacing and then inserting the new
|
|
9052 * spacing.
|
|
9053 */
|
|
9054 if (State & VREPLACE_FLAG)
|
|
9055 {
|
|
9056 /* Backspace from real cursor to change_col */
|
|
9057 backspace_until_column(change_col);
|
|
9058
|
|
9059 /* Insert each char in saved_line from changed_col to
|
|
9060 * ptr-cursor */
|
|
9061 ins_bytes_len(saved_line + change_col,
|
|
9062 cursor->col - change_col);
|
|
9063 }
|
|
9064 #endif
|
|
9065 }
|
|
9066
|
|
9067 #ifdef FEAT_VREPLACE
|
|
9068 if (State & VREPLACE_FLAG)
|
|
9069 vim_free(saved_line);
|
|
9070 #endif
|
|
9071 curwin->w_p_list = save_list;
|
|
9072 }
|
|
9073
|
|
9074 return FALSE;
|
|
9075 }
|
|
9076
|
|
9077 /*
|
|
9078 * Handle CR or NL in insert mode.
|
|
9079 * Return TRUE when out of memory or can't undo.
|
|
9080 */
|
|
9081 static int
|
|
9082 ins_eol(c)
|
|
9083 int c;
|
|
9084 {
|
|
9085 int i;
|
|
9086
|
|
9087 if (echeck_abbr(c + ABBR_OFF))
|
|
9088 return FALSE;
|
|
9089 if (stop_arrow() == FAIL)
|
|
9090 return TRUE;
|
|
9091 undisplay_dollar();
|
|
9092
|
|
9093 /*
|
|
9094 * Strange Vi behaviour: In Replace mode, typing a NL will not delete the
|
|
9095 * character under the cursor. Only push a NUL on the replace stack,
|
|
9096 * nothing to put back when the NL is deleted.
|
|
9097 */
|
|
9098 if ((State & REPLACE_FLAG)
|
|
9099 #ifdef FEAT_VREPLACE
|
|
9100 && !(State & VREPLACE_FLAG)
|
|
9101 #endif
|
|
9102 )
|
|
9103 replace_push(NUL);
|
|
9104
|
|
9105 /*
|
|
9106 * In VREPLACE mode, a NL replaces the rest of the line, and starts
|
|
9107 * replacing the next line, so we push all of the characters left on the
|
|
9108 * line onto the replace stack. This is not done here though, it is done
|
|
9109 * in open_line().
|
|
9110 */
|
|
9111
|
844
|
9112 #ifdef FEAT_VIRTUALEDIT
|
|
9113 /* Put cursor on NUL if on the last char and coladd is 1 (happens after
|
|
9114 * CTRL-O). */
|
|
9115 if (virtual_active() && curwin->w_cursor.coladd > 0)
|
|
9116 coladvance(getviscol());
|
|
9117 #endif
|
|
9118
|
7
|
9119 #ifdef FEAT_RIGHTLEFT
|
|
9120 # ifdef FEAT_FKMAP
|
|
9121 if (p_altkeymap && p_fkmap)
|
|
9122 fkmap(NL);
|
|
9123 # endif
|
|
9124 /* NL in reverse insert will always start in the end of
|
|
9125 * current line. */
|
|
9126 if (revins_on)
|
|
9127 curwin->w_cursor.col += (colnr_T)STRLEN(ml_get_cursor());
|
|
9128 #endif
|
|
9129
|
|
9130 AppendToRedobuff(NL_STR);
|
|
9131 i = open_line(FORWARD,
|
|
9132 #ifdef FEAT_COMMENTS
|
|
9133 has_format_option(FO_RET_COMS) ? OPENLINE_DO_COM :
|
|
9134 #endif
|
|
9135 0, old_indent);
|
|
9136 old_indent = 0;
|
|
9137 #ifdef FEAT_CINDENT
|
|
9138 can_cindent = TRUE;
|
|
9139 #endif
|
|
9140
|
|
9141 return (!i);
|
|
9142 }
|
|
9143
|
|
9144 #ifdef FEAT_DIGRAPHS
|
|
9145 /*
|
|
9146 * Handle digraph in insert mode.
|
|
9147 * Returns character still to be inserted, or NUL when nothing remaining to be
|
|
9148 * done.
|
|
9149 */
|
|
9150 static int
|
|
9151 ins_digraph()
|
|
9152 {
|
|
9153 int c;
|
|
9154 int cc;
|
|
9155
|
|
9156 pc_status = PC_STATUS_UNSET;
|
|
9157 if (redrawing() && !char_avail())
|
|
9158 {
|
|
9159 /* may need to redraw when no more chars available now */
|
661
|
9160 ins_redraw(FALSE);
|
7
|
9161
|
|
9162 edit_putchar('?', TRUE);
|
|
9163 #ifdef FEAT_CMDL_INFO
|
|
9164 add_to_showcmd_c(Ctrl_K);
|
|
9165 #endif
|
|
9166 }
|
|
9167
|
|
9168 #ifdef USE_ON_FLY_SCROLL
|
|
9169 dont_scroll = TRUE; /* disallow scrolling here */
|
|
9170 #endif
|
|
9171
|
|
9172 /* don't map the digraph chars. This also prevents the
|
|
9173 * mode message to be deleted when ESC is hit */
|
|
9174 ++no_mapping;
|
|
9175 ++allow_keys;
|
|
9176 c = safe_vgetc();
|
|
9177 --no_mapping;
|
|
9178 --allow_keys;
|
|
9179 if (IS_SPECIAL(c) || mod_mask) /* special key */
|
|
9180 {
|
|
9181 #ifdef FEAT_CMDL_INFO
|
|
9182 clear_showcmd();
|
|
9183 #endif
|
|
9184 insert_special(c, TRUE, FALSE);
|
|
9185 return NUL;
|
|
9186 }
|
|
9187 if (c != ESC)
|
|
9188 {
|
|
9189 if (redrawing() && !char_avail())
|
|
9190 {
|
|
9191 /* may need to redraw when no more chars available now */
|
661
|
9192 ins_redraw(FALSE);
|
7
|
9193
|
|
9194 if (char2cells(c) == 1)
|
|
9195 {
|
|
9196 /* first remove the '?', otherwise it's restored when typing
|
|
9197 * an ESC next */
|
|
9198 edit_unputchar();
|
661
|
9199 ins_redraw(FALSE);
|
7
|
9200 edit_putchar(c, TRUE);
|
|
9201 }
|
|
9202 #ifdef FEAT_CMDL_INFO
|
|
9203 add_to_showcmd_c(c);
|
|
9204 #endif
|
|
9205 }
|
|
9206 ++no_mapping;
|
|
9207 ++allow_keys;
|
|
9208 cc = safe_vgetc();
|
|
9209 --no_mapping;
|
|
9210 --allow_keys;
|
|
9211 if (cc != ESC)
|
|
9212 {
|
|
9213 AppendToRedobuff((char_u *)CTRL_V_STR);
|
|
9214 c = getdigraph(c, cc, TRUE);
|
|
9215 #ifdef FEAT_CMDL_INFO
|
|
9216 clear_showcmd();
|
|
9217 #endif
|
|
9218 return c;
|
|
9219 }
|
|
9220 }
|
|
9221 edit_unputchar();
|
|
9222 #ifdef FEAT_CMDL_INFO
|
|
9223 clear_showcmd();
|
|
9224 #endif
|
|
9225 return NUL;
|
|
9226 }
|
|
9227 #endif
|
|
9228
|
|
9229 /*
|
|
9230 * Handle CTRL-E and CTRL-Y in Insert mode: copy char from other line.
|
|
9231 * Returns the char to be inserted, or NUL if none found.
|
|
9232 */
|
|
9233 static int
|
|
9234 ins_copychar(lnum)
|
|
9235 linenr_T lnum;
|
|
9236 {
|
|
9237 int c;
|
|
9238 int temp;
|
|
9239 char_u *ptr, *prev_ptr;
|
|
9240
|
|
9241 if (lnum < 1 || lnum > curbuf->b_ml.ml_line_count)
|
|
9242 {
|
|
9243 vim_beep();
|
|
9244 return NUL;
|
|
9245 }
|
|
9246
|
|
9247 /* try to advance to the cursor column */
|
|
9248 temp = 0;
|
|
9249 ptr = ml_get(lnum);
|
|
9250 prev_ptr = ptr;
|
|
9251 validate_virtcol();
|
|
9252 while ((colnr_T)temp < curwin->w_virtcol && *ptr != NUL)
|
|
9253 {
|
|
9254 prev_ptr = ptr;
|
|
9255 temp += lbr_chartabsize_adv(&ptr, (colnr_T)temp);
|
|
9256 }
|
|
9257 if ((colnr_T)temp > curwin->w_virtcol)
|
|
9258 ptr = prev_ptr;
|
|
9259
|
|
9260 #ifdef FEAT_MBYTE
|
|
9261 c = (*mb_ptr2char)(ptr);
|
|
9262 #else
|
|
9263 c = *ptr;
|
|
9264 #endif
|
|
9265 if (c == NUL)
|
|
9266 vim_beep();
|
|
9267 return c;
|
|
9268 }
|
|
9269
|
449
|
9270 /*
|
|
9271 * CTRL-Y or CTRL-E typed in Insert mode.
|
|
9272 */
|
|
9273 static int
|
|
9274 ins_ctrl_ey(tc)
|
|
9275 int tc;
|
|
9276 {
|
|
9277 int c = tc;
|
|
9278
|
|
9279 #ifdef FEAT_INS_EXPAND
|
|
9280 if (ctrl_x_mode == CTRL_X_SCROLL)
|
|
9281 {
|
|
9282 if (c == Ctrl_Y)
|
|
9283 scrolldown_clamp();
|
|
9284 else
|
|
9285 scrollup_clamp();
|
|
9286 redraw_later(VALID);
|
|
9287 }
|
|
9288 else
|
|
9289 #endif
|
|
9290 {
|
|
9291 c = ins_copychar(curwin->w_cursor.lnum + (c == Ctrl_Y ? -1 : 1));
|
|
9292 if (c != NUL)
|
|
9293 {
|
|
9294 long tw_save;
|
|
9295
|
|
9296 /* The character must be taken literally, insert like it
|
|
9297 * was typed after a CTRL-V, and pretend 'textwidth'
|
|
9298 * wasn't set. Digits, 'o' and 'x' are special after a
|
|
9299 * CTRL-V, don't use it for these. */
|
|
9300 if (c < 256 && !isalnum(c))
|
|
9301 AppendToRedobuff((char_u *)CTRL_V_STR); /* CTRL-V */
|
|
9302 tw_save = curbuf->b_p_tw;
|
|
9303 curbuf->b_p_tw = -1;
|
|
9304 insert_special(c, TRUE, FALSE);
|
|
9305 curbuf->b_p_tw = tw_save;
|
|
9306 #ifdef FEAT_RIGHTLEFT
|
|
9307 revins_chars++;
|
|
9308 revins_legal++;
|
|
9309 #endif
|
|
9310 c = Ctrl_V; /* pretend CTRL-V is last character */
|
|
9311 auto_format(FALSE, TRUE);
|
|
9312 }
|
|
9313 }
|
|
9314 return c;
|
|
9315 }
|
|
9316
|
7
|
9317 #ifdef FEAT_SMARTINDENT
|
|
9318 /*
|
|
9319 * Try to do some very smart auto-indenting.
|
|
9320 * Used when inserting a "normal" character.
|
|
9321 */
|
|
9322 static void
|
|
9323 ins_try_si(c)
|
|
9324 int c;
|
|
9325 {
|
|
9326 pos_T *pos, old_pos;
|
|
9327 char_u *ptr;
|
|
9328 int i;
|
|
9329 int temp;
|
|
9330
|
|
9331 /*
|
|
9332 * do some very smart indenting when entering '{' or '}'
|
|
9333 */
|
|
9334 if (((did_si || can_si_back) && c == '{') || (can_si && c == '}'))
|
|
9335 {
|
|
9336 /*
|
|
9337 * for '}' set indent equal to indent of line containing matching '{'
|
|
9338 */
|
|
9339 if (c == '}' && (pos = findmatch(NULL, '{')) != NULL)
|
|
9340 {
|
|
9341 old_pos = curwin->w_cursor;
|
|
9342 /*
|
|
9343 * If the matching '{' has a ')' immediately before it (ignoring
|
|
9344 * white-space), then line up with the start of the line
|
|
9345 * containing the matching '(' if there is one. This handles the
|
|
9346 * case where an "if (..\n..) {" statement continues over multiple
|
|
9347 * lines -- webb
|
|
9348 */
|
|
9349 ptr = ml_get(pos->lnum);
|
|
9350 i = pos->col;
|
|
9351 if (i > 0) /* skip blanks before '{' */
|
|
9352 while (--i > 0 && vim_iswhite(ptr[i]))
|
|
9353 ;
|
|
9354 curwin->w_cursor.lnum = pos->lnum;
|
|
9355 curwin->w_cursor.col = i;
|
|
9356 if (ptr[i] == ')' && (pos = findmatch(NULL, '(')) != NULL)
|
|
9357 curwin->w_cursor = *pos;
|
|
9358 i = get_indent();
|
|
9359 curwin->w_cursor = old_pos;
|
|
9360 #ifdef FEAT_VREPLACE
|
|
9361 if (State & VREPLACE_FLAG)
|
|
9362 change_indent(INDENT_SET, i, FALSE, NUL);
|
|
9363 else
|
|
9364 #endif
|
|
9365 (void)set_indent(i, SIN_CHANGED);
|
|
9366 }
|
|
9367 else if (curwin->w_cursor.col > 0)
|
|
9368 {
|
|
9369 /*
|
|
9370 * when inserting '{' after "O" reduce indent, but not
|
|
9371 * more than indent of previous line
|
|
9372 */
|
|
9373 temp = TRUE;
|
|
9374 if (c == '{' && can_si_back && curwin->w_cursor.lnum > 1)
|
|
9375 {
|
|
9376 old_pos = curwin->w_cursor;
|
|
9377 i = get_indent();
|
|
9378 while (curwin->w_cursor.lnum > 1)
|
|
9379 {
|
|
9380 ptr = skipwhite(ml_get(--(curwin->w_cursor.lnum)));
|
|
9381
|
|
9382 /* ignore empty lines and lines starting with '#'. */
|
|
9383 if (*ptr != '#' && *ptr != NUL)
|
|
9384 break;
|
|
9385 }
|
|
9386 if (get_indent() >= i)
|
|
9387 temp = FALSE;
|
|
9388 curwin->w_cursor = old_pos;
|
|
9389 }
|
|
9390 if (temp)
|
|
9391 shift_line(TRUE, FALSE, 1);
|
|
9392 }
|
|
9393 }
|
|
9394
|
|
9395 /*
|
|
9396 * set indent of '#' always to 0
|
|
9397 */
|
|
9398 if (curwin->w_cursor.col > 0 && can_si && c == '#')
|
|
9399 {
|
|
9400 /* remember current indent for next line */
|
|
9401 old_indent = get_indent();
|
|
9402 (void)set_indent(0, SIN_CHANGED);
|
|
9403 }
|
|
9404
|
|
9405 /* Adjust ai_col, the char at this position can be deleted. */
|
|
9406 if (ai_col > curwin->w_cursor.col)
|
|
9407 ai_col = curwin->w_cursor.col;
|
|
9408 }
|
|
9409 #endif
|
|
9410
|
|
9411 /*
|
|
9412 * Get the value that w_virtcol would have when 'list' is off.
|
|
9413 * Unless 'cpo' contains the 'L' flag.
|
|
9414 */
|
|
9415 static colnr_T
|
|
9416 get_nolist_virtcol()
|
|
9417 {
|
|
9418 if (curwin->w_p_list && vim_strchr(p_cpo, CPO_LISTWM) == NULL)
|
|
9419 return getvcol_nolist(&curwin->w_cursor);
|
|
9420 validate_virtcol();
|
|
9421 return curwin->w_virtcol;
|
|
9422 }
|