-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit.c
7614 lines (7012 loc) · 180 KB
/
edit.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
* edit.c: functions for Insert mode
*/
#include "vim.h"
#ifdef FEAT_INS_EXPAND
/*
* definitions used for CTRL-X submode
*/
#define CTRL_X_WANT_IDENT 0x100
#define CTRL_X_NOT_DEFINED_YET 1
#define CTRL_X_SCROLL 2
#define CTRL_X_WHOLE_LINE 3
#define CTRL_X_FILES 4
#define CTRL_X_TAGS (5 + CTRL_X_WANT_IDENT)
#define CTRL_X_PATH_PATTERNS (6 + CTRL_X_WANT_IDENT)
#define CTRL_X_PATH_DEFINES (7 + CTRL_X_WANT_IDENT)
#define CTRL_X_FINISHED 8
#define CTRL_X_DICTIONARY (9 + CTRL_X_WANT_IDENT)
#define CTRL_X_THESAURUS (10 + CTRL_X_WANT_IDENT)
#define CTRL_X_CMDLINE 11
#define CHECK_KEYS_TIME 30
#define CTRL_X_MSG(i) ctrl_x_msgs[(i) & ~CTRL_X_WANT_IDENT]
static char *ctrl_x_msgs[] =
{
N_(" Keyword completion (^N^P)"), /* ctrl_x_mode == 0, ^P/^N compl. */
N_(" ^X mode (^E^Y^L^]^F^I^K^D^V^N^P)"),
/* Scroll has it's own msgs, in it's place there is the msg for local
* ctrl_x_mode = 0 (eg continue_status & CONT_LOCAL) -- Acevedo */
N_(" Keyword Local completion (^N^P)"),
N_(" Whole line completion (^L^N^P)"),
N_(" File name completion (^F^N^P)"),
N_(" Tag completion (^]^N^P)"),
N_(" Path pattern completion (^N^P)"),
N_(" Definition completion (^D^N^P)"),
NULL,
N_(" Dictionary completion (^K^N^P)"),
N_(" Thesaurus completion (^T^N^P)"),
N_(" Command-line completion (^V^N^P)")
};
static char_u e_hitend[] = N_("Hit end of paragraph");
/*
* Structure used to store one match for insert completion.
*/
struct Completion
{
struct Completion *next;
struct Completion *prev;
char_u *str; /* matched text */
char_u *fname; /* file containing the match */
int original; /* ORIGINAL_TEXT, CONT_S_IPOS or FREE_FNAME */
int number; /* sequence number */
};
/* the original text when the expansion begun */
#define ORIGINAL_TEXT (1)
#define FREE_FNAME (2)
/*
* All the current matches are stored in a list.
* "first_match" points to the start of the list.
* "curr_match" points to the currently selected entry.
* "shown_match" is different from curr_match during ins_compl_get_exp().
*/
static struct Completion *first_match = NULL;
static struct Completion *curr_match = NULL;
static struct Completion *shown_match = NULL;
static int started_completion = FALSE;
static int completion_matches = 0;
static char_u *complete_pat = NULL;
static int complete_direction = FORWARD;
static int shown_direction = FORWARD;
static int completion_pending = FALSE;
static pos_T initial_pos;
static colnr_T complete_col = 0; /* column where the text starts
that is being completed */
static int save_sm;
static char_u *original_text = NULL; /* text before completion */
static int continue_mode = 0;
static expand_T complete_xp;
static int ins_compl_add __ARGS((char_u *str, int len, char_u *, int dir, int reuse));
static void ins_compl_add_matches __ARGS((int num_matches, char_u **matches, int dir));
static int ins_compl_make_cyclic __ARGS((void));
static void ins_compl_dictionaries __ARGS((char_u *dict, char_u *pat, int dir, int flags, int thesaurus));
static void ins_compl_free __ARGS((void));
static void ins_compl_clear __ARGS((void));
static void ins_compl_prep __ARGS((int c));
static buf_T *ins_compl_next_buf __ARGS((buf_T *buf, int flag));
static int ins_compl_get_exp __ARGS((pos_T *ini, int dir));
static void ins_compl_delete __ARGS((void));
static void ins_compl_insert __ARGS((void));
static int ins_compl_next __ARGS((int allow_get_expansion));
static int ins_complete __ARGS((int c));
static int quote_meta __ARGS((char_u *dest, char_u *str, int len));
#endif /* FEAT_INS_EXPAND */
#define BACKSPACE_CHAR 1
#define BACKSPACE_WORD 2
#define BACKSPACE_WORD_NOT_SPACE 3
#define BACKSPACE_LINE 4
static void ins_redraw __ARGS((void));
static void ins_ctrl_v __ARGS((void));
static void undisplay_dollar __ARGS((void));
static void insert_special __ARGS((int, int, int));
static void check_auto_format __ARGS((int));
static void redo_literal __ARGS((int c));
static void start_arrow __ARGS((pos_T *end_insert_pos));
static void stop_insert __ARGS((pos_T *end_insert_pos, int esc));
static int echeck_abbr __ARGS((int));
static void replace_push_off __ARGS((int c));
static int replace_pop __ARGS((void));
static void replace_join __ARGS((int off));
static void replace_pop_ins __ARGS((void));
#ifdef FEAT_MBYTE
static void mb_replace_pop_ins __ARGS((int cc));
#endif
static void replace_flush __ARGS((void));
static void replace_do_bs __ARGS((void));
#ifdef FEAT_CINDENT
static int cindent_on __ARGS((void));
#endif
static void ins_reg __ARGS((void));
static void ins_ctrl_g __ARGS((void));
static int ins_esc __ARGS((long *count, int cmdchar));
#ifdef FEAT_RIGHTLEFT
static void ins_ctrl_ __ARGS((void));
#endif
#ifdef FEAT_VISUAL
static int ins_start_select __ARGS((int c));
#endif
static void ins_shift __ARGS((int c, int lastc));
static void ins_del __ARGS((void));
static int ins_bs __ARGS((int c, int mode, int *inserted_space_p));
#ifdef FEAT_MOUSE
static void ins_mouse __ARGS((int c));
static void ins_mousescroll __ARGS((int up));
#endif
static void ins_left __ARGS((void));
static void ins_home __ARGS((int c));
static void ins_end __ARGS((int c));
static void ins_s_left __ARGS((void));
static void ins_right __ARGS((void));
static void ins_s_right __ARGS((void));
static void ins_up __ARGS((int startcol));
static void ins_pageup __ARGS((void));
static void ins_down __ARGS((int startcol));
static void ins_pagedown __ARGS((void));
#ifdef FEAT_DND
static void ins_drop __ARGS((void));
#endif
static int ins_tab __ARGS((void));
static int ins_eol __ARGS((int c));
#ifdef FEAT_DIGRAPHS
static int ins_digraph __ARGS((void));
#endif
static int ins_copychar __ARGS((linenr_T lnum));
#ifdef FEAT_SMARTINDENT
static void ins_try_si __ARGS((int c));
#endif
static colnr_T get_nolist_virtcol __ARGS((void));
static colnr_T Insstart_textlen; /* length of line when insert started */
static colnr_T Insstart_blank_vcol; /* vcol for first inserted blank */
static char_u *last_insert = NULL; /* the text of the previous insert,
K_SPECIAL and CSI are escaped */
static int last_insert_skip; /* nr of chars in front of previous insert */
static int new_insert_skip; /* nr of chars in front of current insert */
#ifdef FEAT_CINDENT
static int can_cindent; /* may do cindenting on this line */
#endif
static int old_indent = 0; /* for ^^D command in insert mode */
#ifdef FEAT_RIGHTLEFT
int revins_on; /* reverse insert mode on */
int revins_chars; /* how much to skip after edit */
int revins_legal; /* was the last char 'legal'? */
int revins_scol; /* start column of revins session */
#endif
#if defined(FEAT_MBYTE) && defined(MACOS_CLASSIC)
static short previous_script = smRoman;
#endif
static int ins_need_undo; /* call u_save() before inserting a
char. Set when edit() is called.
after that arrow_used is used. */
static int did_add_space = FALSE; /* auto_format() added an extra space
under the cursor */
/*
* edit(): Start inserting text.
*
* "cmdchar" can be:
* 'i' normal insert command
* 'a' normal append command
* 'R' replace command
* 'r' "r<CR>" command: insert one <CR>. Note: count can be > 1, for redo,
* but still only one <CR> is inserted. The <Esc> is not used for redo.
* 'g' "gI" command.
* 'V' "gR" command for Virtual Replace mode.
* 'v' "gr" command for single character Virtual Replace mode.
*
* This function is not called recursively. For CTRL-O commands, it returns
* and lets the caller handle the Normal-mode command.
*
* Return TRUE if a CTRL-O command caused the return (insert mode pending).
*/
int
edit(cmdchar, startln, count)
int cmdchar;
int startln; /* if set, insert at start of line */
long count;
{
int c = 0;
char_u *ptr;
int lastc;
colnr_T mincol;
static linenr_T o_lnum = 0;
static int o_eol = FALSE;
int i;
int did_backspace = TRUE; /* previous char was backspace */
#ifdef FEAT_CINDENT
int line_is_white = FALSE; /* line is empty before insert */
#endif
linenr_T old_topline = 0; /* topline before insertion */
#ifdef FEAT_DIFF
int old_topfill = -1;
#endif
int inserted_space = FALSE; /* just inserted a space */
int replaceState = REPLACE;
int did_restart_edit = restart_edit;
/* sleep before redrawing, needed for "CTRL-O :" that results in an
* error message */
check_for_delay(TRUE);
#ifdef HAVE_SANDBOX
/* Don't allow inserting in the sandbox. */
if (sandbox != 0)
{
EMSG(_(e_sandbox));
return FALSE;
}
#endif
#ifdef FEAT_INS_EXPAND
ins_compl_clear(); /* clear stuff for CTRL-X mode */
#endif
#ifdef FEAT_MOUSE
/*
* When doing a paste with the middle mouse button, Insstart is set to
* where the paste started.
*/
if (where_paste_started.lnum != 0)
Insstart = where_paste_started;
else
#endif
{
Insstart = curwin->w_cursor;
if (startln)
Insstart.col = 0;
}
Insstart_textlen = linetabsize(ml_get_curline());
Insstart_blank_vcol = MAXCOL;
if (!did_ai)
ai_col = 0;
if (cmdchar != NUL && restart_edit == 0)
{
ResetRedobuff();
AppendNumberToRedobuff(count);
#ifdef FEAT_VREPLACE
if (cmdchar == 'V' || cmdchar == 'v')
{
/* "gR" or "gr" command */
AppendCharToRedobuff('g');
AppendCharToRedobuff((cmdchar == 'v') ? 'r' : 'R');
}
else
#endif
{
AppendCharToRedobuff(cmdchar);
if (cmdchar == 'g') /* "gI" command */
AppendCharToRedobuff('I');
else if (cmdchar == 'r') /* "r<CR>" command */
count = 1; /* insert only one <CR> */
}
}
if (cmdchar == 'R')
{
#ifdef FEAT_FKMAP
if (p_fkmap && p_ri)
{
beep_flush();
EMSG(farsi_text_3); /* encoded in Farsi */
State = INSERT;
}
else
#endif
State = REPLACE;
}
#ifdef FEAT_VREPLACE
else if (cmdchar == 'V' || cmdchar == 'v')
{
State = VREPLACE;
replaceState = VREPLACE;
orig_line_count = curbuf->b_ml.ml_line_count;
vr_lines_changed = 1;
}
#endif
else
State = INSERT;
stop_insert_mode = FALSE;
/*
* Need to recompute the cursor position, it might move when the cursor is
* on a TAB or special character.
*/
curs_columns(TRUE);
/*
* Enable langmap or IME, indicated by 'iminsert'.
* Note that IME may enabled/disabled without us noticing here, thus the
* 'iminsert' value may not reflect what is actually used. It is updated
* when hitting <Esc>.
*/
if (curbuf->b_p_iminsert == B_IMODE_LMAP)
State |= LANGMAP;
#ifdef USE_IM_CONTROL
im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
#endif
#if defined(FEAT_MBYTE) && defined(MACOS_CLASSIC)
KeyScript(previous_script);
#endif
#ifdef FEAT_MOUSE
setmouse();
#endif
#ifdef FEAT_CMDL_INFO
clear_showcmd();
#endif
#ifdef FEAT_RIGHTLEFT
/* there is no reverse replace mode */
revins_on = (State == INSERT && p_ri);
if (revins_on)
undisplay_dollar();
revins_chars = 0;
revins_legal = 0;
revins_scol = -1;
#endif
/*
* Handle restarting Insert mode.
* Don't do this for "CTRL-O ." (repeat an insert): we get here with
* restart_edit non-zero, and something in the stuff buffer.
*/
if (restart_edit != 0 && stuff_empty())
{
#ifdef FEAT_MOUSE
/*
* After a paste we consider text typed to be part of the insert for
* the pasted text. You can backspace over the pasted text too.
*/
if (where_paste_started.lnum)
arrow_used = FALSE;
else
#endif
arrow_used = TRUE;
restart_edit = 0;
/*
* If the cursor was after the end-of-line before the CTRL-O and it is
* now at the end-of-line, put it after the end-of-line (this is not
* correct in very rare cases).
* Also do this if curswant is greater than the current virtual
* column. Eg after "^O$" or "^O80|".
*/
validate_virtcol();
update_curswant();
if (((o_eol && curwin->w_cursor.lnum == o_lnum)
|| curwin->w_curswant > curwin->w_virtcol)
&& *(ptr = ml_get_curline() + curwin->w_cursor.col) != NUL)
{
if (ptr[1] == NUL)
++curwin->w_cursor.col;
#ifdef FEAT_MBYTE
else if (has_mbyte)
{
i = (*mb_ptr2len_check)(ptr);
if (ptr[i] == NUL)
curwin->w_cursor.col += i;
}
#endif
}
o_eol = FALSE;
}
else
arrow_used = FALSE;
/* we are in insert mode now, don't need to start it anymore */
need_start_insertmode = FALSE;
/* Need to save the line for undo before inserting the first char. */
ins_need_undo = TRUE;
#ifdef FEAT_MOUSE
where_paste_started.lnum = 0;
#endif
#ifdef FEAT_CINDENT
can_cindent = TRUE;
#endif
#ifdef FEAT_FOLDING
/* The cursor line is not in a closed fold, unless 'insertmode' is set or
* restarting. */
if (!p_im && did_restart_edit == 0)
foldOpenCursor();
#endif
/*
* If 'showmode' is set, show the current (insert/replace/..) mode.
* A warning message for changing a readonly file is given here, before
* actually changing anything. It's put after the mode, if any.
*/
i = 0;
if (p_smd)
i = showmode();
if (!p_im && did_restart_edit == 0)
change_warning(i + 1);
#ifdef CURSOR_SHAPE
ui_cursor_shape(); /* may show different cursor shape */
#endif
#ifdef FEAT_DIGRAPHS
do_digraph(-1); /* clear digraphs */
#endif
/*
* Get the current length of the redo buffer, those characters have to be
* skipped if we want to get to the inserted characters.
*/
ptr = get_inserted();
if (ptr == NULL)
new_insert_skip = 0;
else
{
new_insert_skip = (int)STRLEN(ptr);
vim_free(ptr);
}
old_indent = 0;
/*
* Main loop in Insert mode: repeat until Insert mode is left.
*/
for (;;)
{
#ifdef FEAT_RIGHTLEFT
if (!revins_legal)
revins_scol = -1; /* reset on illegal motions */
else
revins_legal = 0;
#endif
if (arrow_used) /* don't repeat insert when arrow key used */
count = 0;
if (stop_insert_mode)
{
/* ":stopinsert" used or 'insertmode' reset */
count = 0;
goto doESCkey;
}
/* set curwin->w_curswant for next K_DOWN or K_UP */
if (!arrow_used)
curwin->w_set_curswant = TRUE;
/* If there is no typeahead may check for timestamps (e.g., for when a
* menu invoked a shell command). */
if (stuff_empty())
{
did_check_timestamps = FALSE;
if (need_check_timestamps)
check_timestamps(FALSE);
}
/*
* When emsg() was called msg_scroll will have been set.
*/
msg_scroll = FALSE;
#ifdef FEAT_GUI
/* When 'mousefocus' is set a mouse movement may have taken us to
* another window. "need_mouse_correct" may then be set because of an
* autocommand. */
if (need_mouse_correct)
gui_mouse_correct();
#endif
#ifdef FEAT_FOLDING
/* Open fold at the cursor line, according to 'foldopen'. */
if (fdo_flags & FDO_INSERT)
foldOpenCursor();
/* Close folds where the cursor isn't, according to 'foldclose' */
if (!char_avail())
foldCheckClose();
#endif
/*
* If we inserted a character at the last position of the last line in
* the window, scroll the window one line up. This avoids an extra
* redraw.
* This is detected when the cursor column is smaller after inserting
* something.
* Don't do this when the topline changed already, it has
* already been adjusted (by insertchar() calling open_line())).
*/
if (curbuf->b_mod_set
&& curwin->w_p_wrap
&& !did_backspace
&& curwin->w_topline == old_topline
#ifdef FEAT_DIFF
&& curwin->w_topfill == old_topfill
#endif
)
{
mincol = curwin->w_wcol;
validate_cursor_col();
if ((int)curwin->w_wcol < (int)mincol - curbuf->b_p_ts
&& curwin->w_wrow == W_WINROW(curwin)
+ curwin->w_height - 1 - p_so
&& (curwin->w_cursor.lnum != curwin->w_topline
#ifdef FEAT_DIFF
|| curwin->w_topfill > 0
#endif
))
{
#ifdef FEAT_DIFF
if (curwin->w_topfill > 0)
--curwin->w_topfill;
else
#endif
#ifdef FEAT_FOLDING
if (hasFolding(curwin->w_topline, NULL, &old_topline))
set_topline(curwin, old_topline + 1);
else
#endif
set_topline(curwin, curwin->w_topline + 1);
}
}
/* May need to adjust w_topline to show the cursor. */
update_topline();
did_backspace = FALSE;
validate_cursor(); /* may set must_redraw */
/*
* Redraw the display when no characters are waiting.
* Also shows mode, ruler and positions cursor.
*/
ins_redraw();
#ifdef FEAT_SCROLLBIND
if (curwin->w_p_scb)
do_check_scrollbind(TRUE);
#endif
update_curswant();
old_topline = curwin->w_topline;
#ifdef FEAT_DIFF
old_topfill = curwin->w_topfill;
#endif
#ifdef USE_ON_FLY_SCROLL
dont_scroll = FALSE; /* allow scrolling here */
#endif
/*
* Get a character for Insert mode.
*/
lastc = c; /* remember previous char for CTRL-D */
c = safe_vgetc();
#ifdef FEAT_RIGHTLEFT
if (p_hkmap && KeyTyped)
c = hkmap(c); /* Hebrew mode mapping */
#endif
#ifdef FEAT_FKMAP
if (p_fkmap && KeyTyped)
c = fkmap(c); /* Farsi mode mapping */
#endif
#ifdef FEAT_INS_EXPAND
/* Prepare for or stop CTRL-X mode. This doesn't do completion, but
* it does fix up the text when finishing completion. */
ins_compl_prep(c);
#endif
/* CTRL-\ CTRL-N goes to Normal mode, CTRL-\ CTRL-G goes to mode
* selected with 'insertmode'. */
if (c == Ctrl_BSL)
{
/* may need to redraw when no more chars available now */
ins_redraw();
++no_mapping;
++allow_keys;
c = safe_vgetc();
--no_mapping;
--allow_keys;
if (c != Ctrl_N && c != Ctrl_G) /* it's something else */
{
vungetc(c);
c = Ctrl_BSL;
}
else if (c == Ctrl_G && p_im)
continue;
else
{
count = 0;
goto doESCkey;
}
}
#ifdef FEAT_DIGRAPHS
c = do_digraph(c);
#endif
#ifdef FEAT_INS_EXPAND
if ((c == Ctrl_V || c == Ctrl_Q) && ctrl_x_mode == CTRL_X_CMDLINE)
goto docomplete;
#endif
if (c == Ctrl_V || c == Ctrl_Q)
{
ins_ctrl_v();
c = Ctrl_V; /* pretend CTRL-V is last typed character */
continue;
}
#ifdef FEAT_CINDENT
if (cindent_on()
# ifdef FEAT_INS_EXPAND
&& ctrl_x_mode == 0
# endif
)
{
/* A key name preceded by a bang means this key is not to be
* inserted. Skip ahead to the re-indenting below.
* A key name preceded by a star means that indenting has to be
* done before inserting the key. */
line_is_white = inindent(0);
if (in_cinkeys(c, '!', line_is_white))
goto force_cindent;
if (can_cindent && in_cinkeys(c, '*', line_is_white)
&& stop_arrow() == OK)
do_c_expr_indent();
}
#endif
#ifdef FEAT_RIGHTLEFT
if (curwin->w_p_rl)
switch (c)
{
case K_LEFT: c = K_RIGHT; break;
case K_S_LEFT: c = K_S_RIGHT; break;
case K_C_LEFT: c = K_C_RIGHT; break;
case K_RIGHT: c = K_LEFT; break;
case K_S_RIGHT: c = K_S_LEFT; break;
case K_C_RIGHT: c = K_C_LEFT; break;
}
#endif
#ifdef FEAT_VISUAL
/*
* If 'keymodel' contains "startsel", may start selection. If it
* does, a CTRL-O and c will be stuffed, we need to get these
* characters.
*/
if (ins_start_select(c))
continue;
#endif
/*
* The big switch to handle a character in insert mode.
*/
switch (c)
{
/* toggle insert/replace mode */
case K_INS:
case K_KINS:
#ifdef FEAT_FKMAP
if (p_fkmap && p_ri)
{
beep_flush();
EMSG(farsi_text_3); /* encoded in Farsi */
break;
}
#endif
if (State & REPLACE_FLAG)
State = INSERT | (State & LANGMAP);
else
State = replaceState | (State & LANGMAP);
AppendCharToRedobuff(K_INS);
showmode();
#ifdef CURSOR_SHAPE
ui_cursor_shape(); /* may show different cursor shape */
#endif
break;
#ifdef FEAT_INS_EXPAND
/* Enter CTRL-X mode */
case Ctrl_X:
/* CTRL-X after CTRL-V CTRL-X doesn't do anything, so that CTRL-X
* CTRL-V works like CTRL-N */
if (ctrl_x_mode != CTRL_X_CMDLINE)
{
/* if the next ^X<> won't ADD nothing, then reset
* continue_status */
if (continue_status & CONT_N_ADDS)
continue_status = (continue_status | CONT_INTRPT);
else
continue_status = 0;
/* We're not sure which CTRL-X mode it will be yet */
ctrl_x_mode = CTRL_X_NOT_DEFINED_YET;
edit_submode = (char_u *)_(CTRL_X_MSG(ctrl_x_mode));
edit_submode_pre = NULL;
showmode();
}
break;
#endif
/* end of Select mode mapping - ignore */
case K_SELECT:
break;
/* suspend when 'insertmode' set */
case Ctrl_Z:
if (!p_im)
goto normalchar; /* insert CTRL-Z as normal char */
stuffReadbuff((char_u *)":st\r");
c = Ctrl_O;
/*FALLTHROUGH*/
/* execute one command */
case Ctrl_O:
if (echeck_abbr(Ctrl_O + ABBR_OFF))
break;
count = 0;
#ifdef FEAT_VREPLACE
if (State & VREPLACE_FLAG)
restart_edit = 'V';
else
#endif
if (State & REPLACE_FLAG)
restart_edit = 'R';
else
restart_edit = 'I';
#ifdef FEAT_VIRTUALEDIT
if (virtual_active())
o_eol = FALSE; /* cursor always keeps its column */
else
#endif
o_eol = (gchar_cursor() == NUL);
goto doESCkey;
#ifdef FEAT_SNIFF
case K_SNIFF:
stuffcharReadbuff(K_SNIFF);
goto doESCkey;
#endif
/* Hitting the help key in insert mode is like <ESC> <Help> */
case K_HELP:
case K_F1:
case K_XF1:
stuffcharReadbuff(K_HELP);
if (p_im)
need_start_insertmode = TRUE;
goto doESCkey;
#ifdef FEAT_NETBEANS_INTG
case K_F21:
++no_mapping; /* don't map the next key hits */
i = safe_vgetc();
--no_mapping;
netbeans_keycommand(i);
break;
#endif
/* an escape ends input mode */
case ESC:
if (echeck_abbr(ESC + ABBR_OFF))
break;
/*FALLTHROUGH*/
case Ctrl_C:
#ifdef FEAT_CMDWIN
if (c == Ctrl_C && cmdwin_type != 0)
{
/* Close the cmdline window. */
cmdwin_result = K_IGNORE;
got_int = FALSE; /* don't stop executing autocommands et al. */
goto doESCkey;
}
#endif
#ifdef UNIX
do_intr:
#endif
/* when 'insertmode' set, and not halfway a mapping, don't leave
* Insert mode */
if (goto_im())
{
if (got_int)
{
(void)vgetc(); /* flush all buffers */
got_int = FALSE;
}
else
vim_beep();
break;
}
doESCkey:
/*
* This is the ONLY return from edit()!
*/
/* Always update o_lnum, so that a "CTRL-O ." that adds a line
* still puts the cursor back after the inserted text. */
if (o_eol && gchar_cursor() == NUL)
o_lnum = curwin->w_cursor.lnum;
if (ins_esc(&count, cmdchar))
return (c == Ctrl_O);
continue;
/*
* Insert the previously inserted text.
* For ^@ the trailing ESC will end the insert, unless there is an
* error.
*/
case K_ZERO:
case NUL:
case Ctrl_A:
if (stuff_inserted(NUL, 1L, (c == Ctrl_A)) == FAIL
&& c != Ctrl_A && !p_im)
goto doESCkey; /* quit insert mode */
inserted_space = FALSE;
break;
/* insert the contents of a register */
case Ctrl_R:
ins_reg();
auto_format(FALSE, TRUE);
inserted_space = FALSE;
break;
case Ctrl_G:
ins_ctrl_g();
break;
case Ctrl_HAT:
if (map_to_exists_mode((char_u *)"", LANGMAP))
{
/* ":lmap" mappings exists, Toggle use of ":lmap" mappings. */
if (State & LANGMAP)
{
curbuf->b_p_iminsert = B_IMODE_NONE;
State &= ~LANGMAP;
}
else
{
curbuf->b_p_iminsert = B_IMODE_LMAP;
State |= LANGMAP;
#ifdef USE_IM_CONTROL
im_set_active(FALSE);
#endif
}
}
#ifdef USE_IM_CONTROL
else
{
/* There are no ":lmap" mappings, toggle IM */
if (im_get_status())
{
curbuf->b_p_iminsert = B_IMODE_NONE;
im_set_active(FALSE);
}
else
{
curbuf->b_p_iminsert = B_IMODE_IM;
State &= ~LANGMAP;
im_set_active(TRUE);
}
}
#endif
set_iminsert_global();
showmode();
#ifdef FEAT_GUI
/* may show different cursor shape or color */
if (gui.in_use)
gui_update_cursor(TRUE, FALSE);
#endif
#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
/* Show/unshow value of 'keymap' in status lines. */
status_redraw_curbuf();
#endif
break;
#ifdef FEAT_RIGHTLEFT
case Ctrl__:
if (!p_ari)
goto normalchar;
ins_ctrl_();
break;
#endif
/* Make indent one shiftwidth smaller. */
case Ctrl_D:
#if defined(FEAT_INS_EXPAND) && defined(FEAT_FIND_ID)
if (ctrl_x_mode == CTRL_X_PATH_DEFINES)
goto docomplete;
#endif
/* FALLTHROUGH */
/* Make indent one shiftwidth greater. */
case Ctrl_T:
# ifdef FEAT_INS_EXPAND
if (c == Ctrl_T && ctrl_x_mode == CTRL_X_THESAURUS)
{
if (*curbuf->b_p_tsr == NUL && *p_tsr == NUL)
{
ctrl_x_mode = 0;
msg_attr((char_u *)_("'thesaurus' option is empty"),
hl_attr(HLF_E));
if (emsg_silent == 0)
{
vim_beep();
setcursor();
out_flush();
ui_delay(2000L, FALSE);
}
break;
}
goto docomplete;
}
# endif
ins_shift(c, lastc);
auto_format(FALSE, TRUE);
inserted_space = FALSE;
break;
/* delete character under the cursor */
case K_DEL:
case K_KDEL:
ins_del();
auto_format(FALSE, TRUE);
break;
/* delete character before the cursor */
case K_BS:
case Ctrl_H:
did_backspace = ins_bs(c, BACKSPACE_CHAR, &inserted_space);
auto_format(FALSE, TRUE);
break;
/* delete word before the cursor */
case Ctrl_W:
did_backspace = ins_bs(c, BACKSPACE_WORD, &inserted_space);
auto_format(FALSE, TRUE);
break;