annotate src/edit.c @ 1395:c845dcf7fafa v7.1.110

updated for version 7.1-110
author vimboss
date Sat, 15 Sep 2007 12:49:35 +0000
parents bdcfe793d49f
children 342cf2a9f5cc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 * edit.c: functions for Insert mode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 * definitions used for CTRL-X submode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 #define CTRL_X_WANT_IDENT 0x100
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 #define CTRL_X_NOT_DEFINED_YET 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 #define CTRL_X_SCROLL 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 #define CTRL_X_WHOLE_LINE 3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 #define CTRL_X_FILES 4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 #define CTRL_X_TAGS (5 + CTRL_X_WANT_IDENT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 #define CTRL_X_PATH_PATTERNS (6 + CTRL_X_WANT_IDENT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 #define CTRL_X_PATH_DEFINES (7 + CTRL_X_WANT_IDENT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 #define CTRL_X_FINISHED 8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 #define CTRL_X_DICTIONARY (9 + CTRL_X_WANT_IDENT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 #define CTRL_X_THESAURUS (10 + CTRL_X_WANT_IDENT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 #define CTRL_X_CMDLINE 11
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
33 #define CTRL_X_FUNCTION 12
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
34 #define CTRL_X_OMNI 13
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
35 #define CTRL_X_SPELL 14
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
36 #define CTRL_X_LOCAL_MSG 15 /* only used in "ctrl_x_msgs" */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 #define CTRL_X_MSG(i) ctrl_x_msgs[(i) & ~CTRL_X_WANT_IDENT]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 static char *ctrl_x_msgs[] =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 N_(" Keyword completion (^N^P)"), /* ctrl_x_mode == 0, ^P/^N compl. */
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
43 N_(" ^X mode (^]^D^E^F^I^K^L^N^O^Ps^U^V^Y)"),
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
44 NULL,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 N_(" Whole line completion (^L^N^P)"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 N_(" File name completion (^F^N^P)"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 N_(" Tag completion (^]^N^P)"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 N_(" Path pattern completion (^N^P)"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 N_(" Definition completion (^D^N^P)"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 N_(" Dictionary completion (^K^N^P)"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 N_(" Thesaurus completion (^T^N^P)"),
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
53 N_(" Command-line completion (^V^N^P)"),
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
54 N_(" User defined completion (^U^N^P)"),
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
55 N_(" Omni completion (^O^N^P)"),
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
56 N_(" Spelling suggestion (s^N^P)"),
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
57 N_(" Keyword Local completion (^N^P)"),
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 static char_u e_hitend[] = N_("Hit end of paragraph");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 * Structure used to store one match for insert completion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 */
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
65 typedef struct compl_S compl_T;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
66 struct compl_S
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
68 compl_T *cp_next;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
69 compl_T *cp_prev;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
70 char_u *cp_str; /* matched text */
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
71 char cp_icase; /* TRUE or FALSE: ignore case */
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
72 char_u *(cp_text[CPT_COUNT]); /* text for the menu */
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
73 char_u *cp_fname; /* file containing the match, allocated when
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
74 * cp_flags has FREE_FNAME */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
75 int cp_flags; /* ORIGINAL_TEXT, CONT_S_IPOS or FREE_FNAME */
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
76 int cp_number; /* sequence number */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
79 #define ORIGINAL_TEXT (1) /* the original text when the expansion begun */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 #define FREE_FNAME (2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 * All the current matches are stored in a list.
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
84 * "compl_first_match" points to the start of the list.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
85 * "compl_curr_match" points to the currently selected entry.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
86 * "compl_shown_match" is different from compl_curr_match during
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
87 * ins_compl_get_exp().
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
89 static compl_T *compl_first_match = NULL;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
90 static compl_T *compl_curr_match = NULL;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
91 static compl_T *compl_shown_match = NULL;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
92
825
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
93 /* After using a cursor key <Enter> selects a match in the popup menu,
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
94 * otherwise it inserts a line break. */
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
95 static int compl_enter_selects = FALSE;
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
96
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
97 /* When "compl_leader" is not NULL only matches that start with this string
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
98 * are used. */
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
99 static char_u *compl_leader = NULL;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
100
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
101 static int compl_get_longest = FALSE; /* put longest common string
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
102 in compl_leader */
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
103
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
104 static int compl_used_match; /* Selected one of the matches. When
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
105 FALSE the match was edited or using
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
106 the longest common string. */
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
107
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
108 static int compl_was_interrupted = FALSE; /* didn't finish finding
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
109 completions. */
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
110
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
111 static int compl_restarting = FALSE; /* don't insert match */
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
112
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
113 /* When the first completion is done "compl_started" is set. When it's
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
114 * FALSE the word to be completed must be located. */
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
115 static int compl_started = FALSE;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
116
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
117 static int compl_matches = 0;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
118 static char_u *compl_pattern = NULL;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
119 static int compl_direction = FORWARD;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
120 static int compl_shows_dir = FORWARD;
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
121 static int compl_pending = 0; /* > 1 for postponed CTRL-N */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
122 static pos_T compl_startpos;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
123 static colnr_T compl_col = 0; /* column where the text starts
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
124 * that is being completed */
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
125 static char_u *compl_orig_text = NULL; /* text as it was before
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
126 * completion started */
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
127 static int compl_cont_mode = 0;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
128 static expand_T compl_xp;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
129
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
130 static void ins_ctrl_x __ARGS((void));
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
131 static int has_compl_option __ARGS((int dict_opt));
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
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 adup));
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
133 static int ins_compl_equal __ARGS((compl_T *match, char_u *str, int len));
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
134 static void ins_compl_longest_match __ARGS((compl_T *match));
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
135 static void ins_compl_add_matches __ARGS((int num_matches, char_u **matches, int icase));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 static int ins_compl_make_cyclic __ARGS((void));
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
137 static void ins_compl_upd_pum __ARGS((void));
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
138 static void ins_compl_del_pum __ARGS((void));
648
9032e4668296 updated for version 7.0189
vimboss
parents: 644
diff changeset
139 static int pum_wanted __ARGS((void));
707
111b7dcc8a17 updated for version 7.0213
vimboss
parents: 703
diff changeset
140 static int pum_enough_matches __ARGS((void));
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
141 static void ins_compl_dictionaries __ARGS((char_u *dict, char_u *pat, int flags, int thesaurus));
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
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
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
143 static char_u *find_line_end __ARGS((char_u *ptr));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 static void ins_compl_free __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 static void ins_compl_clear __ARGS((void));
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
146 static int ins_compl_bs __ARGS((void));
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
147 static void ins_compl_new_leader __ARGS((void));
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
148 static void ins_compl_addleader __ARGS((int c));
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
149 static void ins_compl_restart __ARGS((void));
694
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
150 static void ins_compl_set_original_text __ARGS((char_u *str));
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
151 static void ins_compl_addfrommatch __ARGS((void));
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
152 static int ins_compl_prep __ARGS((int c));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 static buf_T *ins_compl_next_buf __ARGS((buf_T *buf, int flag));
724
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
154 #if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL)
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
155 static void ins_compl_add_list __ARGS((list_T *list));
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
156 #endif
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
157 static int ins_compl_get_exp __ARGS((pos_T *ini));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 static void ins_compl_delete __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 static void ins_compl_insert __ARGS((void));
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
160 static int ins_compl_next __ARGS((int allow_get_expansion, int count, int insert_match));
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
161 static int ins_compl_key2dir __ARGS((int c));
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
162 static int ins_compl_pum_key __ARGS((int c));
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
163 static int ins_compl_key2count __ARGS((int c));
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
164 static int ins_compl_use_match __ARGS((int c));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 static int ins_complete __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 static int quote_meta __ARGS((char_u *dest, char_u *str, int len));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 #endif /* FEAT_INS_EXPAND */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 #define BACKSPACE_CHAR 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 #define BACKSPACE_WORD 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 #define BACKSPACE_WORD_NOT_SPACE 3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 #define BACKSPACE_LINE 4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
174 static void ins_redraw __ARGS((int ready));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 static void ins_ctrl_v __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 static void undisplay_dollar __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 static void insert_special __ARGS((int, int, int));
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
178 static void internal_format __ARGS((int textwidth, int second_indent, int flags, int format_only));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 static void check_auto_format __ARGS((int));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 static void redo_literal __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 static void start_arrow __ARGS((pos_T *end_insert_pos));
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
182 #ifdef FEAT_SPELL
221
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
183 static void check_spell_redraw __ARGS((void));
484
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
184 static void spell_back_to_badword __ARGS((void));
497
73f10d8124f4 updated for version 7.0136
vimboss
parents: 484
diff changeset
185 static int spell_bad_len = 0; /* length of located bad word */
221
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
186 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 static void stop_insert __ARGS((pos_T *end_insert_pos, int esc));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 static int echeck_abbr __ARGS((int));
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
189 #if 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 static void replace_push_off __ARGS((int c));
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
191 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 static int replace_pop __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 static void replace_join __ARGS((int off));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 static void replace_pop_ins __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 static void mb_replace_pop_ins __ARGS((int cc));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 static void replace_flush __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 static void replace_do_bs __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 static int cindent_on __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 static void ins_reg __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 static void ins_ctrl_g __ARGS((void));
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
205 static void ins_ctrl_hat __ARGS((void));
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
206 static int ins_esc __ARGS((long *count, int cmdchar, int nomove));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 static void ins_ctrl_ __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 #ifdef FEAT_VISUAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 static int ins_start_select __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 #endif
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
213 static void ins_insert __ARGS((int replaceState));
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
214 static void ins_ctrl_o __ARGS((void));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 static void ins_shift __ARGS((int c, int lastc));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 static void ins_del __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 static int ins_bs __ARGS((int c, int mode, int *inserted_space_p));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 static void ins_mouse __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 static void ins_mousescroll __ARGS((int up));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 #endif
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
222 #if defined(FEAT_GUI_TABLINE) || defined(PROTO)
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
223 static void ins_tabline __ARGS((int c));
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
224 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 static void ins_left __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 static void ins_home __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 static void ins_end __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 static void ins_s_left __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 static void ins_right __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 static void ins_s_right __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 static void ins_up __ARGS((int startcol));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 static void ins_pageup __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 static void ins_down __ARGS((int startcol));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 static void ins_pagedown __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 #ifdef FEAT_DND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 static void ins_drop __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 static int ins_tab __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 static int ins_eol __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 #ifdef FEAT_DIGRAPHS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 static int ins_digraph __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 static int ins_copychar __ARGS((linenr_T lnum));
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
244 static int ins_ctrl_ey __ARGS((int tc));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 static void ins_try_si __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 static colnr_T get_nolist_virtcol __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 static colnr_T Insstart_textlen; /* length of line when insert started */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 static colnr_T Insstart_blank_vcol; /* vcol for first inserted blank */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 static char_u *last_insert = NULL; /* the text of the previous insert,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 K_SPECIAL and CSI are escaped */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 static int last_insert_skip; /* nr of chars in front of previous insert */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 static int new_insert_skip; /* nr of chars in front of current insert */
603
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
257 static int did_restart_edit; /* "restart_edit" when calling edit() */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 static int can_cindent; /* may do cindenting on this line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 static int old_indent = 0; /* for ^^D command in insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 #ifdef FEAT_RIGHTLEFT
298
f9de3e679a04 updated for version 7.0078
vimboss
parents: 278
diff changeset
266 static int revins_on; /* reverse insert mode on */
f9de3e679a04 updated for version 7.0078
vimboss
parents: 278
diff changeset
267 static int revins_chars; /* how much to skip after edit */
f9de3e679a04 updated for version 7.0078
vimboss
parents: 278
diff changeset
268 static int revins_legal; /* was the last char 'legal'? */
f9de3e679a04 updated for version 7.0078
vimboss
parents: 278
diff changeset
269 static int revins_scol; /* start column of revins session */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 static int ins_need_undo; /* call u_save() before inserting a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 char. Set when edit() is called.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 after that arrow_used is used. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 static int did_add_space = FALSE; /* auto_format() added an extra space
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 under the cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 * edit(): Start inserting text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 * "cmdchar" can be:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 * 'i' normal insert command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 * 'a' normal append command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 * 'R' replace command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 * 'r' "r<CR>" command: insert one <CR>. Note: count can be > 1, for redo,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 * but still only one <CR> is inserted. The <Esc> is not used for redo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 * 'g' "gI" command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 * 'V' "gR" command for Virtual Replace mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 * 'v' "gr" command for single character Virtual Replace mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 * This function is not called recursively. For CTRL-O commands, it returns
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 * and lets the caller handle the Normal-mode command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 * Return TRUE if a CTRL-O command caused the return (insert mode pending).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 edit(cmdchar, startln, count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 int cmdchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300 int startln; /* if set, insert at start of line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 long count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 int c = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 int lastc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 colnr_T mincol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 static linenr_T o_lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 int did_backspace = TRUE; /* previous char was backspace */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 int line_is_white = FALSE; /* line is empty before insert */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 linenr_T old_topline = 0; /* topline before insertion */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 int old_topfill = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 int inserted_space = FALSE; /* just inserted a space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 int replaceState = REPLACE;
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
319 int nomove = FALSE; /* don't move cursor on return */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320
603
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
321 /* Remember whether editing was restarted after CTRL-O. */
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
322 did_restart_edit = restart_edit;
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
323
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 /* sleep before redrawing, needed for "CTRL-O :" that results in an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 * error message */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 check_for_delay(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 #ifdef HAVE_SANDBOX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 /* Don't allow inserting in the sandbox. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 if (sandbox != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 EMSG(_(e_sandbox));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 #endif
632
b6632d553df3 updated for version 7.0182
vimboss
parents: 626
diff changeset
336 /* Don't allow changes in the buffer while editing the cmdline. The
b6632d553df3 updated for version 7.0182
vimboss
parents: 626
diff changeset
337 * caller of getcmdline() may get confused. */
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 632
diff changeset
338 if (textlock != 0)
632
b6632d553df3 updated for version 7.0182
vimboss
parents: 626
diff changeset
339 {
b6632d553df3 updated for version 7.0182
vimboss
parents: 626
diff changeset
340 EMSG(_(e_secure));
b6632d553df3 updated for version 7.0182
vimboss
parents: 626
diff changeset
341 return FALSE;
b6632d553df3 updated for version 7.0182
vimboss
parents: 626
diff changeset
342 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 #ifdef FEAT_INS_EXPAND
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
345 /* Don't allow recursive insert mode when busy with completion. */
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
346 if (compl_started || pum_visible())
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
347 {
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
348 EMSG(_(e_secure));
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
349 return FALSE;
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
350 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 ins_compl_clear(); /* clear stuff for CTRL-X mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353
11
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
354 #ifdef FEAT_AUTOCMD
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
355 /*
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
356 * Trigger InsertEnter autocommands. Do not do this for "r<CR>" or "grx".
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
357 */
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
358 if (cmdchar != 'r' && cmdchar != 'v')
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
359 {
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 523
diff changeset
360 # ifdef FEAT_EVAL
11
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
361 if (cmdchar == 'R')
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
362 ptr = (char_u *)"r";
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
363 else if (cmdchar == 'V')
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
364 ptr = (char_u *)"v";
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
365 else
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
366 ptr = (char_u *)"i";
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
367 set_vim_var_string(VV_INSERTMODE, ptr, 1);
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 523
diff changeset
368 # endif
11
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
369 apply_autocmds(EVENT_INSERTENTER, NULL, NULL, FALSE, curbuf);
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
370 }
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
371 #endif
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
372
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 * When doing a paste with the middle mouse button, Insstart is set to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 * where the paste started.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 if (where_paste_started.lnum != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 Insstart = where_paste_started;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 Insstart = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384 if (startln)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 Insstart.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 Insstart_textlen = linetabsize(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 Insstart_blank_vcol = MAXCOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 if (!did_ai)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 ai_col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 if (cmdchar != NUL && restart_edit == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 ResetRedobuff();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395 AppendNumberToRedobuff(count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 if (cmdchar == 'V' || cmdchar == 'v')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 /* "gR" or "gr" command */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 AppendCharToRedobuff('g');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401 AppendCharToRedobuff((cmdchar == 'v') ? 'r' : 'R');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406 AppendCharToRedobuff(cmdchar);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 if (cmdchar == 'g') /* "gI" command */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 AppendCharToRedobuff('I');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409 else if (cmdchar == 'r') /* "r<CR>" command */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 count = 1; /* insert only one <CR> */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 if (cmdchar == 'R')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 #ifdef FEAT_FKMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 if (p_fkmap && p_ri)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 beep_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 EMSG(farsi_text_3); /* encoded in Farsi */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 State = INSERT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 State = REPLACE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428 else if (cmdchar == 'V' || cmdchar == 'v')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430 State = VREPLACE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431 replaceState = VREPLACE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432 orig_line_count = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 vr_lines_changed = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 State = INSERT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439 stop_insert_mode = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 * Need to recompute the cursor position, it might move when the cursor is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443 * on a TAB or special character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445 curs_columns(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448 * Enable langmap or IME, indicated by 'iminsert'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449 * Note that IME may enabled/disabled without us noticing here, thus the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450 * 'iminsert' value may not reflect what is actually used. It is updated
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 * when hitting <Esc>.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 State |= LANGMAP;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455 #ifdef USE_IM_CONTROL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 setmouse();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 clear_showcmd();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 /* there is no reverse replace mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467 revins_on = (State == INSERT && p_ri);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468 if (revins_on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470 revins_chars = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 revins_legal = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 revins_scol = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476 * Handle restarting Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477 * Don't do this for "CTRL-O ." (repeat an insert): we get here with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478 * restart_edit non-zero, and something in the stuff buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 if (restart_edit != 0 && stuff_empty())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484 * After a paste we consider text typed to be part of the insert for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 * the pasted text. You can backspace over the pasted text too.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487 if (where_paste_started.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 arrow_used = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491 arrow_used = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 restart_edit = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 * If the cursor was after the end-of-line before the CTRL-O and it is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496 * now at the end-of-line, put it after the end-of-line (this is not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497 * correct in very rare cases).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498 * Also do this if curswant is greater than the current virtual
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499 * column. Eg after "^O$" or "^O80|".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 validate_virtcol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 update_curswant();
230
9281a51ca7a2 updated for version 7.0064
vimboss
parents: 221
diff changeset
503 if (((ins_at_eol && curwin->w_cursor.lnum == o_lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 || curwin->w_curswant > curwin->w_virtcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505 && *(ptr = ml_get_curline() + curwin->w_cursor.col) != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507 if (ptr[1] == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
508 ++curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
509 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 else if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 {
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 470
diff changeset
512 i = (*mb_ptr2len)(ptr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513 if (ptr[i] == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514 curwin->w_cursor.col += i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
516 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517 }
230
9281a51ca7a2 updated for version 7.0064
vimboss
parents: 221
diff changeset
518 ins_at_eol = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
520 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521 arrow_used = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523 /* we are in insert mode now, don't need to start it anymore */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524 need_start_insertmode = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526 /* Need to save the line for undo before inserting the first char. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527 ins_need_undo = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
530 where_paste_started.lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536 /* The cursor line is not in a closed fold, unless 'insertmode' is set or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537 * restarting. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
538 if (!p_im && did_restart_edit == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
539 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
541
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
542 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543 * If 'showmode' is set, show the current (insert/replace/..) mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544 * A warning message for changing a readonly file is given here, before
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
545 * actually changing anything. It's put after the mode, if any.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 i = 0;
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
548 if (p_smd && msg_silent == 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
549 i = showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
550
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
551 if (!p_im && did_restart_edit == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552 change_warning(i + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
554 #ifdef CURSOR_SHAPE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
555 ui_cursor_shape(); /* may show different cursor shape */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
557 #ifdef FEAT_DIGRAPHS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558 do_digraph(-1); /* clear digraphs */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560
603
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
561 /*
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
562 * Get the current length of the redo buffer, those characters have to be
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
563 * skipped if we want to get to the inserted characters.
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
564 */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565 ptr = get_inserted();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 if (ptr == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
567 new_insert_skip = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570 new_insert_skip = (int)STRLEN(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571 vim_free(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 old_indent = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 * Main loop in Insert mode: repeat until Insert mode is left.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582 if (!revins_legal)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 revins_scol = -1; /* reset on illegal motions */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585 revins_legal = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587 if (arrow_used) /* don't repeat insert when arrow key used */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588 count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590 if (stop_insert_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592 /* ":stopinsert" used or 'insertmode' reset */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
593 count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594 goto doESCkey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 /* set curwin->w_curswant for next K_DOWN or K_UP */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598 if (!arrow_used)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601 /* If there is no typeahead may check for timestamps (e.g., for when a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 * menu invoked a shell command). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603 if (stuff_empty())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605 did_check_timestamps = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 if (need_check_timestamps)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 check_timestamps(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611 * When emsg() was called msg_scroll will have been set.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
612 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613 msg_scroll = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
614
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616 /* When 'mousefocus' is set a mouse movement may have taken us to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617 * another window. "need_mouse_correct" may then be set because of an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618 * autocommand. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
619 if (need_mouse_correct)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620 gui_mouse_correct();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
621 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
622
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
623 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
624 /* Open fold at the cursor line, according to 'foldopen'. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
625 if (fdo_flags & FDO_INSERT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
627 /* Close folds where the cursor isn't, according to 'foldclose' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628 if (!char_avail())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
629 foldCheckClose();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
630 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
631
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
632 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
633 * If we inserted a character at the last position of the last line in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
634 * the window, scroll the window one line up. This avoids an extra
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635 * redraw.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636 * This is detected when the cursor column is smaller after inserting
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
637 * something.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
638 * Don't do this when the topline changed already, it has
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
639 * already been adjusted (by insertchar() calling open_line())).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
640 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
641 if (curbuf->b_mod_set
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
642 && curwin->w_p_wrap
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
643 && !did_backspace
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
644 && curwin->w_topline == old_topline
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
645 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
646 && curwin->w_topfill == old_topfill
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
647 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
648 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
649 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
650 mincol = curwin->w_wcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
651 validate_cursor_col();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
652
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
653 if ((int)curwin->w_wcol < (int)mincol - curbuf->b_p_ts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
654 && curwin->w_wrow == W_WINROW(curwin)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
655 + curwin->w_height - 1 - p_so
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
656 && (curwin->w_cursor.lnum != curwin->w_topline
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
657 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
658 || curwin->w_topfill > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
659 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
660 ))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
661 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
662 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
663 if (curwin->w_topfill > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
664 --curwin->w_topfill;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
665 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
666 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
667 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
668 if (hasFolding(curwin->w_topline, NULL, &old_topline))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
669 set_topline(curwin, old_topline + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
670 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
671 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
672 set_topline(curwin, curwin->w_topline + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
673 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
674 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
675
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
676 /* May need to adjust w_topline to show the cursor. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
677 update_topline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
678
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
679 did_backspace = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
680
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
681 validate_cursor(); /* may set must_redraw */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
682
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
683 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
684 * Redraw the display when no characters are waiting.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
685 * Also shows mode, ruler and positions cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
686 */
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
687 ins_redraw(TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
688
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
689 #ifdef FEAT_SCROLLBIND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
690 if (curwin->w_p_scb)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
691 do_check_scrollbind(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
692 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
693
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
694 update_curswant();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
695 old_topline = curwin->w_topline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
696 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
697 old_topfill = curwin->w_topfill;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
698 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
699
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
700 #ifdef USE_ON_FLY_SCROLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
701 dont_scroll = FALSE; /* allow scrolling here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
702 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
703
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
704 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
705 * Get a character for Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
706 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
707 lastc = c; /* remember previous char for CTRL-D */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
708 c = safe_vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
709
978
0e3e208b4b90 updated for version 7.0-104
vimboss
parents: 947
diff changeset
710 #ifdef FEAT_AUTOCMD
0e3e208b4b90 updated for version 7.0-104
vimboss
parents: 947
diff changeset
711 /* Don't want K_CURSORHOLD for the second key, e.g., after CTRL-V. */
0e3e208b4b90 updated for version 7.0-104
vimboss
parents: 947
diff changeset
712 did_cursorhold = TRUE;
0e3e208b4b90 updated for version 7.0-104
vimboss
parents: 947
diff changeset
713 #endif
0e3e208b4b90 updated for version 7.0-104
vimboss
parents: 947
diff changeset
714
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
715 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
716 if (p_hkmap && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
717 c = hkmap(c); /* Hebrew mode mapping */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
718 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
719 #ifdef FEAT_FKMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
720 if (p_fkmap && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
721 c = fkmap(c); /* Farsi mode mapping */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
722 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
723
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
724 #ifdef FEAT_INS_EXPAND
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
725 /*
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
726 * Special handling of keys while the popup menu is visible or wanted
897
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
727 * and the cursor is still in the completed word. Only when there is
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
728 * a match, skip this when no matches were found.
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
729 */
897
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
730 if (compl_started
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
731 && pum_wanted()
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
732 && curwin->w_cursor.col >= compl_col
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
733 && (compl_shown_match == NULL
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
734 || compl_shown_match != compl_shown_match->cp_next))
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
735 {
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
736 /* BS: Delete one character from "compl_leader". */
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
737 if ((c == K_BS || c == Ctrl_H)
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
738 && curwin->w_cursor.col > compl_col
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
739 && (c = ins_compl_bs()) == NUL)
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
740 continue;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
741
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
742 /* When no match was selected or it was edited. */
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
743 if (!compl_used_match)
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
744 {
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
745 /* CTRL-L: Add one character from the current match to
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
746 * "compl_leader". Except when at the original match and
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
747 * there is nothing to add, CTRL-L works like CTRL-P then. */
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
748 if (c == Ctrl_L
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
749 && (ctrl_x_mode != CTRL_X_WHOLE_LINE
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
750 || STRLEN(compl_shown_match->cp_str)
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
751 > curwin->w_cursor.col - compl_col))
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
752 {
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
753 ins_compl_addfrommatch();
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
754 continue;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
755 }
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
756
683
a39b8af64334 updated for version 7.0205
vimboss
parents: 681
diff changeset
757 /* A printable, non-white character: Add to "compl_leader". */
a39b8af64334 updated for version 7.0205
vimboss
parents: 681
diff changeset
758 if (vim_isprintc(c) && !vim_iswhite(c))
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
759 {
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
760 ins_compl_addleader(c);
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
761 continue;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
762 }
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
763
887
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
764 /* Pressing CTRL-Y selects the current match. When
825
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
765 * compl_enter_selects is set the Enter key does the same. */
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
766 if (c == Ctrl_Y || (compl_enter_selects
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
767 && (c == CAR || c == K_KENTER || c == NL)))
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
768 {
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
769 ins_compl_delete();
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
770 ins_compl_insert();
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
771 }
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
772 }
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
773 }
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
774
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
775 /* Prepare for or stop CTRL-X mode. This doesn't do completion, but
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
776 * it does fix up the text when finishing completion. */
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
777 compl_get_longest = FALSE;
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
778 if (c != K_IGNORE && ins_compl_prep(c))
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
779 continue;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
780 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
781
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
782 /* CTRL-\ CTRL-N goes to Normal mode,
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
783 * CTRL-\ CTRL-G goes to mode selected with 'insertmode',
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
784 * CTRL-\ CTRL-O is like CTRL-O but without moving the cursor. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
785 if (c == Ctrl_BSL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
786 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
787 /* may need to redraw when no more chars available now */
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
788 ins_redraw(FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
789 ++no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
790 ++allow_keys;
1389
bdcfe793d49f updated for version 7.1-104
vimboss
parents: 1353
diff changeset
791 c = plain_vgetc();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
792 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
793 --allow_keys;
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
794 if (c != Ctrl_N && c != Ctrl_G && c != Ctrl_O)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
795 {
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
796 /* it's something else */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
797 vungetc(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
798 c = Ctrl_BSL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
799 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
800 else if (c == Ctrl_G && p_im)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
801 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
802 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
803 {
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
804 if (c == Ctrl_O)
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
805 {
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
806 ins_ctrl_o();
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
807 ins_at_eol = FALSE; /* cursor keeps its column */
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
808 nomove = TRUE;
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
809 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
810 count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
811 goto doESCkey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
812 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
813 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
814
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
815 #ifdef FEAT_DIGRAPHS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
816 c = do_digraph(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
817 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
818
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
819 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
820 if ((c == Ctrl_V || c == Ctrl_Q) && ctrl_x_mode == CTRL_X_CMDLINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
821 goto docomplete;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
822 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
823 if (c == Ctrl_V || c == Ctrl_Q)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
824 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
825 ins_ctrl_v();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
826 c = Ctrl_V; /* pretend CTRL-V is last typed character */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
827 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
828 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
829
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
830 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
831 if (cindent_on()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
832 # ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
833 && ctrl_x_mode == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
834 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
835 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
836 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
837 /* A key name preceded by a bang means this key is not to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
838 * inserted. Skip ahead to the re-indenting below.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
839 * A key name preceded by a star means that indenting has to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
840 * done before inserting the key. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
841 line_is_white = inindent(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
842 if (in_cinkeys(c, '!', line_is_white))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
843 goto force_cindent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
844 if (can_cindent && in_cinkeys(c, '*', line_is_white)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
845 && stop_arrow() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
846 do_c_expr_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
847 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
848 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
849
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
850 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
851 if (curwin->w_p_rl)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
852 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
853 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
854 case K_LEFT: c = K_RIGHT; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
855 case K_S_LEFT: c = K_S_RIGHT; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
856 case K_C_LEFT: c = K_C_RIGHT; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
857 case K_RIGHT: c = K_LEFT; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
858 case K_S_RIGHT: c = K_S_LEFT; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
859 case K_C_RIGHT: c = K_C_LEFT; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
860 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
861 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
862
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
863 #ifdef FEAT_VISUAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
864 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
865 * If 'keymodel' contains "startsel", may start selection. If it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
866 * does, a CTRL-O and c will be stuffed, we need to get these
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
867 * characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
868 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
869 if (ins_start_select(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
870 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
871 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
872
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
873 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
874 * The big switch to handle a character in insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
875 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
876 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
877 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
878 case ESC: /* End input mode */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
879 if (echeck_abbr(ESC + ABBR_OFF))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
880 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
881 /*FALLTHROUGH*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
882
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
883 case Ctrl_C: /* End input mode */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
884 #ifdef FEAT_CMDWIN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
885 if (c == Ctrl_C && cmdwin_type != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
886 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
887 /* Close the cmdline window. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
888 cmdwin_result = K_IGNORE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
889 got_int = FALSE; /* don't stop executing autocommands et al. */
929
2448f4c8afc6 updated for version 7.0-055
vimboss
parents: 909
diff changeset
890 nomove = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
891 goto doESCkey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
892 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
893 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
894
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
895 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
896 do_intr:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
897 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
898 /* when 'insertmode' set, and not halfway a mapping, don't leave
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
899 * Insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
900 if (goto_im())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
901 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
902 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
903 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
904 (void)vgetc(); /* flush all buffers */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
905 got_int = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
906 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
907 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
908 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
909 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
910 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
911 doESCkey:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
912 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
913 * This is the ONLY return from edit()!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
914 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
915 /* Always update o_lnum, so that a "CTRL-O ." that adds a line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
916 * still puts the cursor back after the inserted text. */
230
9281a51ca7a2 updated for version 7.0064
vimboss
parents: 221
diff changeset
917 if (ins_at_eol && gchar_cursor() == NUL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
918 o_lnum = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
919
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
920 if (ins_esc(&count, cmdchar, nomove))
11
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
921 {
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
922 #ifdef FEAT_AUTOCMD
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
923 if (cmdchar != 'r' && cmdchar != 'v')
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
924 apply_autocmds(EVENT_INSERTLEAVE, NULL, NULL,
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
925 FALSE, curbuf);
993
cbc9c335ddb1 updated for version 7.0-119
vimboss
parents: 989
diff changeset
926 did_cursorhold = FALSE;
11
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
927 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
928 return (c == Ctrl_O);
11
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
929 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
930 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
931
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
932 case Ctrl_Z: /* suspend when 'insertmode' set */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
933 if (!p_im)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
934 goto normalchar; /* insert CTRL-Z as normal char */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
935 stuffReadbuff((char_u *)":st\r");
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
936 c = Ctrl_O;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
937 /*FALLTHROUGH*/
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
938
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
939 case Ctrl_O: /* execute one command */
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
940 #ifdef FEAT_COMPL_FUNC
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
941 if (ctrl_x_mode == CTRL_X_OMNI)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
942 goto docomplete;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
943 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
944 if (echeck_abbr(Ctrl_O + ABBR_OFF))
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
945 break;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
946 ins_ctrl_o();
853
d10fbefd3bc1 updated for version 7.0f05
vimboss
parents: 846
diff changeset
947
d10fbefd3bc1 updated for version 7.0f05
vimboss
parents: 846
diff changeset
948 #ifdef FEAT_VIRTUALEDIT
d10fbefd3bc1 updated for version 7.0f05
vimboss
parents: 846
diff changeset
949 /* don't move the cursor left when 'virtualedit' has "onemore". */
d10fbefd3bc1 updated for version 7.0f05
vimboss
parents: 846
diff changeset
950 if (ve_flags & VE_ONEMORE)
d10fbefd3bc1 updated for version 7.0f05
vimboss
parents: 846
diff changeset
951 {
d10fbefd3bc1 updated for version 7.0f05
vimboss
parents: 846
diff changeset
952 ins_at_eol = FALSE;
d10fbefd3bc1 updated for version 7.0f05
vimboss
parents: 846
diff changeset
953 nomove = TRUE;
d10fbefd3bc1 updated for version 7.0f05
vimboss
parents: 846
diff changeset
954 }
d10fbefd3bc1 updated for version 7.0f05
vimboss
parents: 846
diff changeset
955 #endif
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
956 count = 0;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
957 goto doESCkey;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
958
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
959 case K_INS: /* toggle insert/replace mode */
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
960 case K_KINS:
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
961 ins_insert(replaceState);
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
962 break;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
963
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
964 case K_SELECT: /* end of Select mode mapping - ignore */
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
965 break;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
966
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
967 #ifdef FEAT_SNIFF
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
968 case K_SNIFF: /* Sniff command received */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
969 stuffcharReadbuff(K_SNIFF);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
970 goto doESCkey;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
971 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
972
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
973 case K_HELP: /* Help key works like <ESC> <Help> */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
974 case K_F1:
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
975 case K_XF1:
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
976 stuffcharReadbuff(K_HELP);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
977 if (p_im)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
978 need_start_insertmode = TRUE;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
979 goto doESCkey;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
980
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
981 #ifdef FEAT_NETBEANS_INTG
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
982 case K_F21: /* NetBeans command */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
983 ++no_mapping; /* don't map the next key hits */
1389
bdcfe793d49f updated for version 7.1-104
vimboss
parents: 1353
diff changeset
984 i = plain_vgetc();
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
985 --no_mapping;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
986 netbeans_keycommand(i);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
987 break;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
988 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
989
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
990 case K_ZERO: /* Insert the previously inserted text. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
991 case NUL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
992 case Ctrl_A:
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
993 /* For ^@ the trailing ESC will end the insert, unless there is an
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
994 * error. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
995 if (stuff_inserted(NUL, 1L, (c == Ctrl_A)) == FAIL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
996 && c != Ctrl_A && !p_im)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
997 goto doESCkey; /* quit insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
998 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
999 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1000
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1001 case Ctrl_R: /* insert the contents of a register */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1002 ins_reg();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1003 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1004 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1005 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1006
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1007 case Ctrl_G: /* commands starting with CTRL-G */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1008 ins_ctrl_g();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1009 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1010
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1011 case Ctrl_HAT: /* switch input mode and/or langmap */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1012 ins_ctrl_hat();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1013 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1014
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1015 #ifdef FEAT_RIGHTLEFT
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1016 case Ctrl__: /* switch between languages */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1017 if (!p_ari)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1018 goto normalchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1019 ins_ctrl_();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1020 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1021 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1022
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1023 case Ctrl_D: /* Make indent one shiftwidth smaller. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1024 #if defined(FEAT_INS_EXPAND) && defined(FEAT_FIND_ID)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1025 if (ctrl_x_mode == CTRL_X_PATH_DEFINES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1026 goto docomplete;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1027 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1028 /* FALLTHROUGH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1029
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1030 case Ctrl_T: /* Make indent one shiftwidth greater. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1031 # ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1032 if (c == Ctrl_T && ctrl_x_mode == CTRL_X_THESAURUS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1033 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1034 if (has_compl_option(FALSE))
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1035 goto docomplete;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1036 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1037 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1038 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1039 ins_shift(c, lastc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1040 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1041 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1042 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1043
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1044 case K_DEL: /* delete character under the cursor */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1045 case K_KDEL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1046 ins_del();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1047 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1048 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1049
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1050 case K_BS: /* delete character before the cursor */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1051 case Ctrl_H:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1052 did_backspace = ins_bs(c, BACKSPACE_CHAR, &inserted_space);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1053 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1054 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1055
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1056 case Ctrl_W: /* delete word before the cursor */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1057 did_backspace = ins_bs(c, BACKSPACE_WORD, &inserted_space);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1058 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1059 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1060
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1061 case Ctrl_U: /* delete all inserted text in current line */
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
1062 # ifdef FEAT_COMPL_FUNC
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
1063 /* CTRL-X CTRL-U completes with 'completefunc'. */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1064 if (ctrl_x_mode == CTRL_X_FUNCTION)
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
1065 goto docomplete;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
1066 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1067 did_backspace = ins_bs(c, BACKSPACE_LINE, &inserted_space);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1068 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1069 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1070 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1071
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1072 #ifdef FEAT_MOUSE
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1073 case K_LEFTMOUSE: /* mouse keys */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1074 case K_LEFTMOUSE_NM:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1075 case K_LEFTDRAG:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1076 case K_LEFTRELEASE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1077 case K_LEFTRELEASE_NM:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1078 case K_MIDDLEMOUSE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1079 case K_MIDDLEDRAG:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1080 case K_MIDDLERELEASE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1081 case K_RIGHTMOUSE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1082 case K_RIGHTDRAG:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1083 case K_RIGHTRELEASE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1084 case K_X1MOUSE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1085 case K_X1DRAG:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1086 case K_X1RELEASE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1087 case K_X2MOUSE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1088 case K_X2DRAG:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1089 case K_X2RELEASE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1090 ins_mouse(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1091 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1092
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1093 case K_MOUSEDOWN: /* Default action for scroll wheel up: scroll up */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1094 ins_mousescroll(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1095 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1096
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1097 case K_MOUSEUP: /* Default action for scroll wheel down: scroll down */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1098 ins_mousescroll(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1099 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1100 #endif
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
1101 #ifdef FEAT_GUI_TABLINE
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
1102 case K_TABLINE:
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
1103 case K_TABMENU:
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
1104 ins_tabline(c);
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
1105 break;
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
1106 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1107
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1108 case K_IGNORE: /* Something mapped to nothing */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1109 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1110
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1111 #ifdef FEAT_AUTOCMD
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1112 case K_CURSORHOLD: /* Didn't type something for a while. */
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1113 apply_autocmds(EVENT_CURSORHOLDI, NULL, NULL, FALSE, curbuf);
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1114 did_cursorhold = TRUE;
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1115 break;
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1116 #endif
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1117
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 620
diff changeset
1118 #ifdef FEAT_GUI_W32
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 620
diff changeset
1119 /* On Win32 ignore <M-F4>, we get it when closing the window was
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 620
diff changeset
1120 * cancelled. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 620
diff changeset
1121 case K_F4:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 620
diff changeset
1122 if (mod_mask != MOD_MASK_ALT)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 620
diff changeset
1123 goto normalchar;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 620
diff changeset
1124 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 620
diff changeset
1125 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 620
diff changeset
1126
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1127 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1128 case K_VER_SCROLLBAR:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1129 ins_scroll();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1130 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1131
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1132 case K_HOR_SCROLLBAR:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1133 ins_horscroll();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1134 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1135 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1136
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1137 case K_HOME: /* <Home> */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1138 case K_KHOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1139 case K_S_HOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1140 case K_C_HOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1141 ins_home(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1142 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1143
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1144 case K_END: /* <End> */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1145 case K_KEND:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1146 case K_S_END:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1147 case K_C_END:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1148 ins_end(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1149 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1150
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1151 case K_LEFT: /* <Left> */
180
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1152 if (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1153 ins_s_left();
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1154 else
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1155 ins_left();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1156 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1157
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1158 case K_S_LEFT: /* <S-Left> */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1159 case K_C_LEFT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1160 ins_s_left();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1161 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1162
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1163 case K_RIGHT: /* <Right> */
180
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1164 if (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1165 ins_s_right();
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1166 else
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1167 ins_right();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1168 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1169
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1170 case K_S_RIGHT: /* <S-Right> */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1171 case K_C_RIGHT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1172 ins_s_right();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1173 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1174
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1175 case K_UP: /* <Up> */
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
1176 #ifdef FEAT_INS_EXPAND
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
1177 if (pum_visible())
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
1178 goto docomplete;
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
1179 #endif
180
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1180 if (mod_mask & MOD_MASK_SHIFT)
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1181 ins_pageup();
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1182 else
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1183 ins_up(FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1184 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1185
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1186 case K_S_UP: /* <S-Up> */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1187 case K_PAGEUP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1188 case K_KPAGEUP:
613
53114ef7778f updated for version 7.0174
vimboss
parents: 610
diff changeset
1189 #ifdef FEAT_INS_EXPAND
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
1190 if (pum_visible())
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
1191 goto docomplete;
613
53114ef7778f updated for version 7.0174
vimboss
parents: 610
diff changeset
1192 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1193 ins_pageup();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1194 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1195
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1196 case K_DOWN: /* <Down> */
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
1197 #ifdef FEAT_INS_EXPAND
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
1198 if (pum_visible())
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
1199 goto docomplete;
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
1200 #endif
180
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1201 if (mod_mask & MOD_MASK_SHIFT)
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1202 ins_pagedown();
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1203 else
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1204 ins_down(FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1205 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1206
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1207 case K_S_DOWN: /* <S-Down> */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1208 case K_PAGEDOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1209 case K_KPAGEDOWN:
613
53114ef7778f updated for version 7.0174
vimboss
parents: 610
diff changeset
1210 #ifdef FEAT_INS_EXPAND
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
1211 if (pum_visible())
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
1212 goto docomplete;
613
53114ef7778f updated for version 7.0174
vimboss
parents: 610
diff changeset
1213 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1214 ins_pagedown();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1215 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1216
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1217 #ifdef FEAT_DND
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1218 case K_DROP: /* drag-n-drop event */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1219 ins_drop();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1220 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1221 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1222
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1223 case K_S_TAB: /* When not mapped, use like a normal TAB */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1224 c = TAB;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1225 /* FALLTHROUGH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1226
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1227 case TAB: /* TAB or Complete patterns along path */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1228 #if defined(FEAT_INS_EXPAND) && defined(FEAT_FIND_ID)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1229 if (ctrl_x_mode == CTRL_X_PATH_PATTERNS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1230 goto docomplete;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1231 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1232 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1233 if (ins_tab())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1234 goto normalchar; /* insert TAB as a normal char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1235 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1236 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1237
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1238 case K_KENTER: /* <Enter> */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1239 c = CAR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1240 /* FALLTHROUGH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1241 case CAR:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1242 case NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1243 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1244 /* In a quickfix window a <CR> jumps to the error under the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1245 * cursor. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1246 if (bt_quickfix(curbuf) && c == CAR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1247 {
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
1248 if (curwin->w_llist_ref == NULL) /* quickfix window */
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
1249 do_cmdline_cmd((char_u *)".cc");
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
1250 else /* location list window */
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
1251 do_cmdline_cmd((char_u *)".ll");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1252 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1253 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1254 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1255 #ifdef FEAT_CMDWIN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1256 if (cmdwin_type != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1257 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1258 /* Execute the command in the cmdline window. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1259 cmdwin_result = CAR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1260 goto doESCkey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1261 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1262 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1263 if (ins_eol(c) && !p_im)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1264 goto doESCkey; /* out of memory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1265 auto_format(FALSE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1266 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1267 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1268
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1269 #if defined(FEAT_DIGRAPHS) || defined (FEAT_INS_EXPAND)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1270 case Ctrl_K: /* digraph or keyword completion */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1271 # ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1272 if (ctrl_x_mode == CTRL_X_DICTIONARY)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1273 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1274 if (has_compl_option(TRUE))
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1275 goto docomplete;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1276 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1277 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1278 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1279 # ifdef FEAT_DIGRAPHS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1280 c = ins_digraph();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1281 if (c == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1282 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1283 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1284 goto normalchar;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1285 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1286
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1287 #ifdef FEAT_INS_EXPAND
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1288 case Ctrl_X: /* Enter CTRL-X mode */
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1289 ins_ctrl_x();
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1290 break;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1291
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1292 case Ctrl_RSB: /* Tag name completion after ^X */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1293 if (ctrl_x_mode != CTRL_X_TAGS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1294 goto normalchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1295 goto docomplete;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1296
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1297 case Ctrl_F: /* File name completion after ^X */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1298 if (ctrl_x_mode != CTRL_X_FILES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1299 goto normalchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1300 goto docomplete;
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
1301
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
1302 case 's': /* Spelling completion after ^X */
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
1303 case Ctrl_S:
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
1304 if (ctrl_x_mode != CTRL_X_SPELL)
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
1305 goto normalchar;
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
1306 goto docomplete;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1307 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1308
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1309 case Ctrl_L: /* Whole line completion after ^X */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1310 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1311 if (ctrl_x_mode != CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1312 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1313 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1314 /* CTRL-L with 'insertmode' set: Leave Insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1315 if (p_im)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1316 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1317 if (echeck_abbr(Ctrl_L + ABBR_OFF))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1318 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1319 goto doESCkey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1320 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1321 goto normalchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1322 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1323 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1324 /* FALLTHROUGH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1325
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1326 case Ctrl_P: /* Do previous/next pattern completion */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1327 case Ctrl_N:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1328 /* if 'complete' is empty then plain ^P is no longer special,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1329 * but it is under other ^X modes */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1330 if (*curbuf->b_p_cpt == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1331 && ctrl_x_mode != 0
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1332 && !(compl_cont_status & CONT_LOCAL))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1333 goto normalchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1334
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1335 docomplete:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1336 if (ins_complete(c) == FAIL)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1337 compl_cont_status = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1338 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1339 #endif /* FEAT_INS_EXPAND */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1340
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1341 case Ctrl_Y: /* copy from previous line or scroll down */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1342 case Ctrl_E: /* copy from next line or scroll up */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1343 c = ins_ctrl_ey(c);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1344 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1345
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1346 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1347 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1348 if (c == intr_char) /* special interrupt char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1349 goto do_intr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1350 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1351
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1352 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1353 * Insert a nomal character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1354 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1355 normalchar:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1356 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1357 /* Try to perform smart-indenting. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1358 ins_try_si(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1359 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1360
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1361 if (c == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1362 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1363 inserted_space = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1364 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1365 if (inindent(0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1366 can_cindent = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1367 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1368 if (Insstart_blank_vcol == MAXCOL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1369 && curwin->w_cursor.lnum == Insstart.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1370 Insstart_blank_vcol = get_nolist_virtcol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1371 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1372
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1373 if (vim_iswordc(c) || !echeck_abbr(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1374 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1375 /* Add ABBR_OFF for characters above 0x100, this is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1376 * what check_abbr() expects. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1377 (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1378 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1379 c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1380 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1381 insert_special(c, FALSE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1382 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1383 revins_legal++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1384 revins_chars++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1385 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1386 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1387
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1388 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1389
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1390 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1391 /* When inserting a character the cursor line must never be in a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1392 * closed fold. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1393 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1394 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1395 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1396 } /* end of switch (c) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1397
978
0e3e208b4b90 updated for version 7.0-104
vimboss
parents: 947
diff changeset
1398 #ifdef FEAT_AUTOCMD
0e3e208b4b90 updated for version 7.0-104
vimboss
parents: 947
diff changeset
1399 /* If typed something may trigger CursorHoldI again. */
0e3e208b4b90 updated for version 7.0-104
vimboss
parents: 947
diff changeset
1400 if (c != K_CURSORHOLD)
0e3e208b4b90 updated for version 7.0-104
vimboss
parents: 947
diff changeset
1401 did_cursorhold = FALSE;
0e3e208b4b90 updated for version 7.0-104
vimboss
parents: 947
diff changeset
1402 #endif
0e3e208b4b90 updated for version 7.0-104
vimboss
parents: 947
diff changeset
1403
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1404 /* If the cursor was moved we didn't just insert a space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1405 if (arrow_used)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1406 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1407
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1408 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1409 if (can_cindent && cindent_on()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1410 # ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1411 && ctrl_x_mode == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1412 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1413 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1414 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1415 force_cindent:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1416 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1417 * Indent now if a key was typed that is in 'cinkeys'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1418 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1419 if (in_cinkeys(c, ' ', line_is_white))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1420 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1421 if (stop_arrow() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1422 /* re-indent the current line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1423 do_c_expr_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1424 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1425 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1426 #endif /* FEAT_CINDENT */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1427
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1428 } /* for (;;) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1429 /* NOTREACHED */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1430 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1431
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1432 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1433 * Redraw for Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1434 * This is postponed until getting the next character to make '$' in the 'cpo'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1435 * option work correctly.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1436 * Only redraw when there are no characters available. This speeds up
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1437 * inserting sequences of characters (e.g., for CTRL-R).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1438 */
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1439 /*ARGSUSED*/
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1440 static void
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1441 ins_redraw(ready)
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1442 int ready; /* not busy with something */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1443 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1444 if (!char_avail())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1445 {
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1446 #ifdef FEAT_AUTOCMD
794
f19994020dad updated for version 7.0231
vimboss
parents: 786
diff changeset
1447 /* Trigger CursorMoved if the cursor moved. Not when the popup menu is
f19994020dad updated for version 7.0231
vimboss
parents: 786
diff changeset
1448 * visible, the command might delete it. */
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1449 if (ready && has_cursormovedI()
794
f19994020dad updated for version 7.0231
vimboss
parents: 786
diff changeset
1450 && !equalpos(last_cursormoved, curwin->w_cursor)
f19994020dad updated for version 7.0231
vimboss
parents: 786
diff changeset
1451 # ifdef FEAT_INS_EXPAND
f19994020dad updated for version 7.0231
vimboss
parents: 786
diff changeset
1452 && !pum_visible()
f19994020dad updated for version 7.0231
vimboss
parents: 786
diff changeset
1453 # endif
f19994020dad updated for version 7.0231
vimboss
parents: 786
diff changeset
1454 )
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1455 {
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1456 apply_autocmds(EVENT_CURSORMOVEDI, NULL, NULL, FALSE, curbuf);
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1457 last_cursormoved = curwin->w_cursor;
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1458 }
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1459 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1460 if (must_redraw)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1461 update_screen(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1462 else if (clear_cmdline || redraw_cmdline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1463 showmode(); /* clear cmdline and show mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1464 showruler(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1465 setcursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1466 emsg_on_display = FALSE; /* may remove error message now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1467 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1468 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1469
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1470 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1471 * Handle a CTRL-V or CTRL-Q typed in Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1472 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1473 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1474 ins_ctrl_v()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1475 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1476 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1477
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1478 /* may need to redraw when no more chars available now */
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1479 ins_redraw(FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1480
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1481 if (redrawing() && !char_avail())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1482 edit_putchar('^', TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1483 AppendToRedobuff((char_u *)CTRL_V_STR); /* CTRL-V */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1484
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1485 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1486 add_to_showcmd_c(Ctrl_V);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1487 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1488
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1489 c = get_literal();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1490 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1491 clear_showcmd();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1492 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1493 insert_special(c, FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1494 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1495 revins_chars++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1496 revins_legal++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1497 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1498 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1499
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1500 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1501 * Put a character directly onto the screen. It's not stored in a buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1502 * Used while handling CTRL-K, CTRL-V, etc. in Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1503 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1504 static int pc_status;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1505 #define PC_STATUS_UNSET 0 /* pc_bytes was not set */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1506 #define PC_STATUS_RIGHT 1 /* right halve of double-wide char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1507 #define PC_STATUS_LEFT 2 /* left halve of double-wide char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1508 #define PC_STATUS_SET 3 /* pc_bytes was filled */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1509 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1510 static char_u pc_bytes[MB_MAXBYTES + 1]; /* saved bytes */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1511 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1512 static char_u pc_bytes[2]; /* saved bytes */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1513 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1514 static int pc_attr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1515 static int pc_row;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1516 static int pc_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1517
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1518 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1519 edit_putchar(c, highlight)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1520 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1521 int highlight;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1522 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1523 int attr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1524
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1525 if (ScreenLines != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1526 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1527 update_topline(); /* just in case w_topline isn't valid */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1528 validate_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1529 if (highlight)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1530 attr = hl_attr(HLF_8);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1531 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1532 attr = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1533 pc_row = W_WINROW(curwin) + curwin->w_wrow;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1534 pc_col = W_WINCOL(curwin);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1535 #if defined(FEAT_RIGHTLEFT) || defined(FEAT_MBYTE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1536 pc_status = PC_STATUS_UNSET;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1537 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1538 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1539 if (curwin->w_p_rl)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1540 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1541 pc_col += W_WIDTH(curwin) - 1 - curwin->w_wcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1542 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1543 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1544 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1545 int fix_col = mb_fix_col(pc_col, pc_row);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1546
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1547 if (fix_col != pc_col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1548 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1549 screen_putchar(' ', pc_row, fix_col, attr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1550 --curwin->w_wcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1551 pc_status = PC_STATUS_RIGHT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1552 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1553 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1554 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1555 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1556 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1557 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1558 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1559 pc_col += curwin->w_wcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1560 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1561 if (mb_lefthalve(pc_row, pc_col))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1562 pc_status = PC_STATUS_LEFT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1563 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1564 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1565
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1566 /* save the character to be able to put it back */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1567 #if defined(FEAT_RIGHTLEFT) || defined(FEAT_MBYTE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1568 if (pc_status == PC_STATUS_UNSET)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1569 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1570 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1571 screen_getbytes(pc_row, pc_col, pc_bytes, &pc_attr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1572 pc_status = PC_STATUS_SET;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1573 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1574 screen_putchar(c, pc_row, pc_col, attr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1575 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1576 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1577
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1578 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1579 * Undo the previous edit_putchar().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1580 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1581 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1582 edit_unputchar()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1583 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1584 if (pc_status != PC_STATUS_UNSET && pc_row >= msg_scrolled)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1585 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1586 #if defined(FEAT_MBYTE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1587 if (pc_status == PC_STATUS_RIGHT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1588 ++curwin->w_wcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1589 if (pc_status == PC_STATUS_RIGHT || pc_status == PC_STATUS_LEFT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1590 redrawWinline(curwin->w_cursor.lnum, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1591 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1592 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1593 screen_puts(pc_bytes, pc_row - msg_scrolled, pc_col, pc_attr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1594 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1595 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1596
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1597 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1598 * Called when p_dollar is set: display a '$' at the end of the changed text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1599 * Only works when cursor is in the line that changes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1600 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1601 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1602 display_dollar(col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1603 colnr_T col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1604 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1605 colnr_T save_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1606
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1607 if (!redrawing())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1608 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1609
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1610 cursor_off();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1611 save_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1612 curwin->w_cursor.col = col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1613 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1614 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1615 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1616 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1617
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1618 /* If on the last byte of a multi-byte move to the first byte. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1619 p = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1620 curwin->w_cursor.col -= (*mb_head_off)(p, p + col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1621 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1622 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1623 curs_columns(FALSE); /* recompute w_wrow and w_wcol */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1624 if (curwin->w_wcol < W_WIDTH(curwin))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1625 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1626 edit_putchar('$', FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1627 dollar_vcol = curwin->w_virtcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1628 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1629 curwin->w_cursor.col = save_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1630 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1631
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1632 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1633 * Call this function before moving the cursor from the normal insert position
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1634 * in insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1635 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1636 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1637 undisplay_dollar()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1638 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1639 if (dollar_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1640 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1641 dollar_vcol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1642 redrawWinline(curwin->w_cursor.lnum, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1643 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1644 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1645
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1646 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1647 * Insert an indent (for <Tab> or CTRL-T) or delete an indent (for CTRL-D).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1648 * Keep the cursor on the same character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1649 * type == INDENT_INC increase indent (for CTRL-T or <Tab>)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1650 * type == INDENT_DEC decrease indent (for CTRL-D)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1651 * type == INDENT_SET set indent to "amount"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1652 * if round is TRUE, round the indent to 'shiftwidth' (only with _INC and _Dec).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1653 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1654 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1655 change_indent(type, amount, round, replaced)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1656 int type;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1657 int amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1658 int round;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1659 int replaced; /* replaced character, put on replace stack */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1660 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1661 int vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1662 int last_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1663 int insstart_less; /* reduction for Insstart.col */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1664 int new_cursor_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1665 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1666 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1667 int save_p_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1668 int start_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1669 colnr_T vc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1670 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1671 colnr_T orig_col = 0; /* init for GCC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1672 char_u *new_line, *orig_line = NULL; /* init for GCC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1673
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1674 /* VREPLACE mode needs to know what the line was like before changing */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1675 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1676 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1677 orig_line = vim_strsave(ml_get_curline()); /* Deal with NULL below */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1678 orig_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1679 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1680 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1681
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1682 /* for the following tricks we don't want list mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1683 save_p_list = curwin->w_p_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1684 curwin->w_p_list = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1685 vc = getvcol_nolist(&curwin->w_cursor);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1686 vcol = vc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1687
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1688 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1689 * For Replace mode we need to fix the replace stack later, which is only
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1690 * possible when the cursor is in the indent. Remember the number of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1691 * characters before the cursor if it's possible.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1692 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1693 start_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1694
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1695 /* determine offset from first non-blank */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1696 new_cursor_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1697 beginline(BL_WHITE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1698 new_cursor_col -= curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1699
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1700 insstart_less = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1701
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1702 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1703 * If the cursor is in the indent, compute how many screen columns the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1704 * cursor is to the left of the first non-blank.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1705 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1706 if (new_cursor_col < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1707 vcol = get_indent() - vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1708
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1709 if (new_cursor_col > 0) /* can't fix replace stack */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1710 start_col = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1711
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1712 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1713 * Set the new indent. The cursor will be put on the first non-blank.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1714 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1715 if (type == INDENT_SET)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1716 (void)set_indent(amount, SIN_CHANGED);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1717 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1718 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1719 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1720 int save_State = State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1721
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1722 /* Avoid being called recursively. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1723 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1724 State = INSERT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1725 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1726 shift_line(type == INDENT_DEC, round, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1727 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1728 State = save_State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1729 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1730 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1731 insstart_less -= curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1732
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1733 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1734 * Try to put cursor on same character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1735 * If the cursor is at or after the first non-blank in the line,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1736 * compute the cursor column relative to the column of the first
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1737 * non-blank character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1738 * If we are not in insert mode, leave the cursor on the first non-blank.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1739 * If the cursor is before the first non-blank, position it relative
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1740 * to the first non-blank, counted in screen columns.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1741 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1742 if (new_cursor_col >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1743 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1744 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1745 * When changing the indent while the cursor is touching it, reset
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1746 * Insstart_col to 0.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1747 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1748 if (new_cursor_col == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1749 insstart_less = MAXCOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1750 new_cursor_col += curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1751 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1752 else if (!(State & INSERT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1753 new_cursor_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1754 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1755 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1756 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1757 * Compute the screen column where the cursor should be.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1758 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1759 vcol = get_indent() - vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1760 curwin->w_virtcol = (vcol < 0) ? 0 : vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1761
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1762 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1763 * Advance the cursor until we reach the right screen column.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1764 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1765 vcol = last_vcol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1766 new_cursor_col = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1767 ptr = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1768 while (vcol <= (int)curwin->w_virtcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1769 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1770 last_vcol = vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1771 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1772 if (has_mbyte && new_cursor_col >= 0)
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 470
diff changeset
1773 new_cursor_col += (*mb_ptr2len)(ptr + new_cursor_col);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1774 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1775 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1776 ++new_cursor_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1777 vcol += lbr_chartabsize(ptr + new_cursor_col, (colnr_T)vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1778 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1779 vcol = last_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1780
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1781 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1782 * May need to insert spaces to be able to position the cursor on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1783 * the right screen column.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1784 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1785 if (vcol != (int)curwin->w_virtcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1786 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1787 curwin->w_cursor.col = new_cursor_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1788 i = (int)curwin->w_virtcol - vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1789 ptr = alloc(i + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1790 if (ptr != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1791 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1792 new_cursor_col += i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1793 ptr[i] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1794 while (--i >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1795 ptr[i] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1796 ins_str(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1797 vim_free(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1798 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1799 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1800
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1801 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1802 * When changing the indent while the cursor is in it, reset
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1803 * Insstart_col to 0.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1804 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1805 insstart_less = MAXCOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1806 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1807
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1808 curwin->w_p_list = save_p_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1809
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1810 if (new_cursor_col <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1811 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1812 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1813 curwin->w_cursor.col = new_cursor_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1814 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1815 changed_cline_bef_curs();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1816
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1817 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1818 * May have to adjust the start of the insert.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1819 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1820 if (State & INSERT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1821 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1822 if (curwin->w_cursor.lnum == Insstart.lnum && Insstart.col != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1823 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1824 if ((int)Insstart.col <= insstart_less)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1825 Insstart.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1826 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1827 Insstart.col -= insstart_less;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1828 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1829 if ((int)ai_col <= insstart_less)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1830 ai_col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1831 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1832 ai_col -= insstart_less;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1833 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1834
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1835 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1836 * For REPLACE mode, may have to fix the replace stack, if it's possible.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1837 * If the number of characters before the cursor decreased, need to pop a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1838 * few characters from the replace stack.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1839 * If the number of characters before the cursor increased, need to push a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1840 * few NULs onto the replace stack.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1841 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1842 if (REPLACE_NORMAL(State) && start_col >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1843 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1844 while (start_col > (int)curwin->w_cursor.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1845 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1846 replace_join(0); /* remove a NUL from the replace stack */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1847 --start_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1848 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1849 while (start_col < (int)curwin->w_cursor.col || replaced)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1850 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1851 replace_push(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1852 if (replaced)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1853 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1854 replace_push(replaced);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1855 replaced = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1856 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1857 ++start_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1858 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1859 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1860
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1861 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1862 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1863 * For VREPLACE mode, we also have to fix the replace stack. In this case
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1864 * it is always possible because we backspace over the whole line and then
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1865 * put it back again the way we wanted it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1866 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1867 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1868 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1869 /* If orig_line didn't allocate, just return. At least we did the job,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1870 * even if you can't backspace. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1871 if (orig_line == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1872 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1873
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1874 /* Save new line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1875 new_line = vim_strsave(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1876 if (new_line == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1877 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1878
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1879 /* We only put back the new line up to the cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1880 new_line[curwin->w_cursor.col] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1881
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1882 /* Put back original line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1883 ml_replace(curwin->w_cursor.lnum, orig_line, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1884 curwin->w_cursor.col = orig_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1885
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1886 /* Backspace from cursor to start of line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1887 backspace_until_column(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1888
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1889 /* Insert new stuff into line again */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1890 ins_bytes(new_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1891
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1892 vim_free(new_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1893 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1894 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1895 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1896
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1897 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1898 * Truncate the space at the end of a line. This is to be used only in an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1899 * insert mode. It handles fixing the replace stack for REPLACE and VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1900 * modes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1901 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1902 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1903 truncate_spaces(line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1904 char_u *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1905 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1906 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1907
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1908 /* find start of trailing white space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1909 for (i = (int)STRLEN(line) - 1; i >= 0 && vim_iswhite(line[i]); i--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1910 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1911 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1912 replace_join(0); /* remove a NUL from the replace stack */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1913 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1914 line[i + 1] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1915 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1916
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1917 #if defined(FEAT_VREPLACE) || defined(FEAT_INS_EXPAND) \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1918 || defined(FEAT_COMMENTS) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1919 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1920 * Backspace the cursor until the given column. Handles REPLACE and VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1921 * modes correctly. May also be used when not in insert mode at all.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1922 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1923 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1924 backspace_until_column(col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1925 int col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1926 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1927 while ((int)curwin->w_cursor.col > col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1928 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1929 curwin->w_cursor.col--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1930 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1931 replace_do_bs();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1932 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1933 (void)del_char(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1934 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1935 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1936 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1937
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1938 #if defined(FEAT_INS_EXPAND) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1939 /*
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1940 * CTRL-X pressed in Insert mode.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1941 */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1942 static void
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1943 ins_ctrl_x()
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1944 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1945 /* CTRL-X after CTRL-X CTRL-V doesn't do anything, so that CTRL-X
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1946 * CTRL-V works like CTRL-N */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1947 if (ctrl_x_mode != CTRL_X_CMDLINE)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1948 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1949 /* if the next ^X<> won't ADD nothing, then reset
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1950 * compl_cont_status */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1951 if (compl_cont_status & CONT_N_ADDS)
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
1952 compl_cont_status |= CONT_INTRPT;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1953 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1954 compl_cont_status = 0;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1955 /* We're not sure which CTRL-X mode it will be yet */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1956 ctrl_x_mode = CTRL_X_NOT_DEFINED_YET;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1957 edit_submode = (char_u *)_(CTRL_X_MSG(ctrl_x_mode));
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1958 edit_submode_pre = NULL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1959 showmode();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1960 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1961 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1962
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1963 /*
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1964 * Return TRUE if the 'dict' or 'tsr' option can be used.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1965 */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1966 static int
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1967 has_compl_option(dict_opt)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1968 int dict_opt;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1969 {
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
1970 if (dict_opt ? (*curbuf->b_p_dict == NUL && *p_dict == NUL
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
1971 # ifdef FEAT_SPELL
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
1972 && !curwin->w_p_spell
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
1973 # endif
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
1974 )
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1975 : (*curbuf->b_p_tsr == NUL && *p_tsr == NUL))
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1976 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1977 ctrl_x_mode = 0;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1978 edit_submode = NULL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1979 msg_attr(dict_opt ? (char_u *)_("'dictionary' option is empty")
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1980 : (char_u *)_("'thesaurus' option is empty"),
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1981 hl_attr(HLF_E));
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1982 if (emsg_silent == 0)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1983 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1984 vim_beep();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1985 setcursor();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1986 out_flush();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1987 ui_delay(2000L, FALSE);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1988 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1989 return FALSE;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1990 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1991 return TRUE;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1992 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1993
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1994 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1995 * Is the character 'c' a valid key to go to or keep us in CTRL-X mode?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1996 * This depends on the current mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1997 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1998 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1999 vim_is_ctrl_x_key(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2000 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2001 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2002 /* Always allow ^R - let it's results then be checked */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2003 if (c == Ctrl_R)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2004 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2005
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
2006 /* Accept <PageUp> and <PageDown> if the popup menu is visible. */
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
2007 if (ins_compl_pum_key(c))
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
2008 return TRUE;
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
2009
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2010 switch (ctrl_x_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2011 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2012 case 0: /* Not in any CTRL-X mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2013 return (c == Ctrl_N || c == Ctrl_P || c == Ctrl_X);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2014 case CTRL_X_NOT_DEFINED_YET:
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2015 return ( c == Ctrl_X || c == Ctrl_Y || c == Ctrl_E
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2016 || c == Ctrl_L || c == Ctrl_F || c == Ctrl_RSB
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2017 || c == Ctrl_I || c == Ctrl_D || c == Ctrl_P
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2018 || c == Ctrl_N || c == Ctrl_T || c == Ctrl_V
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
2019 || c == Ctrl_Q || c == Ctrl_U || c == Ctrl_O
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
2020 || c == Ctrl_S || c == 's');
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2021 case CTRL_X_SCROLL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2022 return (c == Ctrl_Y || c == Ctrl_E);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2023 case CTRL_X_WHOLE_LINE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2024 return (c == Ctrl_L || c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2025 case CTRL_X_FILES:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2026 return (c == Ctrl_F || c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2027 case CTRL_X_DICTIONARY:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2028 return (c == Ctrl_K || c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2029 case CTRL_X_THESAURUS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2030 return (c == Ctrl_T || c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2031 case CTRL_X_TAGS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2032 return (c == Ctrl_RSB || c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2033 #ifdef FEAT_FIND_ID
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2034 case CTRL_X_PATH_PATTERNS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2035 return (c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2036 case CTRL_X_PATH_DEFINES:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2037 return (c == Ctrl_D || c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2038 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2039 case CTRL_X_CMDLINE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2040 return (c == Ctrl_V || c == Ctrl_Q || c == Ctrl_P || c == Ctrl_N
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2041 || c == Ctrl_X);
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2042 #ifdef FEAT_COMPL_FUNC
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2043 case CTRL_X_FUNCTION:
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2044 return (c == Ctrl_U || c == Ctrl_P || c == Ctrl_N);
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
2045 case CTRL_X_OMNI:
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2046 return (c == Ctrl_O || c == Ctrl_P || c == Ctrl_N);
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
2047 #endif
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
2048 case CTRL_X_SPELL:
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
2049 return (c == Ctrl_S || c == Ctrl_P || c == Ctrl_N);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2050 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2051 EMSG(_(e_internal));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2052 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2053 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2054
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2055 /*
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2056 * This is like ins_compl_add(), but if 'ic' and 'inf' are set, then the
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2057 * case of the originally typed text is used, and the case of the completed
1219
aea597af5b4e updated for version 7.1b
vimboss
parents: 1159
diff changeset
2058 * text is inferred, ie this tries to work out what case you probably wanted
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2059 * the rest of the word to be in -- webb
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2060 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2061 int
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2062 ins_compl_add_infercase(str, len, icase, fname, dir, flags)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2063 char_u *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2064 int len;
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2065 int icase;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2066 char_u *fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2067 int dir;
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2068 int flags;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2069 {
1353
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2070 char_u *p;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2071 int i, c;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2072 int actual_len; /* Take multi-byte characters */
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2073 int actual_compl_length; /* into account. */
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2074 int *wca; /* Wide character array. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2075 int has_lower = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2076 int was_letter = FALSE;
1353
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2077
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2078 if (p_ic && curbuf->b_p_inf)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2079 {
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2080 /* Infer case of completed part. */
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2081
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2082 /* Find actual length of completion. */
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2083 #ifdef FEAT_MBYTE
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2084 if (has_mbyte)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2085 {
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2086 p = str;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2087 actual_len = 0;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2088 while (*p != NUL)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2089 {
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2090 mb_ptr_adv(p);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2091 ++actual_len;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2092 }
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2093 }
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2094 else
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2095 #endif
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2096 actual_len = len;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2097
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2098 /* Find actual length of original text. */
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2099 #ifdef FEAT_MBYTE
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2100 if (has_mbyte)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2101 {
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2102 p = compl_orig_text;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2103 actual_compl_length = 0;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2104 while (*p != NUL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2105 {
1353
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2106 mb_ptr_adv(p);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2107 ++actual_compl_length;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2108 }
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2109 }
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2110 else
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2111 #endif
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2112 actual_compl_length = compl_length;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2113
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2114 /* Allocate wide character array for the completion and fill it. */
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2115 wca = (int *)alloc(actual_len * sizeof(int));
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2116 if (wca != NULL)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2117 {
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2118 p = str;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2119 for (i = 0; i < actual_len; ++i)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2120 #ifdef FEAT_MBYTE
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2121 if (has_mbyte)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2122 wca[i] = mb_ptr2char_adv(&p);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2123 else
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2124 #endif
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2125 wca[i] = *(p++);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2126
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2127 /* Rule 1: Were any chars converted to lower? */
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2128 p = compl_orig_text;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2129 for (i = 0; i < actual_compl_length; ++i)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2130 {
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2131 #ifdef FEAT_MBYTE
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2132 if (has_mbyte)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2133 c = mb_ptr2char_adv(&p);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2134 else
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2135 #endif
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2136 c = *(p++);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2137 if (MB_ISLOWER(c))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2138 {
1353
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2139 has_lower = TRUE;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2140 if (MB_ISUPPER(wca[i]))
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2141 {
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2142 /* Rule 1 is satisfied. */
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2143 for (i = actual_compl_length; i < actual_len; ++i)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2144 wca[i] = MB_TOLOWER(wca[i]);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2145 break;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2146 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2147 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2148 }
1353
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2149
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2150 /*
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2151 * Rule 2: No lower case, 2nd consecutive letter converted to
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2152 * upper case.
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2153 */
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2154 if (!has_lower)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2155 {
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2156 p = compl_orig_text;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2157 for (i = 0; i < actual_compl_length; ++i)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2158 {
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2159 #ifdef FEAT_MBYTE
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2160 if (has_mbyte)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2161 c = mb_ptr2char_adv(&p);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2162 else
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2163 #endif
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2164 c = *(p++);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2165 if (was_letter && MB_ISUPPER(c) && MB_ISLOWER(wca[i]))
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2166 {
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2167 /* Rule 2 is satisfied. */
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2168 for (i = actual_compl_length; i < actual_len; ++i)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2169 wca[i] = MB_TOUPPER(wca[i]);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2170 break;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2171 }
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2172 was_letter = MB_ISLOWER(c) || MB_ISUPPER(c);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2173 }
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2174 }
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2175
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2176 /* Copy the original case of the part we typed. */
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2177 p = compl_orig_text;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2178 for (i = 0; i < actual_compl_length; ++i)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2179 {
1353
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2180 #ifdef FEAT_MBYTE
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2181 if (has_mbyte)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2182 c = mb_ptr2char_adv(&p);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2183 else
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2184 #endif
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2185 c = *(p++);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2186 if (MB_ISLOWER(c))
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2187 wca[i] = MB_TOLOWER(wca[i]);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2188 else if (MB_ISUPPER(c))
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2189 wca[i] = MB_TOUPPER(wca[i]);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2190 }
1353
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2191
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2192 /*
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2193 * Generate encoding specific output from wide character array.
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2194 * Multi-byte characters can occupy up to five bytes more than
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2195 * ASCII characters, and we also need one byte for NUL, so stay
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2196 * six bytes away from the edge of IObuff.
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2197 */
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2198 p = IObuff;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2199 i = 0;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2200 while (i < actual_len && (p - IObuff + 6) < IOSIZE)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2201 #ifdef FEAT_MBYTE
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2202 if (has_mbyte)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2203 p += mb_char2bytes(wca[i++], p);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2204 else
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2205 #endif
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2206 *(p++) = wca[i++];
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2207 *p = NUL;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2208
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2209 vim_free(wca);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2210 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2211
841
c2cae213194d updated for version 7.0e07
vimboss
parents: 840
diff changeset
2212 return ins_compl_add(IObuff, len, icase, fname, NULL, dir,
c2cae213194d updated for version 7.0e07
vimboss
parents: 840
diff changeset
2213 flags, FALSE);
c2cae213194d updated for version 7.0e07
vimboss
parents: 840
diff changeset
2214 }
c2cae213194d updated for version 7.0e07
vimboss
parents: 840
diff changeset
2215 return ins_compl_add(str, len, icase, fname, NULL, dir, flags, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2216 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2217
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2218 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2219 * Add a match to the list of matches.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2220 * If the given string is already in the list of completions, then return
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2221 * NOTDONE, otherwise add it to the list and return OK. If there is an error,
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2222 * maybe because alloc() returns NULL, then FAIL is returned.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2223 */
841
c2cae213194d updated for version 7.0e07
vimboss
parents: 840
diff changeset
2224 static int
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
2225 ins_compl_add(str, len, icase, fname, cptext, cdir, flags, adup)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2226 char_u *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2227 int len;
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2228 int icase;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2229 char_u *fname;
841
c2cae213194d updated for version 7.0e07
vimboss
parents: 840
diff changeset
2230 char_u **cptext; /* extra text for popup menu or NULL */
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2231 int cdir;
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2232 int flags;
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
2233 int adup; /* accept duplicate match */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2234 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2235 compl_T *match;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2236 int dir = (cdir == 0 ? compl_direction : cdir);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2237
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2238 ui_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2239 if (got_int)
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2240 return FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2241 if (len < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2242 len = (int)STRLEN(str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2243
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2244 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2245 * If the same match is already present, don't add it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2246 */
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
2247 if (compl_first_match != NULL && !adup)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2248 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2249 match = compl_first_match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2250 do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2251 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2252 if ( !(match->cp_flags & ORIGINAL_TEXT)
989
3f8cf4c668c3 updated for version 7.0-115
vimboss
parents: 987
diff changeset
2253 && STRNCMP(match->cp_str, str, len) == 0
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2254 && match->cp_str[len] == NUL)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2255 return NOTDONE;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2256 match = match->cp_next;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2257 } while (match != NULL && match != compl_first_match);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2258 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2259
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2260 /* Remove any popup menu before changing the list of matches. */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2261 ins_compl_del_pum();
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2262
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2263 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2264 * Allocate a new match structure.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2265 * Copy the values to the new match structure.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2266 */
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2267 match = (compl_T *)alloc_clear((unsigned)sizeof(compl_T));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2268 if (match == NULL)
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2269 return FAIL;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2270 match->cp_number = -1;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2271 if (flags & ORIGINAL_TEXT)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2272 match->cp_number = 0;
694
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
2273 if ((match->cp_str = vim_strnsave(str, len)) == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2274 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2275 vim_free(match);
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2276 return FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2277 }
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2278 match->cp_icase = icase;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2279
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2280 /* match-fname is:
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2281 * - compl_curr_match->cp_fname if it is a string equal to fname.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2282 * - a copy of fname, FREE_FNAME is set to free later THE allocated mem.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2283 * - NULL otherwise. --Acevedo */
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2284 if (fname != NULL
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
2285 && compl_curr_match != NULL
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2286 && compl_curr_match->cp_fname != NULL
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2287 && STRCMP(fname, compl_curr_match->cp_fname) == 0)
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2288 match->cp_fname = compl_curr_match->cp_fname;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2289 else if (fname != NULL)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2290 {
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2291 match->cp_fname = vim_strsave(fname);
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2292 flags |= FREE_FNAME;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2293 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2294 else
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2295 match->cp_fname = NULL;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2296 match->cp_flags = flags;
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2297
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2298 if (cptext != NULL)
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2299 {
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2300 int i;
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2301
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2302 for (i = 0; i < CPT_COUNT; ++i)
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2303 if (cptext[i] != NULL && *cptext[i] != NUL)
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2304 match->cp_text[i] = vim_strsave(cptext[i]);
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2305 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2306
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2307 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2308 * Link the new match structure in the list of matches.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2309 */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2310 if (compl_first_match == NULL)
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2311 match->cp_next = match->cp_prev = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2312 else if (dir == FORWARD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2313 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2314 match->cp_next = compl_curr_match->cp_next;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2315 match->cp_prev = compl_curr_match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2316 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2317 else /* BACKWARD */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2318 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2319 match->cp_next = compl_curr_match;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2320 match->cp_prev = compl_curr_match->cp_prev;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2321 }
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2322 if (match->cp_next)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2323 match->cp_next->cp_prev = match;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2324 if (match->cp_prev)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2325 match->cp_prev->cp_next = match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2326 else /* if there's nothing before, it is the first match */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2327 compl_first_match = match;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2328 compl_curr_match = match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2329
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2330 /*
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2331 * Find the longest common string if still doing that.
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2332 */
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2333 if (compl_get_longest && (flags & ORIGINAL_TEXT) == 0)
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2334 ins_compl_longest_match(match);
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2335
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2336 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2337 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2338
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2339 /*
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2340 * Return TRUE if "str[len]" matches with match->cp_str, considering
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2341 * match->cp_icase.
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2342 */
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2343 static int
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2344 ins_compl_equal(match, str, len)
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2345 compl_T *match;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2346 char_u *str;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2347 int len;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2348 {
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2349 if (match->cp_icase)
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2350 return STRNICMP(match->cp_str, str, (size_t)len) == 0;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2351 return STRNCMP(match->cp_str, str, (size_t)len) == 0;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2352 }
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2353
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2354 /*
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2355 * Reduce the longest common string for match "match".
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2356 */
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2357 static void
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2358 ins_compl_longest_match(match)
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2359 compl_T *match;
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2360 {
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2361 char_u *p, *s;
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2362 int c1, c2;
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2363 int had_match;
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2364
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2365 if (compl_leader == NULL)
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2366 {
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2367 /* First match, use it as a whole. */
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2368 compl_leader = vim_strsave(match->cp_str);
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2369 if (compl_leader != NULL)
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2370 {
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2371 had_match = (curwin->w_cursor.col > compl_col);
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2372 ins_compl_delete();
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2373 ins_bytes(compl_leader + curwin->w_cursor.col - compl_col);
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2374 ins_redraw(FALSE);
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2375
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2376 /* When the match isn't there (to avoid matching itself) remove it
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2377 * again after redrawing. */
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2378 if (!had_match)
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2379 ins_compl_delete();
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2380 compl_used_match = FALSE;
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2381 }
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2382 }
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2383 else
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2384 {
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2385 /* Reduce the text if this match differs from compl_leader. */
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2386 p = compl_leader;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2387 s = match->cp_str;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2388 while (*p != NUL)
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2389 {
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2390 #ifdef FEAT_MBYTE
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2391 if (has_mbyte)
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2392 {
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2393 c1 = mb_ptr2char(p);
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2394 c2 = mb_ptr2char(s);
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2395 }
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2396 else
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2397 #endif
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2398 {
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2399 c1 = *p;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2400 c2 = *s;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2401 }
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2402 if (match->cp_icase ? (MB_TOLOWER(c1) != MB_TOLOWER(c2))
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2403 : (c1 != c2))
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2404 break;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2405 #ifdef FEAT_MBYTE
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2406 if (has_mbyte)
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2407 {
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2408 mb_ptr_adv(p);
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2409 mb_ptr_adv(s);
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2410 }
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2411 else
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2412 #endif
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2413 {
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2414 ++p;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2415 ++s;
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2416 }
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2417 }
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2418
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2419 if (*p != NUL)
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2420 {
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2421 /* Leader was shortened, need to change the inserted text. */
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2422 *p = NUL;
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2423 had_match = (curwin->w_cursor.col > compl_col);
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2424 ins_compl_delete();
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2425 ins_bytes(compl_leader + curwin->w_cursor.col - compl_col);
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2426 ins_redraw(FALSE);
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2427
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2428 /* When the match isn't there (to avoid matching itself) remove it
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2429 * again after redrawing. */
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2430 if (!had_match)
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2431 ins_compl_delete();
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2432 }
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2433
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2434 compl_used_match = FALSE;
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2435 }
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2436 }
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2437
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2438 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2439 * Add an array of matches to the list of matches.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2440 * Frees matches[].
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2441 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2442 static void
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2443 ins_compl_add_matches(num_matches, matches, icase)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2444 int num_matches;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2445 char_u **matches;
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2446 int icase;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2447 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2448 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2449 int add_r = OK;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2450 int dir = compl_direction;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2451
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2452 for (i = 0; i < num_matches && add_r != FAIL; i++)
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2453 if ((add_r = ins_compl_add(matches[i], -1, icase,
841
c2cae213194d updated for version 7.0e07
vimboss
parents: 840
diff changeset
2454 NULL, NULL, dir, 0, FALSE)) == OK)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2455 /* if dir was BACKWARD then honor it just once */
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2456 dir = FORWARD;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2457 FreeWild(num_matches, matches);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2458 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2459
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2460 /* Make the completion list cyclic.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2461 * Return the number of matches (excluding the original).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2462 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2463 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2464 ins_compl_make_cyclic()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2465 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2466 compl_T *match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2467 int count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2468
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2469 if (compl_first_match != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2470 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2471 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2472 * Find the end of the list.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2473 */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2474 match = compl_first_match;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2475 /* there's always an entry for the compl_orig_text, it doesn't count. */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2476 while (match->cp_next != NULL && match->cp_next != compl_first_match)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2477 {
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2478 match = match->cp_next;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2479 ++count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2480 }
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2481 match->cp_next = compl_first_match;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2482 compl_first_match->cp_prev = match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2483 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2484 return count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2485 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2486
724
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2487 /*
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2488 * Start completion for the complete() function.
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2489 * "startcol" is where the matched text starts (1 is first column).
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2490 * "list" is the list of matches.
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2491 */
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2492 void
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2493 set_completion(startcol, list)
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2494 int startcol;
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2495 list_T *list;
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2496 {
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2497 /* If already doing completions stop it. */
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2498 if (ctrl_x_mode != 0)
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2499 ins_compl_prep(' ');
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2500 ins_compl_clear();
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2501
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2502 if (stop_arrow() == FAIL)
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2503 return;
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2504
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
2505 if (startcol > (int)curwin->w_cursor.col)
724
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2506 startcol = curwin->w_cursor.col;
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2507 compl_col = startcol;
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2508 compl_length = curwin->w_cursor.col - startcol;
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2509 /* compl_pattern doesn't need to be set */
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2510 compl_orig_text = vim_strnsave(ml_get_curline() + compl_col, compl_length);
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2511 if (compl_orig_text == NULL || ins_compl_add(compl_orig_text,
942
29bf49bad20d updated for version 7.0-068
vimboss
parents: 941
diff changeset
2512 -1, p_ic, NULL, NULL, 0, ORIGINAL_TEXT, FALSE) != OK)
724
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2513 return;
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2514
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2515 /* Handle like dictionary completion. */
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2516 ctrl_x_mode = CTRL_X_WHOLE_LINE;
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2517
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2518 ins_compl_add_list(list);
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2519 compl_matches = ins_compl_make_cyclic();
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2520 compl_started = TRUE;
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2521 compl_used_match = TRUE;
929
2448f4c8afc6 updated for version 7.0-055
vimboss
parents: 909
diff changeset
2522 compl_cont_status = 0;
724
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2523
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2524 compl_curr_match = compl_first_match;
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2525 ins_complete(Ctrl_N);
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2526 out_flush();
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2527 }
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2528
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2529
574
25a70b1cd2da updated for version 7.0163
vimboss
parents: 548
diff changeset
2530 /* "compl_match_array" points the currently displayed list of entries in the
25a70b1cd2da updated for version 7.0163
vimboss
parents: 548
diff changeset
2531 * popup menu. It is NULL when there is no popup menu. */
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2532 static pumitem_T *compl_match_array = NULL;
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2533 static int compl_match_arraysize;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2534
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2535 /*
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2536 * Update the screen and when there is any scrolling remove the popup menu.
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2537 */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2538 static void
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2539 ins_compl_upd_pum()
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2540 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2541 int h;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2542
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2543 if (compl_match_array != NULL)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2544 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2545 h = curwin->w_cline_height;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2546 update_screen(0);
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2547 if (h != curwin->w_cline_height)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2548 ins_compl_del_pum();
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2549 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2550 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2551
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2552 /*
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2553 * Remove any popup menu.
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2554 */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2555 static void
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2556 ins_compl_del_pum()
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2557 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2558 if (compl_match_array != NULL)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2559 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2560 pum_undisplay();
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2561 vim_free(compl_match_array);
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2562 compl_match_array = NULL;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2563 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2564 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2565
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2566 /*
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2567 * Return TRUE if the popup menu should be displayed.
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2568 */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2569 static int
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2570 pum_wanted()
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2571 {
707
111b7dcc8a17 updated for version 7.0213
vimboss
parents: 703
diff changeset
2572 /* 'completeopt' must contain "menu" or "menuone" */
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2573 if (vim_strchr(p_cot, 'm') == NULL)
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2574 return FALSE;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2575
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2576 /* The display looks bad on a B&W display. */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2577 if (t_colors < 8
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2578 #ifdef FEAT_GUI
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2579 && !gui.in_use
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2580 #endif
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2581 )
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2582 return FALSE;
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2583 return TRUE;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2584 }
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2585
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2586 /*
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2587 * Return TRUE if there are two or more matches to be shown in the popup menu.
707
111b7dcc8a17 updated for version 7.0213
vimboss
parents: 703
diff changeset
2588 * One if 'completopt' contains "menuone".
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2589 */
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2590 static int
707
111b7dcc8a17 updated for version 7.0213
vimboss
parents: 703
diff changeset
2591 pum_enough_matches()
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2592 {
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2593 compl_T *compl;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2594 int i;
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2595
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2596 /* Don't display the popup menu if there are no matches or there is only
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2597 * one (ignoring the original text). */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2598 compl = compl_first_match;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2599 i = 0;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2600 do
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2601 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2602 if (compl == NULL
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2603 || ((compl->cp_flags & ORIGINAL_TEXT) == 0 && ++i == 2))
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2604 break;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2605 compl = compl->cp_next;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2606 } while (compl != compl_first_match);
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2607
707
111b7dcc8a17 updated for version 7.0213
vimboss
parents: 703
diff changeset
2608 if (strstr((char *)p_cot, "menuone") != NULL)
111b7dcc8a17 updated for version 7.0213
vimboss
parents: 703
diff changeset
2609 return (i >= 1);
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2610 return (i >= 2);
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2611 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2612
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2613 /*
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2614 * Show the popup menu for the list of matches.
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2615 * Also adjusts "compl_shown_match" to an entry that is actually displayed.
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2616 */
648
9032e4668296 updated for version 7.0189
vimboss
parents: 644
diff changeset
2617 void
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2618 ins_compl_show_pum()
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2619 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2620 compl_T *compl;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2621 compl_T *shown_compl = NULL;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2622 int did_find_shown_match = FALSE;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2623 int shown_match_ok = FALSE;
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2624 int i;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2625 int cur = -1;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2626 colnr_T col;
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2627 int lead_len = 0;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2628
707
111b7dcc8a17 updated for version 7.0213
vimboss
parents: 703
diff changeset
2629 if (!pum_wanted() || !pum_enough_matches())
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2630 return;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2631
794
f19994020dad updated for version 7.0231
vimboss
parents: 786
diff changeset
2632 #if defined(FEAT_EVAL)
f19994020dad updated for version 7.0231
vimboss
parents: 786
diff changeset
2633 /* Dirty hard-coded hack: remove any matchparen highlighting. */
f19994020dad updated for version 7.0231
vimboss
parents: 786
diff changeset
2634 do_cmdline_cmd((char_u *)"if exists('g:loaded_matchparen')|3match none|endif");
f19994020dad updated for version 7.0231
vimboss
parents: 786
diff changeset
2635 #endif
f19994020dad updated for version 7.0231
vimboss
parents: 786
diff changeset
2636
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2637 /* Update the screen before drawing the popup menu over it. */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2638 update_screen(0);
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2639
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2640 if (compl_match_array == NULL)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2641 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2642 /* Need to build the popup menu list. */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2643 compl_match_arraysize = 0;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2644 compl = compl_first_match;
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2645 if (compl_leader != NULL)
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 829
diff changeset
2646 lead_len = (int)STRLEN(compl_leader);
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2647 do
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2648 {
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2649 if ((compl->cp_flags & ORIGINAL_TEXT) == 0
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2650 && (compl_leader == NULL
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2651 || ins_compl_equal(compl, compl_leader, lead_len)))
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2652 ++compl_match_arraysize;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2653 compl = compl->cp_next;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2654 } while (compl != NULL && compl != compl_first_match);
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2655 if (compl_match_arraysize == 0)
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2656 return;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2657 compl_match_array = (pumitem_T *)alloc_clear(
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2658 (unsigned)(sizeof(pumitem_T)
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2659 * compl_match_arraysize));
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2660 if (compl_match_array != NULL)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2661 {
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
2662 /* If the current match is the original text don't find the first
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
2663 * match after it, don't highlight anything. */
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
2664 if (compl_shown_match->cp_flags & ORIGINAL_TEXT)
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
2665 shown_match_ok = TRUE;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
2666
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2667 i = 0;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2668 compl = compl_first_match;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2669 do
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2670 {
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2671 if ((compl->cp_flags & ORIGINAL_TEXT) == 0
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2672 && (compl_leader == NULL
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2673 || ins_compl_equal(compl, compl_leader, lead_len)))
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2674 {
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2675 if (!shown_match_ok)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2676 {
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2677 if (compl == compl_shown_match || did_find_shown_match)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2678 {
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2679 /* This item is the shown match or this is the
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2680 * first displayed item after the shown match. */
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2681 compl_shown_match = compl;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2682 did_find_shown_match = TRUE;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2683 shown_match_ok = TRUE;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2684 }
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2685 else
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2686 /* Remember this displayed match for when the
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2687 * shown match is just below it. */
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2688 shown_compl = compl;
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2689 cur = i;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2690 }
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2691
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2692 if (compl->cp_text[CPT_ABBR] != NULL)
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2693 compl_match_array[i].pum_text =
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2694 compl->cp_text[CPT_ABBR];
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2695 else
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2696 compl_match_array[i].pum_text = compl->cp_str;
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2697 compl_match_array[i].pum_kind = compl->cp_text[CPT_KIND];
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2698 compl_match_array[i].pum_info = compl->cp_text[CPT_INFO];
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2699 if (compl->cp_text[CPT_MENU] != NULL)
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2700 compl_match_array[i++].pum_extra =
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2701 compl->cp_text[CPT_MENU];
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2702 else
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2703 compl_match_array[i++].pum_extra = compl->cp_fname;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2704 }
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2705
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2706 if (compl == compl_shown_match)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2707 {
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2708 did_find_shown_match = TRUE;
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
2709
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
2710 /* When the original text is the shown match don't set
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
2711 * compl_shown_match. */
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
2712 if (compl->cp_flags & ORIGINAL_TEXT)
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
2713 shown_match_ok = TRUE;
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
2714
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2715 if (!shown_match_ok && shown_compl != NULL)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2716 {
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2717 /* The shown match isn't displayed, set it to the
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2718 * previously displayed match. */
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2719 compl_shown_match = shown_compl;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2720 shown_match_ok = TRUE;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2721 }
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2722 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2723 compl = compl->cp_next;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2724 } while (compl != NULL && compl != compl_first_match);
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2725
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2726 if (!shown_match_ok) /* no displayed match at all */
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2727 cur = -1;
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2728 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2729 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2730 else
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2731 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2732 /* popup menu already exists, only need to find the current item.*/
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2733 for (i = 0; i < compl_match_arraysize; ++i)
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2734 if (compl_match_array[i].pum_text == compl_shown_match->cp_str
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2735 || compl_match_array[i].pum_text
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2736 == compl_shown_match->cp_text[CPT_ABBR])
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
2737 {
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
2738 cur = i;
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2739 break;
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
2740 }
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2741 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2742
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2743 if (compl_match_array != NULL)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2744 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2745 /* Compute the screen column of the start of the completed text.
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2746 * Use the cursor to get all wrapping and other settings right. */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2747 col = curwin->w_cursor.col;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2748 curwin->w_cursor.col = compl_col;
732
f7034dd506fd updated for version 7.0221
vimboss
parents: 724
diff changeset
2749 pum_display(compl_match_array, compl_match_arraysize, cur);
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2750 curwin->w_cursor.col = col;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2751 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2752 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2753
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2754 #define DICT_FIRST (1) /* use just first element in "dict" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2755 #define DICT_EXACT (2) /* "dict" is the exact name of a file */
648
9032e4668296 updated for version 7.0189
vimboss
parents: 644
diff changeset
2756
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2757 /*
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2758 * Add any identifiers that match the given pattern in the list of dictionary
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2759 * files "dict_start" to the list of completions.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2760 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2761 static void
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2762 ins_compl_dictionaries(dict_start, pat, flags, thesaurus)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2763 char_u *dict_start;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2764 char_u *pat;
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
2765 int flags; /* DICT_FIRST and/or DICT_EXACT */
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2766 int thesaurus; /* Thesaurus completion */
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2767 {
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2768 char_u *dict = dict_start;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2769 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2770 char_u *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2771 regmatch_T regmatch;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2772 char_u **files;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2773 int count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2774 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2775 int save_p_scs;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2776 int dir = compl_direction;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2777
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2778 if (*dict == NUL)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2779 {
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
2780 #ifdef FEAT_SPELL
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2781 /* When 'dictionary' is empty and spell checking is enabled use
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2782 * "spell". */
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2783 if (!thesaurus && curwin->w_p_spell)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2784 dict = (char_u *)"spell";
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2785 else
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2786 #endif
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2787 return;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2788 }
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2789
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2790 buf = alloc(LSIZE);
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2791 if (buf == NULL)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2792 return;
1074
a112fdce9ebd updated for version 7.0-200
vimboss
parents: 1073
diff changeset
2793 regmatch.regprog = NULL; /* so that we can goto theend */
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2794
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2795 /* If 'infercase' is set, don't use 'smartcase' here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2796 save_p_scs = p_scs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2797 if (curbuf->b_p_inf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2798 p_scs = FALSE;
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
2799
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
2800 /* When invoked to match whole lines for CTRL-X CTRL-L adjust the pattern
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
2801 * to only match at the start of a line. Otherwise just match the
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2802 * pattern. Also need to double backslashes. */
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
2803 if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
2804 {
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2805 char_u *pat_esc = vim_strsave_escaped(pat, (char_u *)"\\");
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2806
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2807 if (pat_esc == NULL)
1159
b5ee70fc4b0c updated for version 7.1a
vimboss
parents: 1085
diff changeset
2808 goto theend;
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2809 i = (int)STRLEN(pat_esc) + 10;
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
2810 ptr = alloc(i);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
2811 if (ptr == NULL)
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2812 {
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2813 vim_free(pat_esc);
1074
a112fdce9ebd updated for version 7.0-200
vimboss
parents: 1073
diff changeset
2814 goto theend;
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2815 }
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2816 vim_snprintf((char *)ptr, i, "^\\s*\\zs\\V%s", pat_esc);
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2817 regmatch.regprog = vim_regcomp(ptr, RE_MAGIC);
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2818 vim_free(pat_esc);
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
2819 vim_free(ptr);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
2820 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
2821 else
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2822 {
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
2823 regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0);
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2824 if (regmatch.regprog == NULL)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2825 goto theend;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2826 }
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
2827
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2828 /* ignore case depends on 'ignorecase', 'smartcase' and "pat" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2829 regmatch.rm_ic = ignorecase(pat);
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2830 while (*dict != NUL && !got_int && !compl_interrupted)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2831 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2832 /* copy one dictionary file name into buf */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2833 if (flags == DICT_EXACT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2834 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2835 count = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2836 files = &dict;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2837 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2838 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2839 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2840 /* Expand wildcards in the dictionary name, but do not allow
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2841 * backticks (for security, the 'dict' option may have been set in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2842 * a modeline). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2843 copy_option_part(&dict, buf, LSIZE, ",");
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
2844 # ifdef FEAT_SPELL
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2845 if (!thesaurus && STRCMP(buf, "spell") == 0)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2846 count = -1;
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
2847 else
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
2848 # endif
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
2849 if (vim_strchr(buf, '`') != NULL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2850 || expand_wildcards(1, &buf, &count, &files,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2851 EW_FILE|EW_SILENT) != OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2852 count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2853 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2854
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
2855 # ifdef FEAT_SPELL
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2856 if (count == -1)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2857 {
712
2e887dfa8917 updated for version 7.0214
vimboss
parents: 707
diff changeset
2858 /* Complete from active spelling. Skip "\<" in the pattern, we
2e887dfa8917 updated for version 7.0214
vimboss
parents: 707
diff changeset
2859 * don't use it as a RE. */
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2860 if (pat[0] == '\\' && pat[1] == '<')
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2861 ptr = pat + 2;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2862 else
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2863 ptr = pat;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2864 spell_dump_compl(curbuf, ptr, regmatch.rm_ic, &dir, 0);
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2865 }
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2866 else
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
2867 # endif
938
fc0c566b9107 updated for version 7.0-064
vimboss
parents: 935
diff changeset
2868 if (count > 0) /* avoid warning for using "files" uninit */
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2869 {
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2870 ins_compl_files(count, files, thesaurus, flags,
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2871 &regmatch, buf, &dir);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2872 if (flags != DICT_EXACT)
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2873 FreeWild(count, files);
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2874 }
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2875 if (flags != 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2876 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2877 }
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2878
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2879 theend:
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2880 p_scs = save_p_scs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2881 vim_free(regmatch.regprog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2882 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2883 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2884
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2885 static void
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2886 ins_compl_files(count, files, thesaurus, flags, regmatch, buf, dir)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2887 int count;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2888 char_u **files;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2889 int thesaurus;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2890 int flags;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2891 regmatch_T *regmatch;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2892 char_u *buf;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2893 int *dir;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2894 {
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2895 char_u *ptr;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2896 int i;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2897 FILE *fp;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2898 int add_r;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2899
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2900 for (i = 0; i < count && !got_int && !compl_interrupted; i++)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2901 {
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2902 fp = mch_fopen((char *)files[i], "r"); /* open dictionary file */
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2903 if (flags != DICT_EXACT)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2904 {
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2905 vim_snprintf((char *)IObuff, IOSIZE,
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2906 _("Scanning dictionary: %s"), (char *)files[i]);
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2907 msg_trunc_attr(IObuff, TRUE, hl_attr(HLF_R));
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2908 }
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2909
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2910 if (fp != NULL)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2911 {
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2912 /*
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2913 * Read dictionary file line by line.
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2914 * Check each line for a match.
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2915 */
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2916 while (!got_int && !compl_interrupted
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2917 && !vim_fgets(buf, LSIZE, fp))
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2918 {
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2919 ptr = buf;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2920 while (vim_regexec(regmatch, buf, (colnr_T)(ptr - buf)))
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2921 {
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2922 ptr = regmatch->startp[0];
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2923 if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2924 ptr = find_line_end(ptr);
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2925 else
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2926 ptr = find_word_end(ptr);
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2927 add_r = ins_compl_add_infercase(regmatch->startp[0],
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2928 (int)(ptr - regmatch->startp[0]),
942
29bf49bad20d updated for version 7.0-068
vimboss
parents: 941
diff changeset
2929 p_ic, files[i], *dir, 0);
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2930 if (thesaurus)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2931 {
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2932 char_u *wstart;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2933
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2934 /*
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2935 * Add the other matches on the line
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2936 */
1353
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2937 ptr = buf;
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2938 while (!got_int)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2939 {
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2940 /* Find start of the next word. Skip white
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2941 * space and punctuation. */
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2942 ptr = find_word_start(ptr);
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2943 if (*ptr == NUL || *ptr == NL)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2944 break;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2945 wstart = ptr;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2946
1353
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2947 /* Find end of the word. */
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2948 #ifdef FEAT_MBYTE
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2949 if (has_mbyte)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2950 /* Japanese words may have characters in
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2951 * different classes, only separate words
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2952 * with single-byte non-word characters. */
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2953 while (*ptr != NUL)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2954 {
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2955 int l = (*mb_ptr2len)(ptr);
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2956
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2957 if (l < 2 && !vim_iswordc(*ptr))
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2958 break;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2959 ptr += l;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2960 }
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2961 else
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2962 #endif
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2963 ptr = find_word_end(ptr);
1353
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2964
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2965 /* Add the word. Skip the regexp match. */
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2966 if (wstart != regmatch->startp[0])
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2967 add_r = ins_compl_add_infercase(wstart,
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2968 (int)(ptr - wstart),
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2969 p_ic, files[i], *dir, 0);
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2970 }
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2971 }
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2972 if (add_r == OK)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2973 /* if dir was BACKWARD then honor it just once */
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2974 *dir = FORWARD;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2975 else if (add_r == FAIL)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2976 break;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2977 /* avoid expensive call to vim_regexec() when at end
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2978 * of line */
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2979 if (*ptr == '\n' || got_int)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2980 break;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2981 }
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2982 line_breakcheck();
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2983 ins_compl_check_keys(50);
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2984 }
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2985 fclose(fp);
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2986 }
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2987 }
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2988 }
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2989
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2990 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2991 * Find the start of the next word.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2992 * Returns a pointer to the first char of the word. Also stops at a NUL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2993 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2994 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2995 find_word_start(ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2996 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2997 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2998 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2999 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3000 while (*ptr != NUL && *ptr != '\n' && mb_get_class(ptr) <= 1)
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 470
diff changeset
3001 ptr += (*mb_ptr2len)(ptr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3002 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3003 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3004 while (*ptr != NUL && *ptr != '\n' && !vim_iswordc(*ptr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3005 ++ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3006 return ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3007 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3008
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3009 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3010 * Find the end of the word. Assumes it starts inside a word.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3011 * Returns a pointer to just after the word.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3012 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3013 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3014 find_word_end(ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3015 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3016 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3017 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3018 int start_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3019
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3020 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3021 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3022 start_class = mb_get_class(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3023 if (start_class > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3024 while (*ptr != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3025 {
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 470
diff changeset
3026 ptr += (*mb_ptr2len)(ptr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3027 if (mb_get_class(ptr) != start_class)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3028 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3029 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3030 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3031 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3032 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3033 while (vim_iswordc(*ptr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3034 ++ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3035 return ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3036 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3037
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3038 /*
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3039 * Find the end of the line, omitting CR and NL at the end.
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3040 * Returns a pointer to just after the line.
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3041 */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3042 static char_u *
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3043 find_line_end(ptr)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3044 char_u *ptr;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3045 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3046 char_u *s;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3047
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3048 s = ptr + STRLEN(ptr);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3049 while (s > ptr && (s[-1] == CAR || s[-1] == NL))
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3050 --s;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3051 return s;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3052 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3053
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3054 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3055 * Free the list of completions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3056 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3057 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3058 ins_compl_free()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3059 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3060 compl_T *match;
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3061 int i;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3062
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3063 vim_free(compl_pattern);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3064 compl_pattern = NULL;
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3065 vim_free(compl_leader);
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3066 compl_leader = NULL;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3067
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3068 if (compl_first_match == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3069 return;
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3070
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3071 ins_compl_del_pum();
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3072 pum_clear();
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3073
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3074 compl_curr_match = compl_first_match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3075 do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3076 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3077 match = compl_curr_match;
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3078 compl_curr_match = compl_curr_match->cp_next;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3079 vim_free(match->cp_str);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3080 /* several entries may use the same fname, free it just once. */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3081 if (match->cp_flags & FREE_FNAME)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3082 vim_free(match->cp_fname);
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3083 for (i = 0; i < CPT_COUNT; ++i)
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3084 vim_free(match->cp_text[i]);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3085 vim_free(match);
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3086 } while (compl_curr_match != NULL && compl_curr_match != compl_first_match);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3087 compl_first_match = compl_curr_match = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3088 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3089
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3090 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3091 ins_compl_clear()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3092 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3093 compl_cont_status = 0;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3094 compl_started = FALSE;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3095 compl_matches = 0;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3096 vim_free(compl_pattern);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3097 compl_pattern = NULL;
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3098 vim_free(compl_leader);
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3099 compl_leader = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3100 edit_submode_extra = NULL;
724
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3101 vim_free(compl_orig_text);
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3102 compl_orig_text = NULL;
825
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
3103 compl_enter_selects = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3104 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3105
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3106 /*
674
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
3107 * Return TRUE when Insert completion is active.
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
3108 */
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
3109 int
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
3110 ins_compl_active()
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
3111 {
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
3112 return compl_started;
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
3113 }
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
3114
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
3115 /*
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3116 * Delete one character before the cursor and show the subset of the matches
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3117 * that match the word that is now before the cursor.
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3118 * Returns the character to be used, NUL if the work is done and another char
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3119 * to be got from the user.
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3120 */
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3121 static int
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3122 ins_compl_bs()
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3123 {
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3124 char_u *line;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3125 char_u *p;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3126
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3127 line = ml_get_curline();
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3128 p = line + curwin->w_cursor.col;
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3129 mb_ptr_back(line, p);
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3130
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3131 /* Stop completion when the whole word was deleted. */
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3132 if ((int)(p - line) - (int)compl_col <= 0)
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3133 return K_BS;
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3134
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3135 /* Deleted more than what was used to find matches or didn't finish
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3136 * finding all matches: need to look for matches all over again. */
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3137 if (curwin->w_cursor.col <= compl_col + compl_length
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3138 || compl_was_interrupted)
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3139 ins_compl_restart();
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3140
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3141 vim_free(compl_leader);
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 829
diff changeset
3142 compl_leader = vim_strnsave(line + compl_col, (int)(p - line) - compl_col);
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3143 if (compl_leader != NULL)
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3144 {
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3145 ins_compl_new_leader();
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3146 return NUL;
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3147 }
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3148 return K_BS;
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3149 }
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3150
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3151 /*
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3152 * Called after changing "compl_leader".
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3153 * Show the popup menu with a different set of matches.
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3154 * May also search for matches again if the previous search was interrupted.
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3155 */
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3156 static void
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3157 ins_compl_new_leader()
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3158 {
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3159 ins_compl_del_pum();
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3160 ins_compl_delete();
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3161 ins_bytes(compl_leader + curwin->w_cursor.col - compl_col);
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3162 compl_used_match = FALSE;
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3163
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3164 if (compl_started)
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3165 ins_compl_set_original_text(compl_leader);
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3166 else
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3167 {
826
1cdd2661f34c updated for version 7.0d01
vimboss
parents: 825
diff changeset
3168 #ifdef FEAT_SPELL
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3169 spell_bad_len = 0; /* need to redetect bad word */
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3170 #endif
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3171 /*
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3172 * Matches were cleared, need to search for them now. First display
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3173 * the changed text before the cursor. Set "compl_restarting" to
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3174 * avoid that the first match is inserted.
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3175 */
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3176 update_screen(0);
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3177 #ifdef FEAT_GUI
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3178 if (gui.in_use)
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3179 {
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3180 /* Show the cursor after the match, not after the redrawn text. */
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3181 setcursor();
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3182 out_flush();
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3183 gui_update_cursor(FALSE, FALSE);
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3184 }
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3185 #endif
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3186 compl_restarting = TRUE;
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3187 if (ins_complete(Ctrl_N) == FAIL)
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3188 compl_cont_status = 0;
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3189 compl_restarting = FALSE;
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3190 }
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3191
887
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3192 #if 0 /* disabled, made CTRL-L, BS and typing char jump to original text. */
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3193 if (!compl_used_match)
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3194 {
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
3195 /* Go to the original text, since none of the matches is inserted. */
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
3196 if (compl_first_match->cp_prev != NULL
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
3197 && (compl_first_match->cp_prev->cp_flags & ORIGINAL_TEXT))
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
3198 compl_shown_match = compl_first_match->cp_prev;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
3199 else
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
3200 compl_shown_match = compl_first_match;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
3201 compl_curr_match = compl_shown_match;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
3202 compl_shows_dir = compl_direction;
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3203 }
887
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3204 #endif
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3205 compl_enter_selects = !compl_used_match;
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3206
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3207 /* Show the popup menu with a different set of matches. */
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3208 ins_compl_show_pum();
947
a157c4786b79 updated for version 7.0-073
vimboss
parents: 944
diff changeset
3209
a157c4786b79 updated for version 7.0-073
vimboss
parents: 944
diff changeset
3210 /* Don't let Enter select the original text when there is no popup menu. */
a157c4786b79 updated for version 7.0-073
vimboss
parents: 944
diff changeset
3211 if (compl_match_array == NULL)
a157c4786b79 updated for version 7.0-073
vimboss
parents: 944
diff changeset
3212 compl_enter_selects = FALSE;
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3213 }
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3214
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3215 /*
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3216 * Append one character to the match leader. May reduce the number of
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3217 * matches.
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3218 */
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3219 static void
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3220 ins_compl_addleader(c)
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3221 int c;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3222 {
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3223 #ifdef FEAT_MBYTE
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3224 int cc;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3225
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3226 if (has_mbyte && (cc = (*mb_char2len)(c)) > 1)
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3227 {
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3228 char_u buf[MB_MAXBYTES + 1];
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3229
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3230 (*mb_char2bytes)(c, buf);
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3231 buf[cc] = NUL;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3232 ins_char_bytes(buf, cc);
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3233 }
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3234 else
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3235 #endif
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3236 ins_char(c);
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3237
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3238 /* If we didn't complete finding matches we must search again. */
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3239 if (compl_was_interrupted)
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3240 ins_compl_restart();
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3241
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3242 vim_free(compl_leader);
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3243 compl_leader = vim_strnsave(ml_get_curline() + compl_col,
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3244 curwin->w_cursor.col - compl_col);
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3245 if (compl_leader != NULL)
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3246 ins_compl_new_leader();
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3247 }
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3248
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3249 /*
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3250 * Setup for finding completions again without leaving CTRL-X mode. Used when
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3251 * BS or a key was typed while still searching for matches.
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3252 */
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3253 static void
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3254 ins_compl_restart()
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3255 {
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3256 ins_compl_free();
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3257 compl_started = FALSE;
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3258 compl_matches = 0;
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3259 compl_cont_status = 0;
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3260 compl_cont_mode = 0;
694
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3261 }
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3262
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3263 /*
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3264 * Set the first match, the original text.
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3265 */
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3266 static void
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3267 ins_compl_set_original_text(str)
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3268 char_u *str;
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3269 {
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3270 char_u *p;
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3271
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3272 /* Replace the original text entry. */
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3273 if (compl_first_match->cp_flags & ORIGINAL_TEXT) /* safety check */
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3274 {
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3275 p = vim_strsave(str);
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3276 if (p != NULL)
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3277 {
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3278 vim_free(compl_first_match->cp_str);
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3279 compl_first_match->cp_str = p;
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3280 }
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3281 }
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3282 }
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3283
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3284 /*
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3285 * Append one character to the match leader. May reduce the number of
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3286 * matches.
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3287 */
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3288 static void
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3289 ins_compl_addfrommatch()
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3290 {
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3291 char_u *p;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3292 int len = curwin->w_cursor.col - compl_col;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3293 int c;
887
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3294 compl_T *cp;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3295
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3296 p = compl_shown_match->cp_str;
677
e649c78407e6 updated for version 7.0202
vimboss
parents: 674
diff changeset
3297 if ((int)STRLEN(p) <= len) /* the match is too short */
887
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3298 {
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3299 /* When still at the original match use the first entry that matches
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3300 * the leader. */
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3301 if (compl_shown_match->cp_flags & ORIGINAL_TEXT)
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3302 {
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3303 p = NULL;
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3304 for (cp = compl_shown_match->cp_next; cp != NULL
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3305 && cp != compl_first_match; cp = cp->cp_next)
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3306 {
987
e625dad74346 updated for version 7.0-113
vimboss
parents: 978
diff changeset
3307 if (compl_leader == NULL
e625dad74346 updated for version 7.0-113
vimboss
parents: 978
diff changeset
3308 || ins_compl_equal(cp, compl_leader,
887
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3309 (int)STRLEN(compl_leader)))
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3310 {
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3311 p = cp->cp_str;
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3312 break;
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3313 }
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3314 }
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3315 if (p == NULL || (int)STRLEN(p) <= len)
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3316 return;
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3317 }
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3318 else
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3319 return;
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3320 }
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3321 p += len;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3322 #ifdef FEAT_MBYTE
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3323 c = mb_ptr2char(p);
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3324 #else
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3325 c = *p;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3326 #endif
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3327 ins_compl_addleader(c);
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3328 }
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3329
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3330 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3331 * Prepare for Insert mode completion, or stop it.
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3332 * Called just after typing a character in Insert mode.
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3333 * Returns TRUE when the character is not to be inserted;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3334 */
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3335 static int
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3336 ins_compl_prep(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3337 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3338 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3339 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3340 int want_cindent;
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3341 int retval = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3342
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3343 /* Forget any previous 'special' messages if this is actually
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3344 * a ^X mode key - bar ^R, in which case we wait to see what it gives us.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3345 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3346 if (c != Ctrl_R && vim_is_ctrl_x_key(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3347 edit_submode_extra = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3348
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3349 /* Ignore end of Select mode mapping */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3350 if (c == K_SELECT)
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3351 return retval;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3352
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
3353 /* Set "compl_get_longest" when finding the first matches. */
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
3354 if (ctrl_x_mode == CTRL_X_NOT_DEFINED_YET
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
3355 || (ctrl_x_mode == 0 && !compl_started))
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
3356 {
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
3357 compl_get_longest = (vim_strchr(p_cot, 'l') != NULL);
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
3358 compl_used_match = TRUE;
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
3359 }
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
3360
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3361 if (ctrl_x_mode == CTRL_X_NOT_DEFINED_YET)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3362 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3363 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3364 * We have just typed CTRL-X and aren't quite sure which CTRL-X mode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3365 * it will be yet. Now we decide.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3366 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3367 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3368 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3369 case Ctrl_E:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3370 case Ctrl_Y:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3371 ctrl_x_mode = CTRL_X_SCROLL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3372 if (!(State & REPLACE_FLAG))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3373 edit_submode = (char_u *)_(" (insert) Scroll (^E/^Y)");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3374 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3375 edit_submode = (char_u *)_(" (replace) Scroll (^E/^Y)");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3376 edit_submode_pre = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3377 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3378 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3379 case Ctrl_L:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3380 ctrl_x_mode = CTRL_X_WHOLE_LINE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3381 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3382 case Ctrl_F:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3383 ctrl_x_mode = CTRL_X_FILES;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3384 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3385 case Ctrl_K:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3386 ctrl_x_mode = CTRL_X_DICTIONARY;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3387 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3388 case Ctrl_R:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3389 /* Simply allow ^R to happen without affecting ^X mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3390 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3391 case Ctrl_T:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3392 ctrl_x_mode = CTRL_X_THESAURUS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3393 break;
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3394 #ifdef FEAT_COMPL_FUNC
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3395 case Ctrl_U:
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3396 ctrl_x_mode = CTRL_X_FUNCTION;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3397 break;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3398 case Ctrl_O:
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
3399 ctrl_x_mode = CTRL_X_OMNI;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3400 break;
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3401 #endif
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3402 case 's':
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3403 case Ctrl_S:
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3404 ctrl_x_mode = CTRL_X_SPELL;
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
3405 #ifdef FEAT_SPELL
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
3406 ++emsg_off; /* Avoid getting the E756 error twice. */
484
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
3407 spell_back_to_badword();
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
3408 --emsg_off;
484
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
3409 #endif
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3410 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3411 case Ctrl_RSB:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3412 ctrl_x_mode = CTRL_X_TAGS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3413 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3414 #ifdef FEAT_FIND_ID
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3415 case Ctrl_I:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3416 case K_S_TAB:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3417 ctrl_x_mode = CTRL_X_PATH_PATTERNS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3418 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3419 case Ctrl_D:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3420 ctrl_x_mode = CTRL_X_PATH_DEFINES;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3421 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3422 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3423 case Ctrl_V:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3424 case Ctrl_Q:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3425 ctrl_x_mode = CTRL_X_CMDLINE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3426 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3427 case Ctrl_P:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3428 case Ctrl_N:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3429 /* ^X^P means LOCAL expansion if nothing interrupted (eg we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3430 * just started ^X mode, or there were enough ^X's to cancel
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3431 * the previous mode, say ^X^F^X^X^P or ^P^X^X^X^P, see below)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3432 * do normal expansion when interrupting a different mode (say
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3433 * ^X^F^X^P or ^P^X^X^P, see below)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3434 * nothing changes if interrupting mode 0, (eg, the flag
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3435 * doesn't change when going to ADDING mode -- Acevedo */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3436 if (!(compl_cont_status & CONT_INTRPT))
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3437 compl_cont_status |= CONT_LOCAL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3438 else if (compl_cont_mode != 0)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3439 compl_cont_status &= ~CONT_LOCAL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3440 /* FALLTHROUGH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3441 default:
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3442 /* If we have typed at least 2 ^X's... for modes != 0, we set
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3443 * compl_cont_status = 0 (eg, as if we had just started ^X
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3444 * mode).
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3445 * For mode 0, we set "compl_cont_mode" to an impossible
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3446 * value, in both cases ^X^X can be used to restart the same
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3447 * mode (avoiding ADDING mode).
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3448 * Undocumented feature: In a mode != 0 ^X^P and ^X^X^P start
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3449 * 'complete' and local ^P expansions respectively.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3450 * In mode 0 an extra ^X is needed since ^X^P goes to ADDING
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3451 * mode -- Acevedo */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3452 if (c == Ctrl_X)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3453 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3454 if (compl_cont_mode != 0)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3455 compl_cont_status = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3456 else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3457 compl_cont_mode = CTRL_X_NOT_DEFINED_YET;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3458 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3459 ctrl_x_mode = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3460 edit_submode = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3461 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3462 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3463 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3464 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3465 else if (ctrl_x_mode != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3466 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3467 /* We're already in CTRL-X mode, do we stay in it? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3468 if (!vim_is_ctrl_x_key(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3469 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3470 if (ctrl_x_mode == CTRL_X_SCROLL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3471 ctrl_x_mode = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3472 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3473 ctrl_x_mode = CTRL_X_FINISHED;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3474 edit_submode = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3475 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3476 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3477 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3478
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3479 if (compl_started || ctrl_x_mode == CTRL_X_FINISHED)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3480 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3481 /* Show error message from attempted keyword completion (probably
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3482 * 'Pattern not found') until another key is hit, then go back to
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3483 * showing what mode we are in. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3484 showmode();
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
3485 if ((ctrl_x_mode == 0 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_R
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
3486 && !ins_compl_pum_key(c))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3487 || ctrl_x_mode == CTRL_X_FINISHED)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3488 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3489 /* Get here when we have finished typing a sequence of ^N and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3490 * ^P or other completion characters in CTRL-X mode. Free up
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3491 * memory that was used, and make sure we can redo the insert. */
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3492 if (compl_curr_match != NULL || compl_leader != NULL || c == Ctrl_E)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3493 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3494 char_u *p;
938
fc0c566b9107 updated for version 7.0-064
vimboss
parents: 935
diff changeset
3495 int temp = 0;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3496
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3497 /*
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3498 * If any of the original typed text has been changed, eg when
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3499 * ignorecase is set, we must add back-spaces to the redo
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3500 * buffer. We add as few as necessary to delete just the part
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3501 * of the original text that has changed.
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3502 * When using the longest match, edited the match or used
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3503 * CTRL-E then don't use the current match.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3504 */
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3505 if (compl_curr_match != NULL && compl_used_match && c != Ctrl_E)
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3506 ptr = compl_curr_match->cp_str;
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3507 else if (compl_leader != NULL)
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3508 ptr = compl_leader;
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3509 else
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3510 ptr = compl_orig_text;
897
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3511 if (compl_orig_text != NULL)
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3512 {
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3513 p = compl_orig_text;
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3514 for (temp = 0; p[temp] != NUL && p[temp] == ptr[temp];
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3515 ++temp)
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3516 ;
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3517 #ifdef FEAT_MBYTE
897
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3518 if (temp > 0)
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3519 temp -= (*mb_head_off)(compl_orig_text, p + temp);
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3520 #endif
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3521 for (p += temp; *p != NUL; mb_ptr_adv(p))
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3522 AppendCharToRedobuff(K_BS);
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3523 }
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3524 if (ptr != NULL)
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3525 AppendToRedobuffLit(ptr + temp, -1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3526 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3527
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3528 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3529 want_cindent = (can_cindent && cindent_on());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3530 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3531 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3532 * When completing whole lines: fix indent for 'cindent'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3533 * Otherwise, break line if it's too long.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3534 */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3535 if (compl_cont_mode == CTRL_X_WHOLE_LINE)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3536 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3537 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3538 /* re-indent the current line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3539 if (want_cindent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3540 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3541 do_c_expr_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3542 want_cindent = FALSE; /* don't do it again */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3543 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3544 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3545 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3546 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3547 {
1073
ec7a570696ac updated for version 7.0-199
vimboss
parents: 1063
diff changeset
3548 int prev_col = curwin->w_cursor.col;
ec7a570696ac updated for version 7.0-199
vimboss
parents: 1063
diff changeset
3549
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3550 /* put the cursor on the last char, for 'tw' formatting */
1073
ec7a570696ac updated for version 7.0-199
vimboss
parents: 1063
diff changeset
3551 if (prev_col > 0)
ec7a570696ac updated for version 7.0-199
vimboss
parents: 1063
diff changeset
3552 dec_cursor();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3553 if (stop_arrow() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3554 insertchar(NUL, 0, -1);
1073
ec7a570696ac updated for version 7.0-199
vimboss
parents: 1063
diff changeset
3555 if (prev_col > 0
ec7a570696ac updated for version 7.0-199
vimboss
parents: 1063
diff changeset
3556 && ml_get_curline()[curwin->w_cursor.col] != NUL)
ec7a570696ac updated for version 7.0-199
vimboss
parents: 1063
diff changeset
3557 inc_cursor();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3558 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3559
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3560 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3561
816
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 794
diff changeset
3562 /* If the popup menu is displayed pressing CTRL-Y means accepting
825
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
3563 * the selection without inserting anything. When
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
3564 * compl_enter_selects is set the Enter key does the same. */
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
3565 if ((c == Ctrl_Y || (compl_enter_selects
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
3566 && (c == CAR || c == K_KENTER || c == NL)))
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
3567 && pum_visible())
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3568 retval = TRUE;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3569
816
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 794
diff changeset
3570 /* CTRL-E means completion is Ended, go back to the typed text. */
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 794
diff changeset
3571 if (c == Ctrl_E)
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 794
diff changeset
3572 {
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 794
diff changeset
3573 ins_compl_delete();
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 794
diff changeset
3574 if (compl_leader != NULL)
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 794
diff changeset
3575 ins_bytes(compl_leader + curwin->w_cursor.col - compl_col);
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 794
diff changeset
3576 else if (compl_first_match != NULL)
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
3577 ins_bytes(compl_orig_text
816
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 794
diff changeset
3578 + curwin->w_cursor.col - compl_col);
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 794
diff changeset
3579 retval = TRUE;
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 794
diff changeset
3580 }
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 794
diff changeset
3581
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3582 ins_compl_free();
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3583 compl_started = FALSE;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3584 compl_matches = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3585 msg_clr_cmdline(); /* necessary for "noshowmode" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3586 ctrl_x_mode = 0;
825
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
3587 compl_enter_selects = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3588 if (edit_submode != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3589 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3590 edit_submode = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3591 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3592 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3593
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3594 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3595 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3596 * Indent now if a key was typed that is in 'cinkeys'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3597 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3598 if (want_cindent && in_cinkeys(KEY_COMPLETE, ' ', inindent(0)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3599 do_c_expr_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3600 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3601 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3602 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3603
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3604 /* reset continue_* if we left expansion-mode, if we stay they'll be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3605 * (re)set properly in ins_complete() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3606 if (!vim_is_ctrl_x_key(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3607 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3608 compl_cont_status = 0;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3609 compl_cont_mode = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3610 }
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3611
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3612 return retval;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3613 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3614
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3615 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3616 * Loops through the list of windows, loaded-buffers or non-loaded-buffers
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3617 * (depending on flag) starting from buf and looking for a non-scanned
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3618 * buffer (other than curbuf). curbuf is special, if it is called with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3619 * buf=curbuf then it has to be the first call for a given flag/expansion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3620 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3621 * Returns the buffer to scan, if any, otherwise returns curbuf -- Acevedo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3622 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3623 static buf_T *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3624 ins_compl_next_buf(buf, flag)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3625 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3626 int flag;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3627 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3628 #ifdef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3629 static win_T *wp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3630 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3631
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3632 if (flag == 'w') /* just windows */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3633 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3634 #ifdef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3635 if (buf == curbuf) /* first call for this flag/expansion */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3636 wp = curwin;
383
8c229eb52e34 updated for version 7.0099
vimboss
parents: 359
diff changeset
3637 while ((wp = (wp->w_next != NULL ? wp->w_next : firstwin)) != curwin
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3638 && wp->w_buffer->b_scanned)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3639 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3640 buf = wp->w_buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3641 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3642 buf = curbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3643 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3644 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3645 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3646 /* 'b' (just loaded buffers), 'u' (just non-loaded buffers) or 'U'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3647 * (unlisted buffers)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3648 * When completing whole lines skip unloaded buffers. */
383
8c229eb52e34 updated for version 7.0099
vimboss
parents: 359
diff changeset
3649 while ((buf = (buf->b_next != NULL ? buf->b_next : firstbuf)) != curbuf
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3650 && ((flag == 'U'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3651 ? buf->b_p_bl
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3652 : (!buf->b_p_bl
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3653 || (buf->b_ml.ml_mfp == NULL) != (flag == 'u')))
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3654 || buf->b_scanned))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3655 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3656 return buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3657 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3658
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3659 #ifdef FEAT_COMPL_FUNC
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3660 static void expand_by_function __ARGS((int type, char_u *base));
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3661
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3662 /*
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
3663 * Execute user defined complete function 'completefunc' or 'omnifunc', and
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3664 * get matches in "matches".
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3665 */
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3666 static void
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3667 expand_by_function(type, base)
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
3668 int type; /* CTRL_X_OMNI or CTRL_X_FUNCTION */
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3669 char_u *base;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3670 {
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
3671 list_T *matchlist;
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3672 char_u *args[2];
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3673 char_u *funcname;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3674 pos_T pos;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3675
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3676 funcname = (type == CTRL_X_FUNCTION) ? curbuf->b_p_cfu : curbuf->b_p_ofu;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3677 if (*funcname == NUL)
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3678 return;
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
3679
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
3680 /* Call 'completefunc' to obtain the list of matches. */
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
3681 args[0] = (char_u *)"0";
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3682 args[1] = base;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3683
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3684 pos = curwin->w_cursor;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3685 matchlist = call_func_retlist(funcname, 2, args, FALSE);
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3686 curwin->w_cursor = pos; /* restore the cursor position */
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
3687 if (matchlist == NULL)
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3688 return;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3689
724
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3690 ins_compl_add_list(matchlist);
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3691 list_unref(matchlist);
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3692 }
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3693 #endif /* FEAT_COMPL_FUNC */
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3694
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3695 #if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL) || defined(PROTO)
724
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3696 /*
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3697 * Add completions from a list.
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3698 */
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3699 static void
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3700 ins_compl_add_list(list)
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3701 list_T *list;
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3702 {
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3703 listitem_T *li;
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3704 int dir = compl_direction;
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3705
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3706 /* Go through the List with matches and add each of them. */
724
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3707 for (li = list->lv_first; li != NULL; li = li->li_next)
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
3708 {
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3709 if (ins_compl_add_tv(&li->li_tv, dir) == OK)
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3710 /* if dir was BACKWARD then honor it just once */
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3711 dir = FORWARD;
648
9032e4668296 updated for version 7.0189
vimboss
parents: 644
diff changeset
3712 else if (did_emsg)
9032e4668296 updated for version 7.0189
vimboss
parents: 644
diff changeset
3713 break;
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
3714 }
724
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3715 }
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3716
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3717 /*
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3718 * Add a match to the list of matches from a typeval_T.
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3719 * If the given string is already in the list of completions, then return
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3720 * NOTDONE, otherwise add it to the list and return OK. If there is an error,
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3721 * maybe because alloc() returns NULL, then FAIL is returned.
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3722 */
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3723 int
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3724 ins_compl_add_tv(tv, dir)
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3725 typval_T *tv;
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3726 int dir;
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3727 {
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3728 char_u *word;
867
a5677b7ce858 updated for version 7.0g04
vimboss
parents: 864
diff changeset
3729 int icase = FALSE;
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
3730 int adup = FALSE;
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3731 char_u *(cptext[CPT_COUNT]);
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3732
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3733 if (tv->v_type == VAR_DICT && tv->vval.v_dict != NULL)
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3734 {
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3735 word = get_dict_string(tv->vval.v_dict, (char_u *)"word", FALSE);
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3736 cptext[CPT_ABBR] = get_dict_string(tv->vval.v_dict,
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3737 (char_u *)"abbr", FALSE);
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3738 cptext[CPT_MENU] = get_dict_string(tv->vval.v_dict,
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3739 (char_u *)"menu", FALSE);
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3740 cptext[CPT_KIND] = get_dict_string(tv->vval.v_dict,
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3741 (char_u *)"kind", FALSE);
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3742 cptext[CPT_INFO] = get_dict_string(tv->vval.v_dict,
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3743 (char_u *)"info", FALSE);
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3744 if (get_dict_string(tv->vval.v_dict, (char_u *)"icase", FALSE) != NULL)
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3745 icase = get_dict_number(tv->vval.v_dict, (char_u *)"icase");
841
c2cae213194d updated for version 7.0e07
vimboss
parents: 840
diff changeset
3746 if (get_dict_string(tv->vval.v_dict, (char_u *)"dup", FALSE) != NULL)
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
3747 adup = get_dict_number(tv->vval.v_dict, (char_u *)"dup");
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3748 }
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3749 else
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3750 {
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3751 word = get_tv_string_chk(tv);
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3752 vim_memset(cptext, 0, sizeof(cptext));
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3753 }
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3754 if (word == NULL || *word == NUL)
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3755 return FAIL;
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
3756 return ins_compl_add(word, -1, icase, NULL, cptext, dir, 0, adup);
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3757 }
724
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3758 #endif
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3759
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3760 /*
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3761 * Get the next expansion(s), using "compl_pattern".
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3762 * The search starts at position "ini" in curbuf and in the direction
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3763 * compl_direction.
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3764 * When "compl_started" is FALSE start at that position, otherwise continue
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3765 * where we stopped searching before.
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3766 * This may return before finding all the matches.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3767 * Return the total number of matches or -1 if still unknown -- Acevedo
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3768 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3769 static int
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3770 ins_compl_get_exp(ini)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3771 pos_T *ini;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3772 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3773 static pos_T first_match_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3774 static pos_T last_match_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3775 static char_u *e_cpt = (char_u *)""; /* curr. entry in 'complete' */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3776 static int found_all = FALSE; /* Found all matches of a
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3777 certain type. */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3778 static buf_T *ins_buf = NULL; /* buffer being scanned */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3779
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3780 pos_T *pos;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3781 char_u **matches;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3782 int save_p_scs;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3783 int save_p_ws;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3784 int save_p_ic;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3785 int i;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3786 int num_matches;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3787 int len;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3788 int found_new_match;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3789 int type = ctrl_x_mode;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3790 char_u *ptr;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3791 char_u *dict = NULL;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3792 int dict_f = 0;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3793 compl_T *old_match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3794
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3795 if (!compl_started)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3796 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3797 for (ins_buf = firstbuf; ins_buf != NULL; ins_buf = ins_buf->b_next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3798 ins_buf->b_scanned = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3799 found_all = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3800 ins_buf = curbuf;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3801 e_cpt = (compl_cont_status & CONT_LOCAL)
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3802 ? (char_u *)"." : curbuf->b_p_cpt;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3803 last_match_pos = first_match_pos = *ini;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3804 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3805
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3806 old_match = compl_curr_match; /* remember the last current match */
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3807 pos = (compl_direction == FORWARD) ? &last_match_pos : &first_match_pos;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3808 /* For ^N/^P loop over all the flags/windows/buffers in 'complete' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3809 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3810 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3811 found_new_match = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3812
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3813 /* For ^N/^P pick a new entry from e_cpt if compl_started is off,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3814 * or if found_all says this entry is done. For ^X^L only use the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3815 * entries from 'complete' that look in loaded buffers. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3816 if ((ctrl_x_mode == 0 || ctrl_x_mode == CTRL_X_WHOLE_LINE)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3817 && (!compl_started || found_all))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3818 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3819 found_all = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3820 while (*e_cpt == ',' || *e_cpt == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3821 e_cpt++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3822 if (*e_cpt == '.' && !curbuf->b_scanned)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3823 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3824 ins_buf = curbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3825 first_match_pos = *ini;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3826 /* So that ^N can match word immediately after cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3827 if (ctrl_x_mode == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3828 dec(&first_match_pos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3829 last_match_pos = first_match_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3830 type = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3831 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3832 else if (vim_strchr((char_u *)"buwU", *e_cpt) != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3833 && (ins_buf = ins_compl_next_buf(ins_buf, *e_cpt)) != curbuf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3834 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3835 /* Scan a buffer, but not the current one. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3836 if (ins_buf->b_ml.ml_mfp != NULL) /* loaded buffer */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3837 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3838 compl_started = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3839 first_match_pos.col = last_match_pos.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3840 first_match_pos.lnum = ins_buf->b_ml.ml_line_count + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3841 last_match_pos.lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3842 type = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3843 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3844 else /* unloaded buffer, scan like dictionary */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3845 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3846 found_all = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3847 if (ins_buf->b_fname == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3848 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3849 type = CTRL_X_DICTIONARY;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3850 dict = ins_buf->b_fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3851 dict_f = DICT_EXACT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3852 }
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 237
diff changeset
3853 vim_snprintf((char *)IObuff, IOSIZE, _("Scanning: %s"),
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3854 ins_buf->b_fname == NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3855 ? buf_spname(ins_buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3856 : ins_buf->b_sfname == NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3857 ? (char *)ins_buf->b_fname
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3858 : (char *)ins_buf->b_sfname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3859 msg_trunc_attr(IObuff, TRUE, hl_attr(HLF_R));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3860 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3861 else if (*e_cpt == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3862 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3863 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3864 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3865 if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3866 type = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3867 else if (*e_cpt == 'k' || *e_cpt == 's')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3868 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3869 if (*e_cpt == 'k')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3870 type = CTRL_X_DICTIONARY;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3871 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3872 type = CTRL_X_THESAURUS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3873 if (*++e_cpt != ',' && *e_cpt != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3874 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3875 dict = e_cpt;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3876 dict_f = DICT_FIRST;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3877 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3878 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3879 #ifdef FEAT_FIND_ID
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3880 else if (*e_cpt == 'i')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3881 type = CTRL_X_PATH_PATTERNS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3882 else if (*e_cpt == 'd')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3883 type = CTRL_X_PATH_DEFINES;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3884 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3885 else if (*e_cpt == ']' || *e_cpt == 't')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3886 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3887 type = CTRL_X_TAGS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3888 sprintf((char*)IObuff, _("Scanning tags."));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3889 msg_trunc_attr(IObuff, TRUE, hl_attr(HLF_R));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3890 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3891 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3892 type = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3893
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3894 /* in any case e_cpt is advanced to the next entry */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3895 (void)copy_option_part(&e_cpt, IObuff, IOSIZE, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3896
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3897 found_all = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3898 if (type == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3899 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3900 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3901 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3902
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3903 switch (type)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3904 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3905 case -1:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3906 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3907 #ifdef FEAT_FIND_ID
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3908 case CTRL_X_PATH_PATTERNS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3909 case CTRL_X_PATH_DEFINES:
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3910 find_pattern_in_path(compl_pattern, compl_direction,
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3911 (int)STRLEN(compl_pattern), FALSE, FALSE,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3912 (type == CTRL_X_PATH_DEFINES
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3913 && !(compl_cont_status & CONT_SOL))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3914 ? FIND_DEFINE : FIND_ANY, 1L, ACTION_EXPAND,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3915 (linenr_T)1, (linenr_T)MAXLNUM);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3916 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3917 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3918
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3919 case CTRL_X_DICTIONARY:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3920 case CTRL_X_THESAURUS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3921 ins_compl_dictionaries(
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3922 dict != NULL ? dict
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3923 : (type == CTRL_X_THESAURUS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3924 ? (*curbuf->b_p_tsr == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3925 ? p_tsr
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3926 : curbuf->b_p_tsr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3927 : (*curbuf->b_p_dict == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3928 ? p_dict
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3929 : curbuf->b_p_dict)),
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3930 compl_pattern,
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3931 dict != NULL ? dict_f
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3932 : 0, type == CTRL_X_THESAURUS);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3933 dict = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3934 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3935
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3936 case CTRL_X_TAGS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3937 /* set p_ic according to p_ic, p_scs and pat for find_tags(). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3938 save_p_ic = p_ic;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3939 p_ic = ignorecase(compl_pattern);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3940
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3941 /* Find up to TAG_MANY matches. Avoids that an enourmous number
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3942 * of matches is found when compl_pattern is empty */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3943 if (find_tags(compl_pattern, &num_matches, &matches,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3944 TAG_REGEXP | TAG_NAMES | TAG_NOIC |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3945 TAG_INS_COMP | (ctrl_x_mode ? TAG_VERBOSE : 0),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3946 TAG_MANY, curbuf->b_ffname) == OK && num_matches > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3947 {
942
29bf49bad20d updated for version 7.0-068
vimboss
parents: 941
diff changeset
3948 ins_compl_add_matches(num_matches, matches, p_ic);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3949 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3950 p_ic = save_p_ic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3951 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3952
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3953 case CTRL_X_FILES:
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3954 if (expand_wildcards(1, &compl_pattern, &num_matches, &matches,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3955 EW_FILE|EW_DIR|EW_ADDSLASH|EW_SILENT) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3956 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3957
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3958 /* May change home directory back to "~". */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3959 tilde_replace(compl_pattern, num_matches, matches);
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
3960 ins_compl_add_matches(num_matches, matches,
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
3961 #ifdef CASE_INSENSITIVE_FILENAME
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
3962 TRUE
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
3963 #else
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
3964 FALSE
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
3965 #endif
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
3966 );
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3967 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3968 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3969
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3970 case CTRL_X_CMDLINE:
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3971 if (expand_cmdline(&compl_xp, compl_pattern,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3972 (int)STRLEN(compl_pattern),
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3973 &num_matches, &matches) == EXPAND_OK)
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
3974 ins_compl_add_matches(num_matches, matches, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3975 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3976
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3977 #ifdef FEAT_COMPL_FUNC
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3978 case CTRL_X_FUNCTION:
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
3979 case CTRL_X_OMNI:
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3980 expand_by_function(type, compl_pattern);
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3981 break;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3982 #endif
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3983
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3984 case CTRL_X_SPELL:
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
3985 #ifdef FEAT_SPELL
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3986 num_matches = expand_spelling(first_match_pos.lnum,
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3987 first_match_pos.col, compl_pattern, &matches);
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3988 if (num_matches > 0)
942
29bf49bad20d updated for version 7.0-068
vimboss
parents: 941
diff changeset
3989 ins_compl_add_matches(num_matches, matches, p_ic);
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3990 #endif
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3991 break;
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3992
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3993 default: /* normal ^P/^N and ^X^L */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3994 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3995 * If 'infercase' is set, don't use 'smartcase' here
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3996 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3997 save_p_scs = p_scs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3998 if (ins_buf->b_p_inf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3999 p_scs = FALSE;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4000
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4001 /* buffers other than curbuf are scanned from the beginning or the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4002 * end but never from the middle, thus setting nowrapscan in this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4003 * buffers is a good idea, on the other hand, we always set
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4004 * wrapscan for curbuf to avoid missing matches -- Acevedo,Webb */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4005 save_p_ws = p_ws;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4006 if (ins_buf != curbuf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4007 p_ws = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4008 else if (*e_cpt == '.')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4009 p_ws = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4010 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4011 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4012 int flags = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4013
1007
7d29124f77f5 updated for version 7.0-133
vimboss
parents: 1000
diff changeset
4014 ++msg_silent; /* Don't want messages for wrapscan. */
7d29124f77f5 updated for version 7.0-133
vimboss
parents: 1000
diff changeset
4015
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4016 /* ctrl_x_mode == CTRL_X_WHOLE_LINE || word-wise search that
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4017 * has added a word that was at the beginning of the line */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4018 if ( ctrl_x_mode == CTRL_X_WHOLE_LINE
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4019 || (compl_cont_status & CONT_SOL))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4020 found_new_match = search_for_exact_line(ins_buf, pos,
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
4021 compl_direction, compl_pattern);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4022 else
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
4023 found_new_match = searchit(NULL, ins_buf, pos,
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
4024 compl_direction,
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4025 compl_pattern, 1L, SEARCH_KEEP + SEARCH_NFMSG,
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
4026 RE_LAST, (linenr_T)0);
1007
7d29124f77f5 updated for version 7.0-133
vimboss
parents: 1000
diff changeset
4027 --msg_silent;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4028 if (!compl_started)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4029 {
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
4030 /* set "compl_started" even on fail */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4031 compl_started = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4032 first_match_pos = *pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4033 last_match_pos = *pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4034 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4035 else if (first_match_pos.lnum == last_match_pos.lnum
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4036 && first_match_pos.col == last_match_pos.col)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4037 found_new_match = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4038 if (found_new_match == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4039 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4040 if (ins_buf == curbuf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4041 found_all = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4042 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4043 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4044
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4045 /* when ADDING, the text before the cursor matches, skip it */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4046 if ( (compl_cont_status & CONT_ADDING) && ins_buf == curbuf
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4047 && ini->lnum == pos->lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4048 && ini->col == pos->col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4049 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4050 ptr = ml_get_buf(ins_buf, pos->lnum, FALSE) + pos->col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4051 if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4052 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4053 if (compl_cont_status & CONT_ADDING)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4054 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4055 if (pos->lnum >= ins_buf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4056 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4057 ptr = ml_get_buf(ins_buf, pos->lnum + 1, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4058 if (!p_paste)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4059 ptr = skipwhite(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4060 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4061 len = (int)STRLEN(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4062 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4063 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4064 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4065 char_u *tmp_ptr = ptr;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4066
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4067 if (compl_cont_status & CONT_ADDING)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4068 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4069 tmp_ptr += compl_length;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4070 /* Skip if already inside a word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4071 if (vim_iswordp(tmp_ptr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4072 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4073 /* Find start of next word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4074 tmp_ptr = find_word_start(tmp_ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4075 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4076 /* Find end of this word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4077 tmp_ptr = find_word_end(tmp_ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4078 len = (int)(tmp_ptr - ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4079
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4080 if ((compl_cont_status & CONT_ADDING)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4081 && len == compl_length)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4082 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4083 if (pos->lnum < ins_buf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4084 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4085 /* Try next line, if any. the new word will be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4086 * "join" as if the normal command "J" was used.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4087 * IOSIZE is always greater than
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4088 * compl_length, so the next STRNCPY always
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4089 * works -- Acevedo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4090 STRNCPY(IObuff, ptr, len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4091 ptr = ml_get_buf(ins_buf, pos->lnum + 1, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4092 tmp_ptr = ptr = skipwhite(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4093 /* Find start of next word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4094 tmp_ptr = find_word_start(tmp_ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4095 /* Find end of next word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4096 tmp_ptr = find_word_end(tmp_ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4097 if (tmp_ptr > ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4098 {
419
f713fc55bf7b updated for version 7.0109
vimboss
parents: 408
diff changeset
4099 if (*ptr != ')' && IObuff[len - 1] != TAB)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4100 {
419
f713fc55bf7b updated for version 7.0109
vimboss
parents: 408
diff changeset
4101 if (IObuff[len - 1] != ' ')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4102 IObuff[len++] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4103 /* IObuf =~ "\k.* ", thus len >= 2 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4104 if (p_js
419
f713fc55bf7b updated for version 7.0109
vimboss
parents: 408
diff changeset
4105 && (IObuff[len - 2] == '.'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4106 || (vim_strchr(p_cpo, CPO_JOINSP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4107 == NULL
419
f713fc55bf7b updated for version 7.0109
vimboss
parents: 408
diff changeset
4108 && (IObuff[len - 2] == '?'
f713fc55bf7b updated for version 7.0109
vimboss
parents: 408
diff changeset
4109 || IObuff[len - 2] == '!'))))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4110 IObuff[len++] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4111 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4112 /* copy as much as posible of the new word */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4113 if (tmp_ptr - ptr >= IOSIZE - len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4114 tmp_ptr = ptr + IOSIZE - len - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4115 STRNCPY(IObuff + len, ptr, tmp_ptr - ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4116 len += (int)(tmp_ptr - ptr);
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4117 flags |= CONT_S_IPOS;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4118 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4119 IObuff[len] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4120 ptr = IObuff;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4121 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4122 if (len == compl_length)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4123 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4124 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4125 }
942
29bf49bad20d updated for version 7.0-068
vimboss
parents: 941
diff changeset
4126 if (ins_compl_add_infercase(ptr, len, p_ic,
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4127 ins_buf == curbuf ? NULL : ins_buf->b_sfname,
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
4128 0, flags) != NOTDONE)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4129 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4130 found_new_match = OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4131 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4132 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4133 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4134 p_scs = save_p_scs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4135 p_ws = save_p_ws;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4136 }
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4137
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4138 /* check if compl_curr_match has changed, (e.g. other type of
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4139 * expansion added somenthing) */
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4140 if (type != 0 && compl_curr_match != old_match)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4141 found_new_match = OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4142
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4143 /* break the loop for specialized modes (use 'complete' just for the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4144 * generic ctrl_x_mode == 0) or when we've found a new match */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4145 if ((ctrl_x_mode != 0 && ctrl_x_mode != CTRL_X_WHOLE_LINE)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4146 || found_new_match != FAIL)
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4147 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4148 if (got_int)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4149 break;
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4150 /* Fill the popup menu as soon as possible. */
989
3f8cf4c668c3 updated for version 7.0-115
vimboss
parents: 987
diff changeset
4151 if (type != -1)
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4152 ins_compl_check_keys(0);
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4153
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4154 if ((ctrl_x_mode != 0 && ctrl_x_mode != CTRL_X_WHOLE_LINE)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4155 || compl_interrupted)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4156 break;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4157 compl_started = TRUE;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4158 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4159 else
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4160 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4161 /* Mark a buffer scanned when it has been scanned completely */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4162 if (type == 0 || type == CTRL_X_PATH_PATTERNS)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4163 ins_buf->b_scanned = TRUE;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4164
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4165 compl_started = FALSE;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4166 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4167 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4168 compl_started = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4169
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4170 if ((ctrl_x_mode == 0 || ctrl_x_mode == CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4171 && *e_cpt == NUL) /* Got to end of 'complete' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4172 found_new_match = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4173
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4174 i = -1; /* total of matches, unknown */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4175 if (found_new_match == FAIL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4176 || (ctrl_x_mode != 0 && ctrl_x_mode != CTRL_X_WHOLE_LINE))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4177 i = ins_compl_make_cyclic();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4178
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4179 /* If several matches were added (FORWARD) or the search failed and has
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4180 * just been made cyclic then we have to move compl_curr_match to the next
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4181 * or previous entry (if any) -- Acevedo */
724
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
4182 compl_curr_match = compl_direction == FORWARD ? old_match->cp_next
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
4183 : old_match->cp_prev;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4184 if (compl_curr_match == NULL)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4185 compl_curr_match = old_match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4186 return i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4187 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4188
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4189 /* Delete the old text being completed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4190 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4191 ins_compl_delete()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4192 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4193 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4194
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4195 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4196 * In insert mode: Delete the typed part.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4197 * In replace mode: Put the old characters back, if any.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4198 */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4199 i = compl_col + (compl_cont_status & CONT_ADDING ? compl_length : 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4200 backspace_until_column(i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4201 changed_cline_bef_curs();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4202 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4203
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4204 /* Insert the new text being completed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4205 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4206 ins_compl_insert()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4207 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4208 ins_bytes(compl_shown_match->cp_str + curwin->w_cursor.col - compl_col);
683
a39b8af64334 updated for version 7.0205
vimboss
parents: 681
diff changeset
4209 if (compl_shown_match->cp_flags & ORIGINAL_TEXT)
a39b8af64334 updated for version 7.0205
vimboss
parents: 681
diff changeset
4210 compl_used_match = FALSE;
a39b8af64334 updated for version 7.0205
vimboss
parents: 681
diff changeset
4211 else
a39b8af64334 updated for version 7.0205
vimboss
parents: 681
diff changeset
4212 compl_used_match = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4213 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4214
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4215 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4216 * Fill in the next completion in the current direction.
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4217 * If "allow_get_expansion" is TRUE, then we may call ins_compl_get_exp() to
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4218 * get more completions. If it is FALSE, then we just do nothing when there
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4219 * are no more completions in a given direction. The latter case is used when
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4220 * we are still in the middle of finding completions, to allow browsing
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4221 * through the ones found so far.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4222 * Return the total number of matches, or -1 if still unknown -- webb.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4223 *
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4224 * compl_curr_match is currently being used by ins_compl_get_exp(), so we use
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4225 * compl_shown_match here.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4226 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4227 * Note that this function may be called recursively once only. First with
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4228 * "allow_get_expansion" TRUE, which calls ins_compl_get_exp(), which in turn
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4229 * calls this function with "allow_get_expansion" FALSE.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4230 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4231 static int
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4232 ins_compl_next(allow_get_expansion, count, insert_match)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4233 int allow_get_expansion;
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4234 int count; /* repeat completion this many times; should
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4235 be at least 1 */
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4236 int insert_match; /* Insert the newly selected match */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4237 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4238 int num_matches = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4239 int i;
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4240 int todo = count;
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4241 compl_T *found_compl = NULL;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4242 int found_end = FALSE;
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
4243 int advance;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4244
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4245 if (compl_leader != NULL
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4246 && (compl_shown_match->cp_flags & ORIGINAL_TEXT) == 0)
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4247 {
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4248 /* Set "compl_shown_match" to the actually shown match, it may differ
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4249 * when "compl_leader" is used to omit some of the matches. */
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4250 while (!ins_compl_equal(compl_shown_match,
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 829
diff changeset
4251 compl_leader, (int)STRLEN(compl_leader))
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4252 && compl_shown_match->cp_next != NULL
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4253 && compl_shown_match->cp_next != compl_first_match)
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4254 compl_shown_match = compl_shown_match->cp_next;
887
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4255
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4256 /* If we didn't find it searching forward, and compl_shows_dir is
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4257 * backward, find the last match. */
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4258 if (compl_shows_dir == BACKWARD
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4259 && !ins_compl_equal(compl_shown_match,
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4260 compl_leader, (int)STRLEN(compl_leader))
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4261 && (compl_shown_match->cp_next == NULL
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4262 || compl_shown_match->cp_next == compl_first_match))
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4263 {
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4264 while (!ins_compl_equal(compl_shown_match,
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4265 compl_leader, (int)STRLEN(compl_leader))
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4266 && compl_shown_match->cp_prev != NULL
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4267 && compl_shown_match->cp_prev != compl_first_match)
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4268 compl_shown_match = compl_shown_match->cp_prev;
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4269 }
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4270 }
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4271
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4272 if (allow_get_expansion && insert_match
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
4273 && (!(compl_get_longest || compl_restarting) || compl_used_match))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4274 /* Delete old text to be replaced */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4275 ins_compl_delete();
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4276
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
4277 /* When finding the longest common text we stick at the original text,
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
4278 * don't let CTRL-N or CTRL-P move to the first match. */
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
4279 advance = count != 1 || !allow_get_expansion || !compl_get_longest;
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
4280
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
4281 /* When restarting the search don't insert the first match either. */
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
4282 if (compl_restarting)
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
4283 {
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
4284 advance = FALSE;
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
4285 compl_restarting = FALSE;
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
4286 }
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
4287
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4288 /* Repeat this for when <PageUp> or <PageDown> is typed. But don't wrap
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4289 * around. */
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4290 while (--todo >= 0)
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4291 {
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4292 if (compl_shows_dir == FORWARD && compl_shown_match->cp_next != NULL)
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4293 {
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4294 compl_shown_match = compl_shown_match->cp_next;
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4295 found_end = (compl_first_match != NULL
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4296 && (compl_shown_match->cp_next == compl_first_match
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4297 || compl_shown_match == compl_first_match));
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4298 }
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4299 else if (compl_shows_dir == BACKWARD
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4300 && compl_shown_match->cp_prev != NULL)
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4301 {
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4302 found_end = (compl_shown_match == compl_first_match);
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4303 compl_shown_match = compl_shown_match->cp_prev;
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4304 found_end |= (compl_shown_match == compl_first_match);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4305 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4306 else
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4307 {
909
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4308 if (!allow_get_expansion)
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4309 {
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4310 if (advance)
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4311 {
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4312 if (compl_shows_dir == BACKWARD)
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4313 compl_pending -= todo + 1;
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4314 else
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4315 compl_pending += todo + 1;
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4316 }
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4317 return -1;
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4318 }
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4319
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
4320 if (advance)
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
4321 {
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
4322 if (compl_shows_dir == BACKWARD)
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
4323 --compl_pending;
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
4324 else
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
4325 ++compl_pending;
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
4326 }
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4327
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
4328 /* Find matches. */
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
4329 num_matches = ins_compl_get_exp(&compl_startpos);
909
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4330
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4331 /* handle any pending completions */
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4332 while (compl_pending != 0 && compl_direction == compl_shows_dir
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
4333 && advance)
909
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4334 {
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4335 if (compl_pending > 0 && compl_shown_match->cp_next != NULL)
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4336 {
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4337 compl_shown_match = compl_shown_match->cp_next;
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4338 --compl_pending;
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4339 }
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4340 if (compl_pending < 0 && compl_shown_match->cp_prev != NULL)
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4341 {
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4342 compl_shown_match = compl_shown_match->cp_prev;
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4343 ++compl_pending;
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4344 }
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4345 else
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4346 break;
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4347 }
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4348 found_end = FALSE;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4349 }
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4350 if ((compl_shown_match->cp_flags & ORIGINAL_TEXT) == 0
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4351 && compl_leader != NULL
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4352 && !ins_compl_equal(compl_shown_match,
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 829
diff changeset
4353 compl_leader, (int)STRLEN(compl_leader)))
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4354 ++todo;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4355 else
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4356 /* Remember a matching item. */
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4357 found_compl = compl_shown_match;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4358
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4359 /* Stop at the end of the list when we found a usable match. */
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4360 if (found_end)
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4361 {
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4362 if (found_compl != NULL)
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4363 {
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4364 compl_shown_match = found_compl;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4365 break;
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4366 }
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4367 todo = 1; /* use first usable match after wrapping around */
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4368 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4369 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4370
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4371 /* Insert the text of the new completion, or the compl_leader. */
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4372 if (insert_match)
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4373 {
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4374 if (!compl_get_longest || compl_used_match)
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4375 ins_compl_insert();
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4376 else
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4377 ins_bytes(compl_leader + curwin->w_cursor.col - compl_col);
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4378 }
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4379 else
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4380 compl_used_match = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4381
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4382 if (!allow_get_expansion)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4383 {
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4384 /* may undisplay the popup menu first */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4385 ins_compl_upd_pum();
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4386
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4387 /* redraw to show the user what was inserted */
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4388 update_screen(0);
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4389
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4390 /* display the updated popup menu */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4391 ins_compl_show_pum();
864
bc620d6bdf06 updated for version 7.0g03
vimboss
parents: 857
diff changeset
4392 #ifdef FEAT_GUI
bc620d6bdf06 updated for version 7.0g03
vimboss
parents: 857
diff changeset
4393 if (gui.in_use)
bc620d6bdf06 updated for version 7.0g03
vimboss
parents: 857
diff changeset
4394 {
bc620d6bdf06 updated for version 7.0g03
vimboss
parents: 857
diff changeset
4395 /* Show the cursor after the match, not after the redrawn text. */
bc620d6bdf06 updated for version 7.0g03
vimboss
parents: 857
diff changeset
4396 setcursor();
bc620d6bdf06 updated for version 7.0g03
vimboss
parents: 857
diff changeset
4397 out_flush();
bc620d6bdf06 updated for version 7.0g03
vimboss
parents: 857
diff changeset
4398 gui_update_cursor(FALSE, FALSE);
bc620d6bdf06 updated for version 7.0g03
vimboss
parents: 857
diff changeset
4399 }
bc620d6bdf06 updated for version 7.0g03
vimboss
parents: 857
diff changeset
4400 #endif
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4401
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4402 /* Delete old text to be replaced, since we're still searching and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4403 * don't want to match ourselves! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4404 ins_compl_delete();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4405 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4406
825
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
4407 /* Enter will select a match when the match wasn't inserted and the popup
1219
aea597af5b4e updated for version 7.1b
vimboss
parents: 1159
diff changeset
4408 * menu is visible. */
825
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
4409 compl_enter_selects = !insert_match && compl_match_array != NULL;
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
4410
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4411 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4412 * Show the file name for the match (if any)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4413 * Truncate the file name to avoid a wait for return.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4414 */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4415 if (compl_shown_match->cp_fname != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4416 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4417 STRCPY(IObuff, "match in file ");
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4418 i = (vim_strsize(compl_shown_match->cp_fname) + 16) - sc_col;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4419 if (i <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4420 i = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4421 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4422 STRCAT(IObuff, "<");
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4423 STRCAT(IObuff, compl_shown_match->cp_fname + i);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4424 msg(IObuff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4425 redraw_cmdline = FALSE; /* don't overwrite! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4426 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4427
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4428 return num_matches;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4429 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4430
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4431 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4432 * Call this while finding completions, to check whether the user has hit a key
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4433 * that should change the currently displayed completion, or exit completion
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
4434 * mode. Also, when compl_pending is not zero, show a completion as soon as
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4435 * possible. -- webb
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4436 * "frequency" specifies out of how many calls we actually check.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4437 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4438 void
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4439 ins_compl_check_keys(frequency)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4440 int frequency;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4441 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4442 static int count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4443
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4444 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4445
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4446 /* Don't check when reading keys from a script. That would break the test
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4447 * scripts */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4448 if (using_script())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4449 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4450
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4451 /* Only do this at regular intervals */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4452 if (++count < frequency)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4453 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4454 count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4455
909
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4456 /* Check for a typed key. Do use mappings, otherwise vim_is_ctrl_x_key()
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4457 * can't do its work correctly. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4458 c = vpeekc_any();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4459 if (c != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4460 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4461 if (vim_is_ctrl_x_key(c) && c != Ctrl_X && c != Ctrl_R)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4462 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4463 c = safe_vgetc(); /* Eat the character */
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4464 compl_shows_dir = ins_compl_key2dir(c);
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4465 (void)ins_compl_next(FALSE, ins_compl_key2count(c),
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4466 c != K_UP && c != K_DOWN);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4467 }
909
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4468 else
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4469 {
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4470 /* Need to get the character to have KeyTyped set. We'll put it
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4471 * back with vungetc() below. */
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4472 c = safe_vgetc();
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4473
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4474 /* Don't interrupt completion when the character wasn't typed,
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4475 * e.g., when doing @q to replay keys. */
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4476 if (c != Ctrl_R && KeyTyped)
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4477 compl_interrupted = TRUE;
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4478
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4479 vungetc(c);
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4480 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4481 }
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
4482 if (compl_pending != 0 && !got_int)
909
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4483 {
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4484 int todo = compl_pending > 0 ? compl_pending : -compl_pending;
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4485
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4486 compl_pending = 0;
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4487 (void)ins_compl_next(FALSE, todo, TRUE);
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4488 }
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4489 }
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4490
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4491 /*
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4492 * Decide the direction of Insert mode complete from the key typed.
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4493 * Returns BACKWARD or FORWARD.
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4494 */
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4495 static int
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4496 ins_compl_key2dir(c)
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4497 int c;
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4498 {
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4499 if (c == Ctrl_P || c == Ctrl_L
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4500 || (pum_visible() && (c == K_PAGEUP || c == K_KPAGEUP
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4501 || c == K_S_UP || c == K_UP)))
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4502 return BACKWARD;
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4503 return FORWARD;
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4504 }
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4505
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4506 /*
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
4507 * Return TRUE for keys that are used for completion only when the popup menu
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
4508 * is visible.
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
4509 */
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
4510 static int
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
4511 ins_compl_pum_key(c)
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
4512 int c;
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
4513 {
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
4514 return pum_visible() && (c == K_PAGEUP || c == K_KPAGEUP || c == K_S_UP
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4515 || c == K_PAGEDOWN || c == K_KPAGEDOWN || c == K_S_DOWN
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4516 || c == K_UP || c == K_DOWN);
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
4517 }
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
4518
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
4519 /*
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4520 * Decide the number of completions to move forward.
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4521 * Returns 1 for most keys, height of the popup menu for page-up/down keys.
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4522 */
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4523 static int
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4524 ins_compl_key2count(c)
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4525 int c;
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4526 {
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4527 int h;
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4528
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4529 if (ins_compl_pum_key(c) && c != K_UP && c != K_DOWN)
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4530 {
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4531 h = pum_get_height();
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4532 if (h > 3)
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4533 h -= 2; /* keep some context */
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4534 return h;
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4535 }
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4536 return 1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4537 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4538
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4539 /*
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4540 * Return TRUE if completion with "c" should insert the match, FALSE if only
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4541 * to change the currently selected completion.
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4542 */
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4543 static int
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4544 ins_compl_use_match(c)
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4545 int c;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4546 {
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4547 switch (c)
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4548 {
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4549 case K_UP:
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4550 case K_DOWN:
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4551 case K_PAGEDOWN:
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4552 case K_KPAGEDOWN:
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4553 case K_S_DOWN:
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4554 case K_PAGEUP:
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4555 case K_KPAGEUP:
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4556 case K_S_UP:
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4557 return FALSE;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4558 }
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4559 return TRUE;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4560 }
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4561
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4562 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4563 * Do Insert mode completion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4564 * Called when character "c" was typed, which has a meaning for completion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4565 * Returns OK if completion was done, FAIL if something failed (out of mem).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4566 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4567 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4568 ins_complete(c)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4569 int c;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4570 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4571 char_u *line;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4572 int startcol = 0; /* column where searched text starts */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4573 colnr_T curs_col; /* cursor column */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4574 int n;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4575
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4576 compl_direction = ins_compl_key2dir(c);
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4577 if (!compl_started)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4578 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4579 /* First time we hit ^N or ^P (in a row, I mean) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4580
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4581 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4582 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4583 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4584 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4585 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4586 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4587 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4588 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4589
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4590 line = ml_get(curwin->w_cursor.lnum);
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4591 curs_col = curwin->w_cursor.col;
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
4592 compl_pending = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4593
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4594 /* if this same ctrl_x_mode has been interrupted use the text from
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4595 * "compl_startpos" to the cursor as a pattern to add a new word
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4596 * instead of expand the one before the cursor, in word-wise if
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4597 * "compl_startpos"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4598 * is not in the same line as the cursor then fix it (the line has
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4599 * been split because it was longer than 'tw'). if SOL is set then
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4600 * skip the previous pattern, a word at the beginning of the line has
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4601 * been inserted, we'll look for that -- Acevedo. */
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4602 if ((compl_cont_status & CONT_INTRPT) == CONT_INTRPT
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4603 && compl_cont_mode == ctrl_x_mode)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4604 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4605 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4606 * it is a continued search
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4607 */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4608 compl_cont_status &= ~CONT_INTRPT; /* remove INTRPT */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4609 if (ctrl_x_mode == 0 || ctrl_x_mode == CTRL_X_PATH_PATTERNS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4610 || ctrl_x_mode == CTRL_X_PATH_DEFINES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4611 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4612 if (compl_startpos.lnum != curwin->w_cursor.lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4613 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4614 /* line (probably) wrapped, set compl_startpos to the
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4615 * first non_blank in the line, if it is not a wordchar
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4616 * include it to get a better pattern, but then we don't
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4617 * want the "\\<" prefix, check it bellow */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4618 compl_col = (colnr_T)(skipwhite(line) - line);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4619 compl_startpos.col = compl_col;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4620 compl_startpos.lnum = curwin->w_cursor.lnum;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4621 compl_cont_status &= ~CONT_SOL; /* clear SOL if present */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4622 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4623 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4624 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4625 /* S_IPOS was set when we inserted a word that was at the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4626 * beginning of the line, which means that we'll go to SOL
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4627 * mode but first we need to redefine compl_startpos */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4628 if (compl_cont_status & CONT_S_IPOS)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4629 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4630 compl_cont_status |= CONT_SOL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4631 compl_startpos.col = (colnr_T)(skipwhite(
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4632 line + compl_length
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4633 + compl_startpos.col) - line);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4634 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4635 compl_col = compl_startpos.col;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4636 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4637 compl_length = curwin->w_cursor.col - (int)compl_col;
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4638 /* IObuff is used to add a "word from the next line" would we
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4639 * have enough space? just being paranoic */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4640 #define MIN_SPACE 75
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4641 if (compl_length > (IOSIZE - MIN_SPACE))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4642 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4643 compl_cont_status &= ~CONT_SOL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4644 compl_length = (IOSIZE - MIN_SPACE);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4645 compl_col = curwin->w_cursor.col - compl_length;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4646 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4647 compl_cont_status |= CONT_ADDING | CONT_N_ADDS;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4648 if (compl_length < 1)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4649 compl_cont_status &= CONT_LOCAL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4650 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4651 else if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4652 compl_cont_status = CONT_ADDING | CONT_N_ADDS;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4653 else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4654 compl_cont_status = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4655 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4656 else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4657 compl_cont_status &= CONT_LOCAL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4658
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4659 if (!(compl_cont_status & CONT_ADDING)) /* normal expansion */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4660 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4661 compl_cont_mode = ctrl_x_mode;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4662 if (ctrl_x_mode != 0) /* Remove LOCAL if ctrl_x_mode != 0 */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4663 compl_cont_status = 0;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4664 compl_cont_status |= CONT_N_ADDS;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4665 compl_startpos = curwin->w_cursor;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4666 startcol = (int)curs_col;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4667 compl_col = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4668 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4669
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4670 /* Work out completion pattern and original text -- webb */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4671 if (ctrl_x_mode == 0 || (ctrl_x_mode & CTRL_X_WANT_IDENT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4672 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4673 if ((compl_cont_status & CONT_SOL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4674 || ctrl_x_mode == CTRL_X_PATH_DEFINES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4675 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4676 if (!(compl_cont_status & CONT_ADDING))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4677 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4678 while (--startcol >= 0 && vim_isIDc(line[startcol]))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4679 ;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4680 compl_col += ++startcol;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4681 compl_length = curs_col - startcol;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4682 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4683 if (p_ic)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4684 compl_pattern = str_foldcase(line + compl_col,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4685 compl_length, NULL, 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4686 else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4687 compl_pattern = vim_strnsave(line + compl_col,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4688 compl_length);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4689 if (compl_pattern == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4690 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4691 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4692 else if (compl_cont_status & CONT_ADDING)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4693 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4694 char_u *prefix = (char_u *)"\\<";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4695
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4696 /* we need 3 extra chars, 1 for the NUL and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4697 * 2 >= strlen(prefix) -- Acevedo */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4698 compl_pattern = alloc(quote_meta(NULL, line + compl_col,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4699 compl_length) + 3);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4700 if (compl_pattern == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4701 return FAIL;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4702 if (!vim_iswordp(line + compl_col)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4703 || (compl_col > 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4704 && (
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4705 #ifdef FEAT_MBYTE
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4706 vim_iswordp(mb_prevptr(line, line + compl_col))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4707 #else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4708 vim_iswordc(line[compl_col - 1])
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4709 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4710 )))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4711 prefix = (char_u *)"";
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4712 STRCPY((char *)compl_pattern, prefix);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4713 (void)quote_meta(compl_pattern + STRLEN(prefix),
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4714 line + compl_col, compl_length);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4715 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4716 else if (--startcol < 0 ||
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4717 #ifdef FEAT_MBYTE
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4718 !vim_iswordp(mb_prevptr(line, line + startcol + 1))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4719 #else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4720 !vim_iswordc(line[startcol])
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4721 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4722 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4723 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4724 /* Match any word of at least two chars */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4725 compl_pattern = vim_strsave((char_u *)"\\<\\k\\k");
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4726 if (compl_pattern == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4727 return FAIL;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4728 compl_col += curs_col;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4729 compl_length = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4730 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4731 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4732 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4733 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4734 /* Search the point of change class of multibyte character
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4735 * or not a word single byte character backward. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4736 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4737 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4738 int base_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4739 int head_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4740
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4741 startcol -= (*mb_head_off)(line, line + startcol);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4742 base_class = mb_get_class(line + startcol);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4743 while (--startcol >= 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4744 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4745 head_off = (*mb_head_off)(line, line + startcol);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4746 if (base_class != mb_get_class(line + startcol
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4747 - head_off))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4748 break;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4749 startcol -= head_off;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4750 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4751 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4752 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4753 #endif
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4754 while (--startcol >= 0 && vim_iswordc(line[startcol]))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4755 ;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4756 compl_col += ++startcol;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4757 compl_length = (int)curs_col - startcol;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4758 if (compl_length == 1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4759 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4760 /* Only match word with at least two chars -- webb
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4761 * there's no need to call quote_meta,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4762 * alloc(7) is enough -- Acevedo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4763 */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4764 compl_pattern = alloc(7);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4765 if (compl_pattern == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4766 return FAIL;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4767 STRCPY((char *)compl_pattern, "\\<");
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4768 (void)quote_meta(compl_pattern + 2, line + compl_col, 1);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4769 STRCAT((char *)compl_pattern, "\\k");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4770 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4771 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4772 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4773 compl_pattern = alloc(quote_meta(NULL, line + compl_col,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4774 compl_length) + 3);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4775 if (compl_pattern == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4776 return FAIL;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4777 STRCPY((char *)compl_pattern, "\\<");
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4778 (void)quote_meta(compl_pattern + 2, line + compl_col,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4779 compl_length);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4780 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4781 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4782 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4783 else if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4784 {
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 829
diff changeset
4785 compl_col = (colnr_T)(skipwhite(line) - line);
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4786 compl_length = (int)curs_col - (int)compl_col;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4787 if (compl_length < 0) /* cursor in indent: empty pattern */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4788 compl_length = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4789 if (p_ic)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4790 compl_pattern = str_foldcase(line + compl_col, compl_length,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4791 NULL, 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4792 else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4793 compl_pattern = vim_strnsave(line + compl_col, compl_length);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4794 if (compl_pattern == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4795 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4796 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4797 else if (ctrl_x_mode == CTRL_X_FILES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4798 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4799 while (--startcol >= 0 && vim_isfilec(line[startcol]))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4800 ;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4801 compl_col += ++startcol;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4802 compl_length = (int)curs_col - startcol;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4803 compl_pattern = addstar(line + compl_col, compl_length,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4804 EXPAND_FILES);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4805 if (compl_pattern == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4806 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4807 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4808 else if (ctrl_x_mode == CTRL_X_CMDLINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4809 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4810 compl_pattern = vim_strnsave(line, curs_col);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4811 if (compl_pattern == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4812 return FAIL;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4813 set_cmd_context(&compl_xp, compl_pattern,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4814 (int)STRLEN(compl_pattern), curs_col);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4815 if (compl_xp.xp_context == EXPAND_UNSUCCESSFUL
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4816 || compl_xp.xp_context == EXPAND_NOTHING)
935
c8cae82dee30 updated for version 7.0-061
vimboss
parents: 929
diff changeset
4817 /* No completion possible, use an empty pattern to get a
c8cae82dee30 updated for version 7.0-061
vimboss
parents: 929
diff changeset
4818 * "pattern not found" message. */
897
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
4819 compl_col = curs_col;
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
4820 else
935
c8cae82dee30 updated for version 7.0-061
vimboss
parents: 929
diff changeset
4821 compl_col = (int)(compl_xp.xp_pattern - compl_pattern);
c8cae82dee30 updated for version 7.0-061
vimboss
parents: 929
diff changeset
4822 compl_length = curs_col - compl_col;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4823 }
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
4824 else if (ctrl_x_mode == CTRL_X_FUNCTION || ctrl_x_mode == CTRL_X_OMNI)
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4825 {
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
4826 #ifdef FEAT_COMPL_FUNC
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
4827 /*
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4828 * Call user defined function 'completefunc' with "a:findstart"
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4829 * set to 1 to obtain the length of text to use for completion.
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
4830 */
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4831 char_u *args[2];
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
4832 int col;
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4833 char_u *funcname;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4834 pos_T pos;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4835
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
4836 /* Call 'completefunc' or 'omnifunc' and get pattern length as a
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4837 * string */
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4838 funcname = ctrl_x_mode == CTRL_X_FUNCTION
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4839 ? curbuf->b_p_cfu : curbuf->b_p_ofu;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4840 if (*funcname == NUL)
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
4841 {
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
4842 EMSG2(_(e_notset), ctrl_x_mode == CTRL_X_FUNCTION
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
4843 ? "completefunc" : "omnifunc");
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
4844 return FAIL;
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
4845 }
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
4846
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
4847 args[0] = (char_u *)"1";
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4848 args[1] = NULL;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4849 pos = curwin->w_cursor;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4850 col = call_func_retnr(funcname, 2, args, FALSE);
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4851 curwin->w_cursor = pos; /* restore the cursor position */
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4852
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
4853 if (col < 0)
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
4854 col = curs_col;
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
4855 compl_col = col;
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
4856 if ((colnr_T)compl_col > curs_col)
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
4857 compl_col = curs_col;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4858
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4859 /* Setup variables for completion. Need to obtain "line" again,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4860 * it may have become invalid. */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4861 line = ml_get(curwin->w_cursor.lnum);
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
4862 compl_length = curs_col - compl_col;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4863 compl_pattern = vim_strnsave(line + compl_col, compl_length);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4864 if (compl_pattern == NULL)
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4865 #endif
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4866 return FAIL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4867 }
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
4868 else if (ctrl_x_mode == CTRL_X_SPELL)
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
4869 {
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
4870 #ifdef FEAT_SPELL
497
73f10d8124f4 updated for version 7.0136
vimboss
parents: 484
diff changeset
4871 if (spell_bad_len > 0)
73f10d8124f4 updated for version 7.0136
vimboss
parents: 484
diff changeset
4872 compl_col = curs_col - spell_bad_len;
73f10d8124f4 updated for version 7.0136
vimboss
parents: 484
diff changeset
4873 else
73f10d8124f4 updated for version 7.0136
vimboss
parents: 484
diff changeset
4874 compl_col = spell_word_start(startcol);
73f10d8124f4 updated for version 7.0136
vimboss
parents: 484
diff changeset
4875 if (compl_col >= (colnr_T)startcol)
897
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
4876 {
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
4877 compl_length = 0;
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
4878 compl_col = curs_col;
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
4879 }
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
4880 else
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
4881 {
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
4882 spell_expand_check_cap(compl_col);
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
4883 compl_length = (int)curs_col - compl_col;
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
4884 }
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 816
diff changeset
4885 /* Need to obtain "line" again, it may have become invalid. */
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 816
diff changeset
4886 line = ml_get(curwin->w_cursor.lnum);
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
4887 compl_pattern = vim_strnsave(line + compl_col, compl_length);
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
4888 if (compl_pattern == NULL)
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
4889 #endif
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
4890 return FAIL;
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
4891 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4892 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4893 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4894 EMSG2(_(e_intern2), "ins_complete()");
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4895 return FAIL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4896 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4897
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4898 if (compl_cont_status & CONT_ADDING)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4899 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4900 edit_submode_pre = (char_u *)_(" Adding");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4901 if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4902 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4903 /* Insert a new line, keep indentation but ignore 'comments' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4904 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4905 char_u *old = curbuf->b_p_com;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4906
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4907 curbuf->b_p_com = (char_u *)"";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4908 #endif
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4909 compl_startpos.lnum = curwin->w_cursor.lnum;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4910 compl_startpos.col = compl_col;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4911 ins_eol('\r');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4912 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4913 curbuf->b_p_com = old;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4914 #endif
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4915 compl_length = 0;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4916 compl_col = curwin->w_cursor.col;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4917 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4918 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4919 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4920 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4921 edit_submode_pre = NULL;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4922 compl_startpos.col = compl_col;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4923 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4924
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4925 if (compl_cont_status & CONT_LOCAL)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4926 edit_submode = (char_u *)_(ctrl_x_msgs[CTRL_X_LOCAL_MSG]);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4927 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4928 edit_submode = (char_u *)_(CTRL_X_MSG(ctrl_x_mode));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4929
694
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
4930 /* Always add completion for the original text. */
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
4931 vim_free(compl_orig_text);
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4932 compl_orig_text = vim_strnsave(line + compl_col, compl_length);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4933 if (compl_orig_text == NULL || ins_compl_add(compl_orig_text,
942
29bf49bad20d updated for version 7.0-068
vimboss
parents: 941
diff changeset
4934 -1, p_ic, NULL, NULL, 0, ORIGINAL_TEXT, FALSE) != OK)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4935 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4936 vim_free(compl_pattern);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4937 compl_pattern = NULL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4938 vim_free(compl_orig_text);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4939 compl_orig_text = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4940 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4941 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4942
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4943 /* showmode might reset the internal line pointers, so it must
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4944 * be called before line = ml_get(), or when this address is no
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4945 * longer needed. -- Acevedo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4946 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4947 edit_submode_extra = (char_u *)_("-- Searching...");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4948 edit_submode_highl = HLF_COUNT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4949 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4950 edit_submode_extra = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4951 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4952 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4953
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4954 compl_shown_match = compl_curr_match;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4955 compl_shows_dir = compl_direction;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4956
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4957 /*
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4958 * Find next match (and following matches).
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4959 */
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4960 n = ins_compl_next(TRUE, ins_compl_key2count(c), ins_compl_use_match(c));
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4961
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4962 /* may undisplay the popup menu */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4963 ins_compl_upd_pum();
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4964
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4965 if (n > 1) /* all matches have been found */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4966 compl_matches = n;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4967 compl_curr_match = compl_shown_match;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4968 compl_direction = compl_shows_dir;
857
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
4969
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
4970 /* Eat the ESC that vgetc() returns after a CTRL-C to avoid leaving Insert
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
4971 * mode. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4972 if (got_int && !global_busy)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4973 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4974 (void)vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4975 got_int = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4976 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4977
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4978 /* we found no match if the list has only the "compl_orig_text"-entry */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4979 if (compl_first_match == compl_first_match->cp_next)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4980 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4981 edit_submode_extra = (compl_cont_status & CONT_ADDING)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4982 && compl_length > 1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4983 ? (char_u *)_(e_hitend) : (char_u *)_(e_patnotf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4984 edit_submode_highl = HLF_E;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4985 /* remove N_ADDS flag, so next ^X<> won't try to go to ADDING mode,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4986 * because we couldn't expand anything at first place, but if we used
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4987 * ^P, ^N, ^X^I or ^X^D we might want to add-expand a single-char-word
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4988 * (such as M in M'exico) if not tried already. -- Acevedo */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4989 if ( compl_length > 1
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4990 || (compl_cont_status & CONT_ADDING)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4991 || (ctrl_x_mode != 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4992 && ctrl_x_mode != CTRL_X_PATH_PATTERNS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4993 && ctrl_x_mode != CTRL_X_PATH_DEFINES))
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4994 compl_cont_status &= ~CONT_N_ADDS;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4995 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4996
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4997 if (compl_curr_match->cp_flags & CONT_S_IPOS)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4998 compl_cont_status |= CONT_S_IPOS;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4999 else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5000 compl_cont_status &= ~CONT_S_IPOS;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5001
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5002 if (edit_submode_extra == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5003 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5004 if (compl_curr_match->cp_flags & ORIGINAL_TEXT)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5005 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5006 edit_submode_extra = (char_u *)_("Back at original");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5007 edit_submode_highl = HLF_W;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5008 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5009 else if (compl_cont_status & CONT_S_IPOS)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5010 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5011 edit_submode_extra = (char_u *)_("Word from other line");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5012 edit_submode_highl = HLF_COUNT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5013 }
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5014 else if (compl_curr_match->cp_next == compl_curr_match->cp_prev)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5015 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5016 edit_submode_extra = (char_u *)_("The only match");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5017 edit_submode_highl = HLF_COUNT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5018 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5019 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5020 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5021 /* Update completion sequence number when needed. */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5022 if (compl_curr_match->cp_number == -1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5023 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5024 int number = 0;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5025 compl_T *match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5026
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5027 if (compl_direction == FORWARD)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5028 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5029 /* search backwards for the first valid (!= -1) number.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5030 * This should normally succeed already at the first loop
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5031 * cycle, so it's fast! */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5032 for (match = compl_curr_match->cp_prev; match != NULL
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5033 && match != compl_first_match;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5034 match = match->cp_prev)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5035 if (match->cp_number != -1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5036 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5037 number = match->cp_number;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5038 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5039 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5040 if (match != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5041 /* go up and assign all numbers which are not assigned
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5042 * yet */
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
5043 for (match = match->cp_next;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
5044 match != NULL && match->cp_number == -1;
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5045 match = match->cp_next)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5046 match->cp_number = ++number;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5047 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5048 else /* BACKWARD */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5049 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5050 /* search forwards (upwards) for the first valid (!= -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5051 * number. This should normally succeed already at the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5052 * first loop cycle, so it's fast! */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5053 for (match = compl_curr_match->cp_next; match != NULL
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5054 && match != compl_first_match;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5055 match = match->cp_next)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5056 if (match->cp_number != -1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5057 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5058 number = match->cp_number;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5059 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5060 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5061 if (match != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5062 /* go down and assign all numbers which are not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5063 * assigned yet */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5064 for (match = match->cp_prev; match
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5065 && match->cp_number == -1;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5066 match = match->cp_prev)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5067 match->cp_number = ++number;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5068 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5069 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5070
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
5071 /* The match should always have a sequence number now, this is
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
5072 * just a safety check. */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5073 if (compl_curr_match->cp_number != -1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5074 {
1063
d763e7d7e938 updated for version 7.0-189
vimboss
parents: 1032
diff changeset
5075 /* Space for 10 text chars. + 2x10-digit no.s = 31.
d763e7d7e938 updated for version 7.0-189
vimboss
parents: 1032
diff changeset
5076 * Translations may need more than twice that. */
d763e7d7e938 updated for version 7.0-189
vimboss
parents: 1032
diff changeset
5077 static char_u match_ref[81];
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5078
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5079 if (compl_matches > 0)
1063
d763e7d7e938 updated for version 7.0-189
vimboss
parents: 1032
diff changeset
5080 vim_snprintf((char *)match_ref, sizeof(match_ref),
d763e7d7e938 updated for version 7.0-189
vimboss
parents: 1032
diff changeset
5081 _("match %d of %d"),
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5082 compl_curr_match->cp_number, compl_matches);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5083 else
1063
d763e7d7e938 updated for version 7.0-189
vimboss
parents: 1032
diff changeset
5084 vim_snprintf((char *)match_ref, sizeof(match_ref),
d763e7d7e938 updated for version 7.0-189
vimboss
parents: 1032
diff changeset
5085 _("match %d"),
d763e7d7e938 updated for version 7.0-189
vimboss
parents: 1032
diff changeset
5086 compl_curr_match->cp_number);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5087 edit_submode_extra = match_ref;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5088 edit_submode_highl = HLF_R;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5089 if (dollar_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5090 curs_columns(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5091 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5092 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5093 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5094
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5095 /* Show a message about what (completion) mode we're in. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5096 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5097 if (edit_submode_extra != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5098 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5099 if (!p_smd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5100 msg_attr(edit_submode_extra,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5101 edit_submode_highl < HLF_COUNT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5102 ? hl_attr(edit_submode_highl) : 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5103 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5104 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5105 msg_clr_cmdline(); /* necessary for "noshowmode" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5106
857
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
5107 /* Show the popup menu, unless we got interrupted. */
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
5108 if (!compl_interrupted)
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
5109 {
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
5110 /* RedrawingDisabled may be set when invoked through complete(). */
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
5111 n = RedrawingDisabled;
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
5112 RedrawingDisabled = 0;
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
5113 ins_compl_show_pum();
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
5114 setcursor();
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
5115 RedrawingDisabled = n;
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
5116 }
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
5117 compl_was_interrupted = compl_interrupted;
857
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
5118 compl_interrupted = FALSE;
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
5119
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5120 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5121 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5122
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5123 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5124 * Looks in the first "len" chars. of "src" for search-metachars.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5125 * If dest is not NULL the chars. are copied there quoting (with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5126 * a backslash) the metachars, and dest would be NUL terminated.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5127 * Returns the length (needed) of dest
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5128 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5129 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5130 quote_meta(dest, src, len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5131 char_u *dest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5132 char_u *src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5133 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5134 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5135 int m;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5136
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5137 for (m = len; --len >= 0; src++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5138 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5139 switch (*src)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5140 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5141 case '.':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5142 case '*':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5143 case '[':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5144 if (ctrl_x_mode == CTRL_X_DICTIONARY
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5145 || ctrl_x_mode == CTRL_X_THESAURUS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5146 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5147 case '~':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5148 if (!p_magic) /* quote these only if magic is set */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5149 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5150 case '\\':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5151 if (ctrl_x_mode == CTRL_X_DICTIONARY
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5152 || ctrl_x_mode == CTRL_X_THESAURUS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5153 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5154 case '^': /* currently it's not needed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5155 case '$':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5156 m++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5157 if (dest != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5158 *dest++ = '\\';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5159 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5160 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5161 if (dest != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5162 *dest++ = *src;
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5163 # ifdef FEAT_MBYTE
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5164 /* Copy remaining bytes of a multibyte character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5165 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5166 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5167 int i, mb_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5168
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 470
diff changeset
5169 mb_len = (*mb_ptr2len)(src) - 1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5170 if (mb_len > 0 && len >= mb_len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5171 for (i = 0; i < mb_len; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5172 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5173 --len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5174 ++src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5175 if (dest != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5176 *dest++ = *src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5177 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5178 }
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5179 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5180 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5181 if (dest != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5182 *dest = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5183
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5184 return m;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5185 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5186 #endif /* FEAT_INS_EXPAND */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5187
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5188 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5189 * Next character is interpreted literally.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5190 * A one, two or three digit decimal number is interpreted as its byte value.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5191 * If one or two digits are entered, the next character is given to vungetc().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5192 * For Unicode a character > 255 may be returned.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5193 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5194 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5195 get_literal()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5196 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5197 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5198 int nc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5199 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5200 int hex = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5201 int octal = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5202 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5203 int unicode = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5204 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5205
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5206 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5207 return Ctrl_C;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5208
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5209 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5210 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5211 * In GUI there is no point inserting the internal code for a special key.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5212 * It is more useful to insert the string "<KEY>" instead. This would
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5213 * probably be useful in a text window too, but it would not be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5214 * vi-compatible (maybe there should be an option for it?) -- webb
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5215 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5216 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5217 ++allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5218 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5219 #ifdef USE_ON_FLY_SCROLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5220 dont_scroll = TRUE; /* disallow scrolling here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5221 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5222 ++no_mapping; /* don't map the next key hits */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5223 cc = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5224 i = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5225 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5226 {
1389
bdcfe793d49f updated for version 7.1-104
vimboss
parents: 1353
diff changeset
5227 nc = plain_vgetc();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5228 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5229 if (!(State & CMDLINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5230 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5231 && MB_BYTE2LEN_CHECK(nc) == 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5232 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5233 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5234 add_to_showcmd(nc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5235 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5236 if (nc == 'x' || nc == 'X')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5237 hex = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5238 else if (nc == 'o' || nc == 'O')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5239 octal = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5240 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5241 else if (nc == 'u' || nc == 'U')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5242 unicode = nc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5243 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5244 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5245 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5246 if (hex
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5247 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5248 || unicode != 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5249 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5250 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5251 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5252 if (!vim_isxdigit(nc))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5253 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5254 cc = cc * 16 + hex2nr(nc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5255 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5256 else if (octal)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5257 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5258 if (nc < '0' || nc > '7')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5259 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5260 cc = cc * 8 + nc - '0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5261 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5262 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5263 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5264 if (!VIM_ISDIGIT(nc))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5265 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5266 cc = cc * 10 + nc - '0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5267 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5268
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5269 ++i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5270 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5271
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5272 if (cc > 255
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5273 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5274 && unicode == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5275 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5276 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5277 cc = 255; /* limit range to 0-255 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5278 nc = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5279
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5280 if (hex) /* hex: up to two chars */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5281 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5282 if (i >= 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5283 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5284 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5285 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5286 else if (unicode) /* Unicode: up to four or eight chars */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5287 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5288 if ((unicode == 'u' && i >= 4) || (unicode == 'U' && i >= 8))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5289 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5290 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5291 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5292 else if (i >= 3) /* decimal or octal: up to three chars */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5293 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5294 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5295 if (i == 0) /* no number entered */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5296 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5297 if (nc == K_ZERO) /* NUL is stored as NL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5298 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5299 cc = '\n';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5300 nc = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5301 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5302 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5303 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5304 cc = nc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5305 nc = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5306 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5307 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5308
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5309 if (cc == 0) /* NUL is stored as NL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5310 cc = '\n';
221
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
5311 #ifdef FEAT_MBYTE
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
5312 if (enc_dbcs && (cc & 0xff) == 0)
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
5313 cc = '?'; /* don't accept an illegal DBCS char, the NUL in the
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
5314 second byte will cause trouble! */
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
5315 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5316
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5317 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5318 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5319 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5320 --allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5321 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5322 if (nc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5323 vungetc(nc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5324 got_int = FALSE; /* CTRL-C typed after CTRL-V is not an interrupt */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5325 return cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5326 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5327
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5328 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5329 * Insert character, taking care of special keys and mod_mask
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5330 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5331 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5332 insert_special(c, allow_modmask, ctrlv)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5333 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5334 int allow_modmask;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5335 int ctrlv; /* c was typed after CTRL-V */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5336 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5337 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5338 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5339
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5340 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5341 * Special function key, translate into "<Key>". Up to the last '>' is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5342 * inserted with ins_str(), so as not to replace characters in replace
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5343 * mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5344 * Only use mod_mask for special keys, to avoid things like <S-Space>,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5345 * unless 'allow_modmask' is TRUE.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5346 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5347 #ifdef MACOS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5348 /* Command-key never produces a normal key */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5349 if (mod_mask & MOD_MASK_CMD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5350 allow_modmask = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5351 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5352 if (IS_SPECIAL(c) || (mod_mask && allow_modmask))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5353 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5354 p = get_special_key_name(c, mod_mask);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5355 len = (int)STRLEN(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5356 c = p[len - 1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5357 if (len > 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5358 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5359 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5360 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5361 p[len - 1] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5362 ins_str(p);
620
9e359e5759f6 updated for version 7.0177
vimboss
parents: 615
diff changeset
5363 AppendToRedobuffLit(p, -1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5364 ctrlv = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5365 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5366 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5367 if (stop_arrow() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5368 insertchar(c, ctrlv ? INSCHAR_CTRLV : 0, -1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5369 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5370
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5371 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5372 * Special characters in this context are those that need processing other
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5373 * than the simple insertion that can be performed here. This includes ESC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5374 * which terminates the insert, and CR/NL which need special processing to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5375 * open up a new line. This routine tries to optimize insertions performed by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5376 * the "redo", "undo" or "put" commands, so it needs to know when it should
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5377 * stop and defer processing to the "normal" mechanism.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5378 * '0' and '^' are special, because they can be followed by CTRL-D.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5379 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5380 #ifdef EBCDIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5381 # define ISSPECIAL(c) ((c) < ' ' || (c) == '0' || (c) == '^')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5382 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5383 # define ISSPECIAL(c) ((c) < ' ' || (c) >= DEL || (c) == '0' || (c) == '^')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5384 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5385
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5386 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5387 # define WHITECHAR(cc) (vim_iswhite(cc) && (!enc_utf8 || !utf_iscomposing(utf_ptr2char(ml_get_cursor() + 1))))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5388 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5389 # define WHITECHAR(cc) vim_iswhite(cc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5390 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5391
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5392 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5393 insertchar(c, flags, second_indent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5394 int c; /* character to insert or NUL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5395 int flags; /* INSCHAR_FORMAT, etc. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5396 int second_indent; /* indent for second line if >= 0 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5397 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5398 int textwidth;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5399 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5400 char_u *p;
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5401 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5402 int fo_ins_blank;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5403
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5404 textwidth = comp_textwidth(flags & INSCHAR_FORMAT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5405 fo_ins_blank = has_format_option(FO_INS_BLANK);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5406
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5407 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5408 * Try to break the line in two or more pieces when:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5409 * - Always do this if we have been called to do formatting only.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5410 * - Always do this when 'formatoptions' has the 'a' flag and the line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5411 * ends in white space.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5412 * - Otherwise:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5413 * - Don't do this if inserting a blank
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5414 * - Don't do this if an existing character is being replaced, unless
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5415 * we're in VREPLACE mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5416 * - Do this if the cursor is not on the line where insert started
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5417 * or - 'formatoptions' doesn't have 'l' or the line was not too long
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5418 * before the insert.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5419 * - 'formatoptions' doesn't have 'b' or a blank was inserted at or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5420 * before 'textwidth'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5421 */
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5422 if (textwidth > 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5423 && ((flags & INSCHAR_FORMAT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5424 || (!vim_iswhite(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5425 && !((State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5426 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5427 && !(State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5428 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5429 && *ml_get_cursor() != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5430 && (curwin->w_cursor.lnum != Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5431 || ((!has_format_option(FO_INS_LONG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5432 || Insstart_textlen <= (colnr_T)textwidth)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5433 && (!fo_ins_blank
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5434 || Insstart_blank_vcol <= (colnr_T)textwidth
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5435 ))))))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5436 {
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5437 /* Format with 'formatexpr' when it's set. Use internal formatting
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5438 * when 'formatexpr' isn't set or it returns non-zero. */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5439 #if defined(FEAT_EVAL)
1000
cb49fa8c7196 updated for version 7.0-126
vimboss
parents: 993
diff changeset
5440 int do_internal = TRUE;
cb49fa8c7196 updated for version 7.0-126
vimboss
parents: 993
diff changeset
5441
cb49fa8c7196 updated for version 7.0-126
vimboss
parents: 993
diff changeset
5442 if (*curbuf->b_p_fex != NUL)
cb49fa8c7196 updated for version 7.0-126
vimboss
parents: 993
diff changeset
5443 {
cb49fa8c7196 updated for version 7.0-126
vimboss
parents: 993
diff changeset
5444 do_internal = (fex_format(curwin->w_cursor.lnum, 1L, c) != 0);
cb49fa8c7196 updated for version 7.0-126
vimboss
parents: 993
diff changeset
5445 /* It may be required to save for undo again, e.g. when setline()
cb49fa8c7196 updated for version 7.0-126
vimboss
parents: 993
diff changeset
5446 * was called. */
cb49fa8c7196 updated for version 7.0-126
vimboss
parents: 993
diff changeset
5447 ins_need_undo = TRUE;
cb49fa8c7196 updated for version 7.0-126
vimboss
parents: 993
diff changeset
5448 }
cb49fa8c7196 updated for version 7.0-126
vimboss
parents: 993
diff changeset
5449 if (do_internal)
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5450 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5451 internal_format(textwidth, second_indent, flags, c == NUL);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5452 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5453
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5454 if (c == NUL) /* only formatting was wanted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5455 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5456
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5457 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5458 /* Check whether this character should end a comment. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5459 if (did_ai && (int)c == end_comment_pending)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5460 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5461 char_u *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5462 char_u lead_end[COM_MAX_LEN]; /* end-comment string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5463 int middle_len, end_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5464 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5465
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5466 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5467 * Need to remove existing (middle) comment leader and insert end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5468 * comment leader. First, check what comment leader we can find.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5469 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5470 i = get_leader_len(line = ml_get_curline(), &p, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5471 if (i > 0 && vim_strchr(p, COM_MIDDLE) != NULL) /* Just checking */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5472 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5473 /* Skip middle-comment string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5474 while (*p && p[-1] != ':') /* find end of middle flags */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5475 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5476 middle_len = copy_option_part(&p, lead_end, COM_MAX_LEN, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5477 /* Don't count trailing white space for middle_len */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5478 while (middle_len > 0 && vim_iswhite(lead_end[middle_len - 1]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5479 --middle_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5480
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5481 /* Find the end-comment string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5482 while (*p && p[-1] != ':') /* find end of end flags */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5483 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5484 end_len = copy_option_part(&p, lead_end, COM_MAX_LEN, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5485
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5486 /* Skip white space before the cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5487 i = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5488 while (--i >= 0 && vim_iswhite(line[i]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5489 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5490 i++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5491
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5492 /* Skip to before the middle leader */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5493 i -= middle_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5494
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5495 /* Check some expected things before we go on */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5496 if (i >= 0 && lead_end[end_len - 1] == end_comment_pending)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5497 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5498 /* Backspace over all the stuff we want to replace */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5499 backspace_until_column(i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5500
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5501 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5502 * Insert the end-comment string, except for the last
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5503 * character, which will get inserted as normal later.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5504 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5505 ins_bytes_len(lead_end, end_len - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5506 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5507 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5508 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5509 end_comment_pending = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5510 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5511
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5512 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5513 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5514 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5515 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5516 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5517 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5518
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5519 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5520 * If there's any pending input, grab up to INPUT_BUFLEN at once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5521 * This speeds up normal text input considerably.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5522 * Don't do this when 'cindent' or 'indentexpr' is set, because we might
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5523 * need to re-indent at a ':', or any other character (but not what
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5524 * 'paste' is set)..
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5525 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5526 #ifdef USE_ON_FLY_SCROLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5527 dont_scroll = FALSE; /* allow scrolling here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5528 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5529
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5530 if ( !ISSPECIAL(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5531 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5532 && (!has_mbyte || (*mb_char2len)(c) == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5533 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5534 && vpeekc() != NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5535 && !(State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5536 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5537 && !cindent_on()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5538 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5539 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5540 && !p_ri
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5541 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5542 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5543 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5544 #define INPUT_BUFLEN 100
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5545 char_u buf[INPUT_BUFLEN + 1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5546 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5547 colnr_T virtcol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5548
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5549 buf[0] = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5550 i = 1;
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5551 if (textwidth > 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5552 virtcol = get_nolist_virtcol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5553 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5554 * Stop the string when:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5555 * - no more chars available
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5556 * - finding a special character (command key)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5557 * - buffer is full
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5558 * - running into the 'textwidth' boundary
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5559 * - need to check for abbreviation: A non-word char after a word-char
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5560 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5561 while ( (c = vpeekc()) != NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5562 && !ISSPECIAL(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5563 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5564 && (!has_mbyte || MB_BYTE2LEN_CHECK(c) == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5565 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5566 && i < INPUT_BUFLEN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5567 && (textwidth == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5568 || (virtcol += byte2cells(buf[i - 1])) < (colnr_T)textwidth)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5569 && !(!no_abbr && !vim_iswordc(c) && vim_iswordc(buf[i - 1])))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5570 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5571 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5572 c = vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5573 if (p_hkmap && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5574 c = hkmap(c); /* Hebrew mode mapping */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5575 # ifdef FEAT_FKMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5576 if (p_fkmap && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5577 c = fkmap(c); /* Farsi mode mapping */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5578 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5579 buf[i++] = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5580 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5581 buf[i++] = vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5582 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5583 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5584
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5585 #ifdef FEAT_DIGRAPHS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5586 do_digraph(-1); /* clear digraphs */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5587 do_digraph(buf[i-1]); /* may be the start of a digraph */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5588 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5589 buf[i] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5590 ins_str(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5591 if (flags & INSCHAR_CTRLV)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5592 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5593 redo_literal(*buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5594 i = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5595 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5596 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5597 i = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5598 if (buf[i] != NUL)
620
9e359e5759f6 updated for version 7.0177
vimboss
parents: 615
diff changeset
5599 AppendToRedobuffLit(buf + i, -1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5600 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5601 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5602 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5603 #ifdef FEAT_MBYTE
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5604 int cc;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5605
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5606 if (has_mbyte && (cc = (*mb_char2len)(c)) > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5607 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5608 char_u buf[MB_MAXBYTES + 1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5609
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5610 (*mb_char2bytes)(c, buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5611 buf[cc] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5612 ins_char_bytes(buf, cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5613 AppendCharToRedobuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5614 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5615 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5616 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5617 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5618 ins_char(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5619 if (flags & INSCHAR_CTRLV)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5620 redo_literal(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5621 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5622 AppendCharToRedobuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5623 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5624 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5625 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5626
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5627 /*
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5628 * Format text at the current insert position.
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5629 */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5630 static void
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5631 internal_format(textwidth, second_indent, flags, format_only)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5632 int textwidth;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5633 int second_indent;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5634 int flags;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5635 int format_only;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5636 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5637 int cc;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5638 int save_char = NUL;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5639 int haveto_redraw = FALSE;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5640 int fo_ins_blank = has_format_option(FO_INS_BLANK);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5641 #ifdef FEAT_MBYTE
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5642 int fo_multibyte = has_format_option(FO_MBYTE_BREAK);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5643 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5644 int fo_white_par = has_format_option(FO_WHITE_PAR);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5645 int first_line = TRUE;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5646 #ifdef FEAT_COMMENTS
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5647 colnr_T leader_len;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5648 int no_leader = FALSE;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5649 int do_comments = (flags & INSCHAR_DO_COM);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5650 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5651
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5652 /*
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5653 * When 'ai' is off we don't want a space under the cursor to be
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5654 * deleted. Replace it with an 'x' temporarily.
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5655 */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5656 if (!curbuf->b_p_ai)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5657 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5658 cc = gchar_cursor();
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5659 if (vim_iswhite(cc))
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5660 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5661 save_char = cc;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5662 pchar_cursor('x');
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5663 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5664 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5665
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5666 /*
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5667 * Repeat breaking lines, until the current line is not too long.
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5668 */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5669 while (!got_int)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5670 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5671 int startcol; /* Cursor column at entry */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5672 int wantcol; /* column at textwidth border */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5673 int foundcol; /* column for start of spaces */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5674 int end_foundcol = 0; /* column for start of word */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5675 colnr_T len;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5676 colnr_T virtcol;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5677 #ifdef FEAT_VREPLACE
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5678 int orig_col = 0;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5679 char_u *saved_text = NULL;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5680 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5681 colnr_T col;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5682
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5683 virtcol = get_nolist_virtcol();
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5684 if (virtcol < (colnr_T)textwidth)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5685 break;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5686
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5687 #ifdef FEAT_COMMENTS
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5688 if (no_leader)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5689 do_comments = FALSE;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5690 else if (!(flags & INSCHAR_FORMAT)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5691 && has_format_option(FO_WRAP_COMS))
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5692 do_comments = TRUE;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5693
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5694 /* Don't break until after the comment leader */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5695 if (do_comments)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5696 leader_len = get_leader_len(ml_get_curline(), NULL, FALSE);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5697 else
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5698 leader_len = 0;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5699
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5700 /* If the line doesn't start with a comment leader, then don't
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5701 * start one in a following broken line. Avoids that a %word
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5702 * moved to the start of the next line causes all following lines
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5703 * to start with %. */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5704 if (leader_len == 0)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5705 no_leader = TRUE;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5706 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5707 if (!(flags & INSCHAR_FORMAT)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5708 #ifdef FEAT_COMMENTS
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5709 && leader_len == 0
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5710 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5711 && !has_format_option(FO_WRAP))
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5712
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5713 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5714 textwidth = 0;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5715 break;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5716 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5717 if ((startcol = curwin->w_cursor.col) == 0)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5718 break;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5719
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5720 /* find column of textwidth border */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5721 coladvance((colnr_T)textwidth);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5722 wantcol = curwin->w_cursor.col;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5723
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5724 curwin->w_cursor.col = startcol - 1;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5725 #ifdef FEAT_MBYTE
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5726 /* Correct cursor for multi-byte character. */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5727 if (has_mbyte)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5728 mb_adjust_cursor();
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5729 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5730 foundcol = 0;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5731
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5732 /*
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5733 * Find position to break at.
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5734 * Stop at first entered white when 'formatoptions' has 'v'
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5735 */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5736 while ((!fo_ins_blank && !has_format_option(FO_INS_VI))
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5737 || curwin->w_cursor.lnum != Insstart.lnum
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5738 || curwin->w_cursor.col >= Insstart.col)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5739 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5740 cc = gchar_cursor();
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5741 if (WHITECHAR(cc))
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5742 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5743 /* remember position of blank just before text */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5744 end_foundcol = curwin->w_cursor.col;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5745
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5746 /* find start of sequence of blanks */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5747 while (curwin->w_cursor.col > 0 && WHITECHAR(cc))
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5748 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5749 dec_cursor();
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5750 cc = gchar_cursor();
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5751 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5752 if (curwin->w_cursor.col == 0 && WHITECHAR(cc))
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5753 break; /* only spaces in front of text */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5754 #ifdef FEAT_COMMENTS
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5755 /* Don't break until after the comment leader */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5756 if (curwin->w_cursor.col < leader_len)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5757 break;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5758 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5759 if (has_format_option(FO_ONE_LETTER))
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5760 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5761 /* do not break after one-letter words */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5762 if (curwin->w_cursor.col == 0)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5763 break; /* one-letter word at begin */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5764
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5765 col = curwin->w_cursor.col;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5766 dec_cursor();
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5767 cc = gchar_cursor();
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5768
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5769 if (WHITECHAR(cc))
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5770 continue; /* one-letter, continue */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5771 curwin->w_cursor.col = col;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5772 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5773 #ifdef FEAT_MBYTE
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5774 if (has_mbyte)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5775 foundcol = curwin->w_cursor.col
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5776 + (*mb_ptr2len)(ml_get_cursor());
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5777 else
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5778 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5779 foundcol = curwin->w_cursor.col + 1;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5780 if (curwin->w_cursor.col < (colnr_T)wantcol)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5781 break;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5782 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5783 #ifdef FEAT_MBYTE
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5784 else if (cc >= 0x100 && fo_multibyte
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5785 && curwin->w_cursor.col <= (colnr_T)wantcol)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5786 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5787 /* Break after or before a multi-byte character. */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5788 foundcol = curwin->w_cursor.col;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5789 if (curwin->w_cursor.col < (colnr_T)wantcol)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5790 foundcol += (*mb_char2len)(cc);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5791 end_foundcol = foundcol;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5792 break;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5793 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5794 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5795 if (curwin->w_cursor.col == 0)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5796 break;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5797 dec_cursor();
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5798 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5799
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5800 if (foundcol == 0) /* no spaces, cannot break line */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5801 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5802 curwin->w_cursor.col = startcol;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5803 break;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5804 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5805
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5806 /* Going to break the line, remove any "$" now. */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5807 undisplay_dollar();
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5808
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5809 /*
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5810 * Offset between cursor position and line break is used by replace
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5811 * stack functions. VREPLACE does not use this, and backspaces
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5812 * over the text instead.
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5813 */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5814 #ifdef FEAT_VREPLACE
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5815 if (State & VREPLACE_FLAG)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5816 orig_col = startcol; /* Will start backspacing from here */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5817 else
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5818 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5819 replace_offset = startcol - end_foundcol - 1;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5820
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5821 /*
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5822 * adjust startcol for spaces that will be deleted and
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5823 * characters that will remain on top line
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5824 */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5825 curwin->w_cursor.col = foundcol;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5826 while (cc = gchar_cursor(), WHITECHAR(cc))
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5827 inc_cursor();
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5828 startcol -= curwin->w_cursor.col;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5829 if (startcol < 0)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5830 startcol = 0;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5831
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5832 #ifdef FEAT_VREPLACE
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5833 if (State & VREPLACE_FLAG)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5834 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5835 /*
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5836 * In VREPLACE mode, we will backspace over the text to be
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5837 * wrapped, so save a copy now to put on the next line.
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5838 */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5839 saved_text = vim_strsave(ml_get_cursor());
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5840 curwin->w_cursor.col = orig_col;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5841 if (saved_text == NULL)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5842 break; /* Can't do it, out of memory */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5843 saved_text[startcol] = NUL;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5844
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5845 /* Backspace over characters that will move to the next line */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5846 if (!fo_white_par)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5847 backspace_until_column(foundcol);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5848 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5849 else
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5850 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5851 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5852 /* put cursor after pos. to break line */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5853 if (!fo_white_par)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5854 curwin->w_cursor.col = foundcol;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5855 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5856
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5857 /*
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5858 * Split the line just before the margin.
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5859 * Only insert/delete lines, but don't really redraw the window.
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5860 */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5861 open_line(FORWARD, OPENLINE_DELSPACES + OPENLINE_MARKFIX
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5862 + (fo_white_par ? OPENLINE_KEEPTRAIL : 0)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5863 #ifdef FEAT_COMMENTS
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5864 + (do_comments ? OPENLINE_DO_COM : 0)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5865 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5866 , old_indent);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5867 old_indent = 0;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5868
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5869 replace_offset = 0;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5870 if (first_line)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5871 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5872 if (second_indent < 0 && has_format_option(FO_Q_NUMBER))
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5873 second_indent = get_number_indent(curwin->w_cursor.lnum -1);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5874 if (second_indent >= 0)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5875 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5876 #ifdef FEAT_VREPLACE
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5877 if (State & VREPLACE_FLAG)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5878 change_indent(INDENT_SET, second_indent, FALSE, NUL);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5879 else
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5880 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5881 (void)set_indent(second_indent, SIN_CHANGED);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5882 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5883 first_line = FALSE;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5884 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5885
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5886 #ifdef FEAT_VREPLACE
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5887 if (State & VREPLACE_FLAG)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5888 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5889 /*
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5890 * In VREPLACE mode we have backspaced over the text to be
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5891 * moved, now we re-insert it into the new line.
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5892 */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5893 ins_bytes(saved_text);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5894 vim_free(saved_text);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5895 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5896 else
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5897 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5898 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5899 /*
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5900 * Check if cursor is not past the NUL off the line, cindent
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5901 * may have added or removed indent.
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5902 */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5903 curwin->w_cursor.col += startcol;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5904 len = (colnr_T)STRLEN(ml_get_curline());
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5905 if (curwin->w_cursor.col > len)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5906 curwin->w_cursor.col = len;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5907 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5908
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5909 haveto_redraw = TRUE;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5910 #ifdef FEAT_CINDENT
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5911 can_cindent = TRUE;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5912 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5913 /* moved the cursor, don't autoindent or cindent now */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5914 did_ai = FALSE;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5915 #ifdef FEAT_SMARTINDENT
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5916 did_si = FALSE;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5917 can_si = FALSE;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5918 can_si_back = FALSE;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5919 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5920 line_breakcheck();
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5921 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5922
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5923 if (save_char != NUL) /* put back space after cursor */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5924 pchar_cursor(save_char);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5925
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5926 if (!format_only && haveto_redraw)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5927 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5928 update_topline();
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5929 redraw_curbuf_later(VALID);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5930 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5931 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5932
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5933 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5934 * Called after inserting or deleting text: When 'formatoptions' includes the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5935 * 'a' flag format from the current line until the end of the paragraph.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5936 * Keep the cursor at the same position relative to the text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5937 * The caller must have saved the cursor line for undo, following ones will be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5938 * saved here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5939 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5940 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5941 auto_format(trailblank, prev_line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5942 int trailblank; /* when TRUE also format with trailing blank */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5943 int prev_line; /* may start in previous line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5944 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5945 pos_T pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5946 colnr_T len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5947 char_u *old;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5948 char_u *new, *pnew;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5949 int wasatend;
301
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
5950 int cc;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5951
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5952 if (!has_format_option(FO_AUTO))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5953 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5954
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5955 pos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5956 old = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5957
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5958 /* may remove added space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5959 check_auto_format(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5960
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5961 /* Don't format in Insert mode when the cursor is on a trailing blank, the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5962 * user might insert normal text next. Also skip formatting when "1" is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5963 * in 'formatoptions' and there is a single character before the cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5964 * Otherwise the line would be broken and when typing another non-white
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5965 * next they are not joined back together. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5966 wasatend = (pos.col == STRLEN(old));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5967 if (*old != NUL && !trailblank && wasatend)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5968 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5969 dec_cursor();
301
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
5970 cc = gchar_cursor();
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
5971 if (!WHITECHAR(cc) && curwin->w_cursor.col > 0
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
5972 && has_format_option(FO_ONE_LETTER))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5973 dec_cursor();
301
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
5974 cc = gchar_cursor();
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
5975 if (WHITECHAR(cc))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5976 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5977 curwin->w_cursor = pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5978 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5979 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5980 curwin->w_cursor = pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5981 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5982
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5983 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5984 /* With the 'c' flag in 'formatoptions' and 't' missing: only format
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5985 * comments. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5986 if (has_format_option(FO_WRAP_COMS) && !has_format_option(FO_WRAP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5987 && get_leader_len(old, NULL, FALSE) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5988 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5989 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5990
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5991 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5992 * May start formatting in a previous line, so that after "x" a word is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5993 * moved to the previous line if it fits there now. Only when this is not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5994 * the start of a paragraph.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5995 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5996 if (prev_line && !paragraph_start(curwin->w_cursor.lnum))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5997 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5998 --curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5999 if (u_save_cursor() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6000 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6001 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6002
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6003 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6004 * Do the formatting and restore the cursor position. "saved_cursor" will
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6005 * be adjusted for the text formatting.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6006 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6007 saved_cursor = pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6008 format_lines((linenr_T)-1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6009 curwin->w_cursor = saved_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6010 saved_cursor.lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6011
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6012 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6013 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6014 /* "cannot happen" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6015 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6016 coladvance((colnr_T)MAXCOL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6017 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6018 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6019 check_cursor_col();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6020
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6021 /* Insert mode: If the cursor is now after the end of the line while it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6022 * previously wasn't, the line was broken. Because of the rule above we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6023 * need to add a space when 'w' is in 'formatoptions' to keep a paragraph
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6024 * formatted. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6025 if (!wasatend && has_format_option(FO_WHITE_PAR))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6026 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6027 new = ml_get_curline();
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 829
diff changeset
6028 len = (colnr_T)STRLEN(new);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6029 if (curwin->w_cursor.col == len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6030 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6031 pnew = vim_strnsave(new, len + 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6032 pnew[len] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6033 pnew[len + 1] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6034 ml_replace(curwin->w_cursor.lnum, pnew, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6035 /* remove the space later */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6036 did_add_space = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6037 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6038 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6039 /* may remove added space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6040 check_auto_format(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6041 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6042
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6043 check_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6044 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6045
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6046 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6047 * When an extra space was added to continue a paragraph for auto-formatting,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6048 * delete it now. The space must be under the cursor, just after the insert
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6049 * position.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6050 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6051 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6052 check_auto_format(end_insert)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6053 int end_insert; /* TRUE when ending Insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6054 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6055 int c = ' ';
301
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
6056 int cc;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6057
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6058 if (did_add_space)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6059 {
301
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
6060 cc = gchar_cursor();
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
6061 if (!WHITECHAR(cc))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6062 /* Somehow the space was removed already. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6063 did_add_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6064 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6065 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6066 if (!end_insert)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6067 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6068 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6069 c = gchar_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6070 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6071 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6072 if (c != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6073 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6074 /* The space is no longer at the end of the line, delete it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6075 del_char(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6076 did_add_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6077 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6078 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6079 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6080 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6081
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6082 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6083 * Find out textwidth to be used for formatting:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6084 * if 'textwidth' option is set, use it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6085 * else if 'wrapmargin' option is set, use W_WIDTH(curwin) - 'wrapmargin'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6086 * if invalid value, use 0.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6087 * Set default to window width (maximum 79) for "gq" operator.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6088 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6089 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6090 comp_textwidth(ff)
867
a5677b7ce858 updated for version 7.0g04
vimboss
parents: 864
diff changeset
6091 int ff; /* force formatting (for "gq" command) */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6092 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6093 int textwidth;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6094
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6095 textwidth = curbuf->b_p_tw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6096 if (textwidth == 0 && curbuf->b_p_wm)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6097 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6098 /* The width is the window width minus 'wrapmargin' minus all the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6099 * things that add to the margin. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6100 textwidth = W_WIDTH(curwin) - curbuf->b_p_wm;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6101 #ifdef FEAT_CMDWIN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6102 if (cmdwin_type != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6103 textwidth -= 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6104 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6105 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6106 textwidth -= curwin->w_p_fdc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6107 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6108 #ifdef FEAT_SIGNS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6109 if (curwin->w_buffer->b_signlist != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6110 # ifdef FEAT_NETBEANS_INTG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6111 || usingNetbeans
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6112 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6113 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6114 textwidth -= 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6115 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6116 if (curwin->w_p_nu)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6117 textwidth -= 8;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6118 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6119 if (textwidth < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6120 textwidth = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6121 if (ff && textwidth == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6122 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6123 textwidth = W_WIDTH(curwin) - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6124 if (textwidth > 79)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6125 textwidth = 79;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6126 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6127 return textwidth;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6128 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6129
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6130 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6131 * Put a character in the redo buffer, for when just after a CTRL-V.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6132 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6133 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6134 redo_literal(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6135 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6136 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6137 char_u buf[10];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6138
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6139 /* Only digits need special treatment. Translate them into a string of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6140 * three digits. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6141 if (VIM_ISDIGIT(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6142 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6143 sprintf((char *)buf, "%03d", c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6144 AppendToRedobuff(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6145 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6146 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6147 AppendCharToRedobuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6148 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6149
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6150 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6151 * start_arrow() is called when an arrow key is used in insert mode.
484
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6152 * For undo/redo it resembles hitting the <ESC> key.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6153 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6154 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6155 start_arrow(end_insert_pos)
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6156 pos_T *end_insert_pos; /* can be NULL */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6157 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6158 if (!arrow_used) /* something has been inserted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6159 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6160 AppendToRedobuff(ESC_STR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6161 stop_insert(end_insert_pos, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6162 arrow_used = TRUE; /* this means we stopped the current insert */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6163 }
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
6164 #ifdef FEAT_SPELL
221
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6165 check_spell_redraw();
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6166 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6167 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6168
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
6169 #ifdef FEAT_SPELL
221
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6170 /*
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6171 * If we skipped highlighting word at cursor, do it now.
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6172 * It may be skipped again, thus reset spell_redraw_lnum first.
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6173 */
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6174 static void
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6175 check_spell_redraw()
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6176 {
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6177 if (spell_redraw_lnum != 0)
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6178 {
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6179 linenr_T lnum = spell_redraw_lnum;
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6180
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6181 spell_redraw_lnum = 0;
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6182 redrawWinline(lnum, FALSE);
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6183 }
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6184 }
484
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6185
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6186 /*
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6187 * Called when starting CTRL_X_SPELL mode: Move backwards to a previous badly
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6188 * spelled word, if there is one.
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6189 */
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6190 static void
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6191 spell_back_to_badword()
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6192 {
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6193 pos_T tpos = curwin->w_cursor;
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6194
499
08012a1ff8d4 updated for version 7.0137
vimboss
parents: 497
diff changeset
6195 spell_bad_len = spell_move_to(curwin, BACKWARD, TRUE, TRUE, NULL);
484
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6196 if (curwin->w_cursor.col != tpos.col)
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6197 start_arrow(&tpos);
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6198 }
221
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6199 #endif
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6200
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6201 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6202 * stop_arrow() is called before a change is made in insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6203 * If an arrow key has been used, start a new insertion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6204 * Returns FAIL if undo is impossible, shouldn't insert then.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6205 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6206 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6207 stop_arrow()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6208 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6209 if (arrow_used)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6210 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6211 if (u_save_cursor() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6212 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6213 arrow_used = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6214 ins_need_undo = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6215 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6216 Insstart = curwin->w_cursor; /* new insertion starts here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6217 Insstart_textlen = linetabsize(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6218 ai_col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6219 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6220 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6221 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6222 orig_line_count = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6223 vr_lines_changed = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6224 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6225 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6226 ResetRedobuff();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6227 AppendToRedobuff((char_u *)"1i"); /* pretend we start an insertion */
613
53114ef7778f updated for version 7.0174
vimboss
parents: 610
diff changeset
6228 new_insert_skip = 2;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6229 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6230 else if (ins_need_undo)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6231 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6232 if (u_save_cursor() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6233 ins_need_undo = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6234 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6235
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6236 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6237 /* Always open fold at the cursor line when inserting something. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6238 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6239 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6240
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6241 return (arrow_used || ins_need_undo ? FAIL : OK);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6242 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6243
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6244 /*
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6245 * Do a few things to stop inserting.
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6246 * "end_insert_pos" is where insert ended. It is NULL when we already jumped
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6247 * to another window/buffer.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6248 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6249 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6250 stop_insert(end_insert_pos, esc)
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6251 pos_T *end_insert_pos;
603
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6252 int esc; /* called by ins_esc() */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6253 {
603
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6254 int cc;
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6255 char_u *ptr;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6256
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6257 stop_redo_ins();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6258 replace_flush(); /* abandon replace stack */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6259
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6260 /*
603
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6261 * Save the inserted text for later redo with ^@ and CTRL-A.
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6262 * Don't do it when "restart_edit" was set and nothing was inserted,
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6263 * otherwise CTRL-O w and then <Left> will clear "last_insert".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6264 */
603
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6265 ptr = get_inserted();
615
7fe13e0f5dce updated for version 7.0175
vimboss
parents: 613
diff changeset
6266 if (did_restart_edit == 0 || (ptr != NULL
7fe13e0f5dce updated for version 7.0175
vimboss
parents: 613
diff changeset
6267 && (int)STRLEN(ptr) > new_insert_skip))
603
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6268 {
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6269 vim_free(last_insert);
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6270 last_insert = ptr;
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6271 last_insert_skip = new_insert_skip;
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6272 }
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6273 else
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6274 vim_free(ptr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6275
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6276 if (!arrow_used && end_insert_pos != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6277 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6278 /* Auto-format now. It may seem strange to do this when stopping an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6279 * insertion (or moving the cursor), but it's required when appending
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6280 * a line and having it end in a space. But only do it when something
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6281 * was actually inserted, otherwise undo won't work. */
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6282 if (!ins_need_undo && has_format_option(FO_AUTO))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6283 {
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6284 pos_T tpos = curwin->w_cursor;
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6285
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6286 /* When the cursor is at the end of the line after a space the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6287 * formatting will move it to the following word. Avoid that by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6288 * moving the cursor onto the space. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6289 cc = 'x';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6290 if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6291 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6292 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6293 cc = gchar_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6294 if (!vim_iswhite(cc))
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6295 curwin->w_cursor = tpos;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6296 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6297
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6298 auto_format(TRUE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6299
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6300 if (vim_iswhite(cc))
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6301 {
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6302 if (gchar_cursor() != NUL)
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6303 inc_cursor();
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6304 #ifdef FEAT_VIRTUALEDIT
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6305 /* If the cursor is still at the same character, also keep
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6306 * the "coladd". */
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6307 if (gchar_cursor() == NUL
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6308 && curwin->w_cursor.lnum == tpos.lnum
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6309 && curwin->w_cursor.col == tpos.col)
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6310 curwin->w_cursor.coladd = tpos.coladd;
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6311 #endif
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6312 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6313 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6314
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6315 /* If a space was inserted for auto-formatting, remove it now. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6316 check_auto_format(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6317
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6318 /* If we just did an auto-indent, remove the white space from the end
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6319 * of the line, and put the cursor back.
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6320 * Do this when ESC was used or moving the cursor up/down. */
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6321 if (did_ai && (esc || (vim_strchr(p_cpo, CPO_INDENT) == NULL
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6322 && curwin->w_cursor.lnum != end_insert_pos->lnum)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6323 {
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6324 pos_T tpos = curwin->w_cursor;
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6325
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6326 curwin->w_cursor = *end_insert_pos;
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
6327 for (;;)
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
6328 {
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
6329 if (gchar_cursor() == NUL && curwin->w_cursor.col > 0)
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
6330 --curwin->w_cursor.col;
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
6331 cc = gchar_cursor();
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
6332 if (!vim_iswhite(cc))
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
6333 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6334 (void)del_char(TRUE);
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
6335 }
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6336 if (curwin->w_cursor.lnum != tpos.lnum)
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6337 curwin->w_cursor = tpos;
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6338 else if (cc != NUL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6339 ++curwin->w_cursor.col; /* put cursor back on the NUL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6340
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6341 #ifdef FEAT_VISUAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6342 /* <C-S-Right> may have started Visual mode, adjust the position for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6343 * deleted characters. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6344 if (VIsual_active && VIsual.lnum == curwin->w_cursor.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6345 {
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 829
diff changeset
6346 cc = (int)STRLEN(ml_get_curline());
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6347 if (VIsual.col > (colnr_T)cc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6348 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6349 VIsual.col = cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6350 # ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6351 VIsual.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6352 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6353 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6354 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6355 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6356 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6357 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6358 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6359 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6360 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6361 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6362 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6363 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6364
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6365 /* Set '[ and '] to the inserted text. When end_insert_pos is NULL we are
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6366 * now in a different buffer. */
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6367 if (end_insert_pos != NULL)
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6368 {
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6369 curbuf->b_op_start = Insstart;
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6370 curbuf->b_op_end = *end_insert_pos;
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6371 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6372 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6373
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6374 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6375 * Set the last inserted text to a single character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6376 * Used for the replace command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6377 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6378 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6379 set_last_insert(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6380 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6381 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6382 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6383
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6384 vim_free(last_insert);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6385 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6386 last_insert = alloc(MB_MAXBYTES * 3 + 5);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6387 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6388 last_insert = alloc(6);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6389 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6390 if (last_insert != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6391 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6392 s = last_insert;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6393 /* Use the CTRL-V only when entering a special char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6394 if (c < ' ' || c == DEL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6395 *s++ = Ctrl_V;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6396 s = add_char2buf(c, s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6397 *s++ = ESC;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6398 *s++ = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6399 last_insert_skip = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6400 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6401 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6402
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
6403 #if defined(EXITFREE) || defined(PROTO)
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
6404 void
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
6405 free_last_insert()
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
6406 {
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
6407 vim_free(last_insert);
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
6408 last_insert = NULL;
694
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
6409 vim_free(compl_orig_text);
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
6410 compl_orig_text = NULL;
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
6411 }
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
6412 #endif
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
6413
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6414 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6415 * Add character "c" to buffer "s". Escape the special meaning of K_SPECIAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6416 * and CSI. Handle multi-byte characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6417 * Returns a pointer to after the added bytes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6418 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6419 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6420 add_char2buf(c, s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6421 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6422 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6423 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6424 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6425 char_u temp[MB_MAXBYTES];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6426 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6427 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6428
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6429 len = (*mb_char2bytes)(c, temp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6430 for (i = 0; i < len; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6431 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6432 c = temp[i];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6433 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6434 /* Need to escape K_SPECIAL and CSI like in the typeahead buffer. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6435 if (c == K_SPECIAL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6436 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6437 *s++ = K_SPECIAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6438 *s++ = KS_SPECIAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6439 *s++ = KE_FILLER;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6440 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6441 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6442 else if (c == CSI)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6443 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6444 *s++ = CSI;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6445 *s++ = KS_EXTRA;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6446 *s++ = (int)KE_CSI;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6447 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6448 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6449 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6450 *s++ = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6451 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6452 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6453 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6454 return s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6455 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6456
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6457 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6458 * move cursor to start of line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6459 * if flags & BL_WHITE move to first non-white
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6460 * if flags & BL_SOL move to first non-white if startofline is set,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6461 * otherwise keep "curswant" column
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6462 * if flags & BL_FIX don't leave the cursor on a NUL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6463 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6464 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6465 beginline(flags)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6466 int flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6467 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6468 if ((flags & BL_SOL) && !p_sol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6469 coladvance(curwin->w_curswant);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6470 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6471 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6472 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6473 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6474 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6475 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6476
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6477 if (flags & (BL_WHITE | BL_SOL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6478 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6479 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6480
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6481 for (ptr = ml_get_curline(); vim_iswhite(*ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6482 && !((flags & BL_FIX) && ptr[1] == NUL); ++ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6483 ++curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6484 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6485 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6486 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6487 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6488
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6489 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6490 * oneright oneleft cursor_down cursor_up
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6491 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6492 * Move one char {right,left,down,up}.
773
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6493 * Doesn't move onto the NUL past the end of the line, unless it is allowed.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6494 * Return OK when successful, FAIL when we hit a line of file boundary.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6495 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6496
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6497 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6498 oneright()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6499 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6500 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6501 int l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6502
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6503 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6504 if (virtual_active())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6505 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6506 pos_T prevpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6507
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6508 /* Adjust for multi-wide char (excluding TAB) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6509 ptr = ml_get_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6510 coladvance(getviscol() + ((*ptr != TAB && vim_isprintc(
773
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6511 # ifdef FEAT_MBYTE
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6512 (*mb_ptr2char)(ptr)
773
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6513 # else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6514 *ptr
773
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6515 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6516 ))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6517 ? ptr2cells(ptr) : 1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6518 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6519 /* Return OK if the cursor moved, FAIL otherwise (at window edge). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6520 return (prevpos.col != curwin->w_cursor.col
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6521 || prevpos.coladd != curwin->w_cursor.coladd) ? OK : FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6522 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6523 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6524
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6525 ptr = ml_get_cursor();
773
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6526 if (*ptr == NUL)
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6527 return FAIL; /* already at the very end */
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6528
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6529 #ifdef FEAT_MBYTE
773
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6530 if (has_mbyte)
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6531 l = (*mb_ptr2len)(ptr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6532 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6533 #endif
773
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6534 l = 1;
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6535
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6536 /* move "l" bytes right, but don't end up on the NUL, unless 'virtualedit'
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6537 * contains "onemore". */
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6538 if (ptr[l] == NUL
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6539 #ifdef FEAT_VIRTUALEDIT
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6540 && (ve_flags & VE_ONEMORE) == 0
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6541 #endif
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6542 )
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6543 return FAIL;
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6544 curwin->w_cursor.col += l;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6545
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6546 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6547 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6548 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6549
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6550 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6551 oneleft()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6552 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6553 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6554 if (virtual_active())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6555 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6556 int width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6557 int v = getviscol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6558
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6559 if (v == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6560 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6561
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6562 # ifdef FEAT_LINEBREAK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6563 /* We might get stuck on 'showbreak', skip over it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6564 width = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6565 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6566 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6567 coladvance(v - width);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6568 /* getviscol() is slow, skip it when 'showbreak' is empty and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6569 * there are no multi-byte characters */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6570 if ((*p_sbr == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6571 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6572 && !has_mbyte
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6573 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6574 ) || getviscol() < v)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6575 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6576 ++width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6577 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6578 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6579 coladvance(v - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6580 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6581
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6582 if (curwin->w_cursor.coladd == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6583 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6584 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6585
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6586 /* Adjust for multi-wide char (not a TAB) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6587 ptr = ml_get_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6588 if (*ptr != TAB && vim_isprintc(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6589 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6590 (*mb_ptr2char)(ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6591 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6592 *ptr
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6593 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6594 ) && ptr2cells(ptr) > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6595 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6596 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6597
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6598 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6599 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6600 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6601 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6602
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6603 if (curwin->w_cursor.col == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6604 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6605
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6606 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6607 --curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6608
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6609 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6610 /* if the character on the left of the current cursor is a multi-byte
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6611 * character, move to its first byte */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6612 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6613 mb_adjust_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6614 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6615 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6616 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6617
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6618 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6619 cursor_up(n, upd_topline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6620 long n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6621 int upd_topline; /* When TRUE: update topline */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6622 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6623 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6624
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6625 if (n > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6626 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6627 lnum = curwin->w_cursor.lnum;
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
6628 /* This fails if the cursor is already in the first line or the count
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
6629 * is larger than the line number and '-' is in 'cpoptions' */
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
6630 if (lnum <= 1 || (n >= lnum && vim_strchr(p_cpo, CPO_MINUS) != NULL))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6631 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6632 if (n >= lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6633 lnum = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6634 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6635 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6636 if (hasAnyFolding(curwin))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6637 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6638 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6639 * Count each sequence of folded lines as one logical line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6640 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6641 /* go to the the start of the current fold */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6642 (void)hasFolding(lnum, &lnum, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6643
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6644 while (n--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6645 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6646 /* move up one line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6647 --lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6648 if (lnum <= 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6649 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6650 /* If we entered a fold, move to the beginning, unless in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6651 * Insert mode or when 'foldopen' contains "all": it will open
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6652 * in a moment. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6653 if (n > 0 || !((State & INSERT) || (fdo_flags & FDO_ALL)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6654 (void)hasFolding(lnum, &lnum, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6655 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6656 if (lnum < 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6657 lnum = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6658 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6659 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6660 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6661 lnum -= n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6662 curwin->w_cursor.lnum = lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6663 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6664
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6665 /* try to advance to the column we want to be at */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6666 coladvance(curwin->w_curswant);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6667
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6668 if (upd_topline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6669 update_topline(); /* make sure curwin->w_topline is valid */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6670
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6671 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6672 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6673
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6674 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6675 * Cursor down a number of logical lines.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6676 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6677 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6678 cursor_down(n, upd_topline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6679 long n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6680 int upd_topline; /* When TRUE: update topline */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6681 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6682 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6683
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6684 if (n > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6685 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6686 lnum = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6687 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6688 /* Move to last line of fold, will fail if it's the end-of-file. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6689 (void)hasFolding(lnum, NULL, &lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6690 #endif
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
6691 /* This fails if the cursor is already in the last line or would move
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
6692 * beyound the last line and '-' is in 'cpoptions' */
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
6693 if (lnum >= curbuf->b_ml.ml_line_count
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
6694 || (lnum + n > curbuf->b_ml.ml_line_count
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
6695 && vim_strchr(p_cpo, CPO_MINUS) != NULL))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6696 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6697 if (lnum + n >= curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6698 lnum = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6699 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6700 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6701 if (hasAnyFolding(curwin))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6702 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6703 linenr_T last;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6704
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6705 /* count each sequence of folded lines as one logical line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6706 while (n--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6707 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6708 if (hasFolding(lnum, NULL, &last))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6709 lnum = last + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6710 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6711 ++lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6712 if (lnum >= curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6713 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6714 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6715 if (lnum > curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6716 lnum = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6717 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6718 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6719 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6720 lnum += n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6721 curwin->w_cursor.lnum = lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6722 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6723
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6724 /* try to advance to the column we want to be at */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6725 coladvance(curwin->w_curswant);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6726
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6727 if (upd_topline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6728 update_topline(); /* make sure curwin->w_topline is valid */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6729
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6730 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6731 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6732
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6733 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6734 * Stuff the last inserted text in the read buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6735 * Last_insert actually is a copy of the redo buffer, so we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6736 * first have to remove the command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6737 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6738 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6739 stuff_inserted(c, count, no_esc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6740 int c; /* Command character to be inserted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6741 long count; /* Repeat this many times */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6742 int no_esc; /* Don't add an ESC at the end */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6743 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6744 char_u *esc_ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6745 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6746 char_u *last_ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6747 char_u last = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6748
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6749 ptr = get_last_insert();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6750 if (ptr == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6751 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6752 EMSG(_(e_noinstext));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6753 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6754 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6755
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6756 /* may want to stuff the command character, to start Insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6757 if (c != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6758 stuffcharReadbuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6759 if ((esc_ptr = (char_u *)vim_strrchr(ptr, ESC)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6760 *esc_ptr = NUL; /* remove the ESC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6761
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6762 /* when the last char is either "0" or "^" it will be quoted if no ESC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6763 * comes after it OR if it will inserted more than once and "ptr"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6764 * starts with ^D. -- Acevedo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6765 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6766 last_ptr = (esc_ptr ? esc_ptr : ptr + STRLEN(ptr)) - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6767 if (last_ptr >= ptr && (*last_ptr == '0' || *last_ptr == '^')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6768 && (no_esc || (*ptr == Ctrl_D && count > 1)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6769 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6770 last = *last_ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6771 *last_ptr = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6772 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6773
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6774 do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6775 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6776 stuffReadbuff(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6777 /* a trailing "0" is inserted as "<C-V>048", "^" as "<C-V>^" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6778 if (last)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6779 stuffReadbuff((char_u *)(last == '0'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6780 ? IF_EB("\026\060\064\070", CTRL_V_STR "xf0")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6781 : IF_EB("\026^", CTRL_V_STR "^")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6782 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6783 while (--count > 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6784
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6785 if (last)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6786 *last_ptr = last;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6787
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6788 if (esc_ptr != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6789 *esc_ptr = ESC; /* put the ESC back */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6790
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6791 /* may want to stuff a trailing ESC, to get out of Insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6792 if (!no_esc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6793 stuffcharReadbuff(ESC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6794
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6795 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6796 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6797
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6798 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6799 get_last_insert()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6800 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6801 if (last_insert == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6802 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6803 return last_insert + last_insert_skip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6804 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6805
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6806 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6807 * Get last inserted string, and remove trailing <Esc>.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6808 * Returns pointer to allocated memory (must be freed) or NULL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6809 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6810 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6811 get_last_insert_save()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6812 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6813 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6814 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6815
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6816 if (last_insert == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6817 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6818 s = vim_strsave(last_insert + last_insert_skip);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6819 if (s != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6820 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6821 len = (int)STRLEN(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6822 if (len > 0 && s[len - 1] == ESC) /* remove trailing ESC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6823 s[len - 1] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6824 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6825 return s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6826 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6827
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6828 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6829 * Check the word in front of the cursor for an abbreviation.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6830 * Called when the non-id character "c" has been entered.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6831 * When an abbreviation is recognized it is removed from the text and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6832 * the replacement string is inserted in typebuf.tb_buf[], followed by "c".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6833 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6834 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6835 echeck_abbr(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6836 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6837 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6838 /* Don't check for abbreviation in paste mode, when disabled and just
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6839 * after moving around with cursor keys. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6840 if (p_paste || no_abbr || arrow_used)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6841 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6842
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6843 return check_abbr(c, ml_get_curline(), curwin->w_cursor.col,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6844 curwin->w_cursor.lnum == Insstart.lnum ? Insstart.col : 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6845 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6846
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6847 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6848 * replace-stack functions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6849 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6850 * When replacing characters, the replaced characters are remembered for each
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6851 * new character. This is used to re-insert the old text when backspacing.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6852 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6853 * There is a NUL headed list of characters for each character that is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6854 * currently in the file after the insertion point. When BS is used, one NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6855 * headed list is put back for the deleted character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6856 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6857 * For a newline, there are two NUL headed lists. One contains the characters
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6858 * that the NL replaced. The extra one stores the characters after the cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6859 * that were deleted (always white space).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6860 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6861 * Replace_offset is normally 0, in which case replace_push will add a new
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6862 * character at the end of the stack. If replace_offset is not 0, that many
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6863 * characters will be left on the stack above the newly inserted character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6864 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6865
298
f9de3e679a04 updated for version 7.0078
vimboss
parents: 278
diff changeset
6866 static char_u *replace_stack = NULL;
f9de3e679a04 updated for version 7.0078
vimboss
parents: 278
diff changeset
6867 static long replace_stack_nr = 0; /* next entry in replace stack */
f9de3e679a04 updated for version 7.0078
vimboss
parents: 278
diff changeset
6868 static long replace_stack_len = 0; /* max. number of entries */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6869
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6870 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6871 replace_push(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6872 int c; /* character that is replaced (NUL is none) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6873 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6874 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6875
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6876 if (replace_stack_nr < replace_offset) /* nothing to do */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6877 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6878 if (replace_stack_len <= replace_stack_nr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6879 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6880 replace_stack_len += 50;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6881 p = lalloc(sizeof(char_u) * replace_stack_len, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6882 if (p == NULL) /* out of memory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6883 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6884 replace_stack_len -= 50;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6885 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6886 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6887 if (replace_stack != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6888 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6889 mch_memmove(p, replace_stack,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6890 (size_t)(replace_stack_nr * sizeof(char_u)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6891 vim_free(replace_stack);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6892 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6893 replace_stack = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6894 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6895 p = replace_stack + replace_stack_nr - replace_offset;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6896 if (replace_offset)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6897 mch_memmove(p + 1, p, (size_t)(replace_offset * sizeof(char_u)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6898 *p = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6899 ++replace_stack_nr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6900 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6901
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6902 #if 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6903 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6904 * call replace_push(c) with replace_offset set to the first NUL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6905 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6906 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6907 replace_push_off(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6908 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6909 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6910 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6911
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6912 p = replace_stack + replace_stack_nr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6913 for (replace_offset = 1; replace_offset < replace_stack_nr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6914 ++replace_offset)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6915 if (*--p == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6916 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6917 replace_push(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6918 replace_offset = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6919 }
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6920 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6921
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6922 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6923 * Pop one item from the replace stack.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6924 * return -1 if stack empty
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6925 * return replaced character or NUL otherwise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6926 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6927 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6928 replace_pop()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6929 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6930 if (replace_stack_nr == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6931 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6932 return (int)replace_stack[--replace_stack_nr];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6933 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6934
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6935 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6936 * Join the top two items on the replace stack. This removes to "off"'th NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6937 * encountered.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6938 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6939 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6940 replace_join(off)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6941 int off; /* offset for which NUL to remove */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6942 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6943 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6944
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6945 for (i = replace_stack_nr; --i >= 0; )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6946 if (replace_stack[i] == NUL && off-- <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6947 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6948 --replace_stack_nr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6949 mch_memmove(replace_stack + i, replace_stack + i + 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6950 (size_t)(replace_stack_nr - i));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6951 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6952 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6953 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6954
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6955 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6956 * Pop bytes from the replace stack until a NUL is found, and insert them
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6957 * before the cursor. Can only be used in REPLACE or VREPLACE mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6958 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6959 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6960 replace_pop_ins()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6961 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6962 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6963 int oldState = State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6964
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6965 State = NORMAL; /* don't want REPLACE here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6966 while ((cc = replace_pop()) > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6967 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6968 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6969 mb_replace_pop_ins(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6970 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6971 ins_char(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6972 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6973 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6974 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6975 State = oldState;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6976 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6977
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6978 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6979 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6980 * Insert bytes popped from the replace stack. "cc" is the first byte. If it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6981 * indicates a multi-byte char, pop the other bytes too.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6982 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6983 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6984 mb_replace_pop_ins(cc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6985 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6986 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6987 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6988 char_u buf[MB_MAXBYTES];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6989 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6990 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6991
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6992 if (has_mbyte && (n = MB_BYTE2LEN(cc)) > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6993 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6994 buf[0] = cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6995 for (i = 1; i < n; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6996 buf[i] = replace_pop();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6997 ins_bytes_len(buf, n);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6998 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6999 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7000 ins_char(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7001
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7002 if (enc_utf8)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7003 /* Handle composing chars. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7004 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7005 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7006 c = replace_pop();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7007 if (c == -1) /* stack empty */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7008 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7009 if ((n = MB_BYTE2LEN(c)) == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7010 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7011 /* Not a multi-byte char, put it back. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7012 replace_push(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7013 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7014 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7015 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7016 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7017 buf[0] = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7018 for (i = 1; i < n; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7019 buf[i] = replace_pop();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7020 if (utf_iscomposing(utf_ptr2char(buf)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7021 ins_bytes_len(buf, n);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7022 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7023 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7024 /* Not a composing char, put it back. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7025 for (i = n - 1; i >= 0; --i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7026 replace_push(buf[i]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7027 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7028 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7029 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7030 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7031 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7032 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7033
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7034 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7035 * make the replace stack empty
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7036 * (called when exiting replace mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7037 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7038 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7039 replace_flush()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7040 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7041 vim_free(replace_stack);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7042 replace_stack = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7043 replace_stack_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7044 replace_stack_nr = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7045 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7046
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7047 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7048 * Handle doing a BS for one character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7049 * cc < 0: replace stack empty, just move cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7050 * cc == 0: character was inserted, delete it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7051 * cc > 0: character was replaced, put cc (first byte of original char) back
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7052 * and check for more characters to be put back
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7053 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7054 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7055 replace_do_bs()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7056 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7057 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7058 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7059 int orig_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7060 int ins_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7061 int orig_vcols = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7062 colnr_T start_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7063 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7064 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7065 int vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7066 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7067
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7068 cc = replace_pop();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7069 if (cc > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7070 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7071 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7072 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7073 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7074 /* Get the number of screen cells used by the character we are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7075 * going to delete. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7076 getvcol(curwin, &curwin->w_cursor, NULL, &start_vcol, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7077 orig_vcols = chartabsize(ml_get_cursor(), start_vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7078 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7079 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7080 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7081 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7082 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7083 del_char(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7084 # ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7085 if (State & VREPLACE_FLAG)
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 829
diff changeset
7086 orig_len = (int)STRLEN(ml_get_cursor());
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7087 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7088 replace_push(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7089 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7090 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7091 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7092 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7093 pchar_cursor(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7094 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7095 if (State & VREPLACE_FLAG)
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 829
diff changeset
7096 orig_len = (int)STRLEN(ml_get_cursor()) - 1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7097 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7098 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7099 replace_pop_ins();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7100
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7101 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7102 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7103 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7104 /* Get the number of screen cells used by the inserted characters */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7105 p = ml_get_cursor();
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 829
diff changeset
7106 ins_len = (int)STRLEN(p) - orig_len;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7107 vcol = start_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7108 for (i = 0; i < ins_len; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7109 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7110 vcol += chartabsize(p + i, vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7111 #ifdef FEAT_MBYTE
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 470
diff changeset
7112 i += (*mb_ptr2len)(p) - 1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7113 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7114 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7115 vcol -= start_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7116
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7117 /* Delete spaces that were inserted after the cursor to keep the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7118 * text aligned. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7119 curwin->w_cursor.col += ins_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7120 while (vcol > orig_vcols && gchar_cursor() == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7121 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7122 del_char(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7123 ++orig_vcols;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7124 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7125 curwin->w_cursor.col -= ins_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7126 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7127 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7128
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7129 /* mark the buffer as changed and prepare for displaying */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7130 changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7131 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7132 else if (cc == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7133 (void)del_char(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7134 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7135
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7136 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7137 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7138 * Return TRUE if C-indenting is on.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7139 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7140 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7141 cindent_on()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7142 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7143 return (!p_paste && (curbuf->b_p_cin
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7144 # ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7145 || *curbuf->b_p_inde != NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7146 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7147 ));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7148 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7149 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7150
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7151 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7152 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7153 * Re-indent the current line, based on the current contents of it and the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7154 * surrounding lines. Fixing the cursor position seems really easy -- I'm very
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7155 * confused what all the part that handles Control-T is doing that I'm not.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7156 * "get_the_indent" should be get_c_indent, get_expr_indent or get_lisp_indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7157 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7158
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7159 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7160 fixthisline(get_the_indent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7161 int (*get_the_indent) __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7162 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7163 change_indent(INDENT_SET, get_the_indent(), FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7164 if (linewhite(curwin->w_cursor.lnum))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7165 did_ai = TRUE; /* delete the indent if the line stays empty */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7166 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7167
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7168 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7169 fix_indent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7170 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7171 if (p_paste)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7172 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7173 # ifdef FEAT_LISP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7174 if (curbuf->b_p_lisp && curbuf->b_p_ai)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7175 fixthisline(get_lisp_indent);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7176 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7177 # if defined(FEAT_LISP) && defined(FEAT_CINDENT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7178 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7179 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7180 # ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7181 if (cindent_on())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7182 do_c_expr_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7183 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7184 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7185
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7186 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7187
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7188 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7189 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7190 * return TRUE if 'cinkeys' contains the key "keytyped",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7191 * when == '*': Only if key is preceded with '*' (indent before insert)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7192 * when == '!': Only if key is prededed with '!' (don't insert)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7193 * when == ' ': Only if key is not preceded with '*'(indent afterwards)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7194 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7195 * "keytyped" can have a few special values:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7196 * KEY_OPEN_FORW
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7197 * KEY_OPEN_BACK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7198 * KEY_COMPLETE just finished completion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7199 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7200 * If line_is_empty is TRUE accept keys with '0' before them.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7201 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7202 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7203 in_cinkeys(keytyped, when, line_is_empty)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7204 int keytyped;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7205 int when;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7206 int line_is_empty;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7207 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7208 char_u *look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7209 int try_match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7210 int try_match_word;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7211 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7212 char_u *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7213 int icase;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7214 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7215
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7216 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7217 if (*curbuf->b_p_inde != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7218 look = curbuf->b_p_indk; /* 'indentexpr' set: use 'indentkeys' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7219 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7220 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7221 look = curbuf->b_p_cink; /* 'indentexpr' empty: use 'cinkeys' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7222 while (*look)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7223 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7224 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7225 * Find out if we want to try a match with this key, depending on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7226 * 'when' and a '*' or '!' before the key.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7227 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7228 switch (when)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7229 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7230 case '*': try_match = (*look == '*'); break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7231 case '!': try_match = (*look == '!'); break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7232 default: try_match = (*look != '*'); break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7233 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7234 if (*look == '*' || *look == '!')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7235 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7236
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7237 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7238 * If there is a '0', only accept a match if the line is empty.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7239 * But may still match when typing last char of a word.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7240 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7241 if (*look == '0')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7242 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7243 try_match_word = try_match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7244 if (!line_is_empty)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7245 try_match = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7246 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7247 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7248 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7249 try_match_word = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7250
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7251 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7252 * does it look like a control character?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7253 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7254 if (*look == '^'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7255 #ifdef EBCDIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7256 && (Ctrl_chr(look[1]) != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7257 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7258 && look[1] >= '?' && look[1] <= '_'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7259 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7260 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7261 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7262 if (try_match && keytyped == Ctrl_chr(look[1]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7263 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7264 look += 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7265 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7266 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7267 * 'o' means "o" command, open forward.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7268 * 'O' means "O" command, open backward.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7269 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7270 else if (*look == 'o')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7271 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7272 if (try_match && keytyped == KEY_OPEN_FORW)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7273 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7274 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7275 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7276 else if (*look == 'O')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7277 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7278 if (try_match && keytyped == KEY_OPEN_BACK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7279 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7280 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7281 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7282
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7283 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7284 * 'e' means to check for "else" at start of line and just before the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7285 * cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7286 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7287 else if (*look == 'e')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7288 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7289 if (try_match && keytyped == 'e' && curwin->w_cursor.col >= 4)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7290 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7291 p = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7292 if (skipwhite(p) == p + curwin->w_cursor.col - 4 &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7293 STRNCMP(p + curwin->w_cursor.col - 4, "else", 4) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7294 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7295 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7296 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7297 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7298
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7299 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7300 * ':' only causes an indent if it is at the end of a label or case
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7301 * statement, or when it was before typing the ':' (to fix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7302 * class::method for C++).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7303 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7304 else if (*look == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7305 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7306 if (try_match && keytyped == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7307 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7308 p = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7309 if (cin_iscase(p) || cin_isscopedecl(p) || cin_islabel(30))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7310 return TRUE;
1300
bacdeee78827 updated for version 7.1-014
vimboss
parents: 1219
diff changeset
7311 /* Need to get the line again after cin_islabel(). */
bacdeee78827 updated for version 7.1-014
vimboss
parents: 1219
diff changeset
7312 p = ml_get_curline();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7313 if (curwin->w_cursor.col > 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7314 && p[curwin->w_cursor.col - 1] == ':'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7315 && p[curwin->w_cursor.col - 2] == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7316 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7317 p[curwin->w_cursor.col - 1] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7318 i = (cin_iscase(p) || cin_isscopedecl(p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7319 || cin_islabel(30));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7320 p = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7321 p[curwin->w_cursor.col - 1] = ':';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7322 if (i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7323 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7324 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7325 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7326 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7327 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7328
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7329
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7330 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7331 * Is it a key in <>, maybe?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7332 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7333 else if (*look == '<')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7334 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7335 if (try_match)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7336 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7337 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7338 * make up some named keys <o>, <O>, <e>, <0>, <>>, <<>, <*>,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7339 * <:> and <!> so that people can re-indent on o, O, e, 0, <,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7340 * >, *, : and ! keys if they really really want to.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7341 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7342 if (vim_strchr((char_u *)"<>!*oOe0:", look[1]) != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7343 && keytyped == look[1])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7344 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7345
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7346 if (keytyped == get_special_key_code(look + 1))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7347 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7348 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7349 while (*look && *look != '>')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7350 look++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7351 while (*look == '>')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7352 look++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7353 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7354
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7355 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7356 * Is it a word: "=word"?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7357 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7358 else if (*look == '=' && look[1] != ',' && look[1] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7359 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7360 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7361 if (*look == '~')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7362 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7363 icase = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7364 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7365 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7366 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7367 icase = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7368 p = vim_strchr(look, ',');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7369 if (p == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7370 p = look + STRLEN(look);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7371 if ((try_match || try_match_word)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7372 && curwin->w_cursor.col >= (colnr_T)(p - look))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7373 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7374 int match = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7375
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7376 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7377 if (keytyped == KEY_COMPLETE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7378 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7379 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7380
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7381 /* Just completed a word, check if it starts with "look".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7382 * search back for the start of a word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7383 line = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7384 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7385 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7386 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7387 char_u *n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7388
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7389 for (s = line + curwin->w_cursor.col; s > line; s = n)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7390 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7391 n = mb_prevptr(line, s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7392 if (!vim_iswordp(n))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7393 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7394 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7395 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7396 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7397 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7398 for (s = line + curwin->w_cursor.col; s > line; --s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7399 if (!vim_iswordc(s[-1]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7400 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7401 if (s + (p - look) <= line + curwin->w_cursor.col
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7402 && (icase
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7403 ? MB_STRNICMP(s, look, p - look)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7404 : STRNCMP(s, look, p - look)) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7405 match = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7406 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7407 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7408 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7409 /* TODO: multi-byte */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7410 if (keytyped == (int)p[-1] || (icase && keytyped < 256
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7411 && TOLOWER_LOC(keytyped) == TOLOWER_LOC((int)p[-1])))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7412 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7413 line = ml_get_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7414 if ((curwin->w_cursor.col == (colnr_T)(p - look)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7415 || !vim_iswordc(line[-(p - look) - 1]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7416 && (icase
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7417 ? MB_STRNICMP(line - (p - look), look, p - look)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7418 : STRNCMP(line - (p - look), look, p - look))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7419 == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7420 match = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7421 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7422 if (match && try_match_word && !try_match)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7423 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7424 /* "0=word": Check if there are only blanks before the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7425 * word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7426 line = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7427 if ((int)(skipwhite(line) - line) !=
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7428 (int)(curwin->w_cursor.col - (p - look)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7429 match = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7430 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7431 if (match)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7432 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7433 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7434 look = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7435 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7436
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7437 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7438 * ok, it's a boring generic character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7439 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7440 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7441 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7442 if (try_match && *look == keytyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7443 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7444 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7445 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7446
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7447 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7448 * Skip over ", ".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7449 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7450 look = skip_to_option_part(look);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7451 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7452 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7453 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7454 #endif /* FEAT_CINDENT */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7455
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7456 #if defined(FEAT_RIGHTLEFT) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7457 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7458 * Map Hebrew keyboard when in hkmap mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7459 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7460 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7461 hkmap(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7462 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7463 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7464 if (p_hkmapp) /* phonetic mapping, by Ilya Dogolazky */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7465 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7466 enum {hALEF=0, BET, GIMEL, DALET, HEI, VAV, ZAIN, HET, TET, IUD,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7467 KAFsofit, hKAF, LAMED, MEMsofit, MEM, NUNsofit, NUN, SAMEH, AIN,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7468 PEIsofit, PEI, ZADIsofit, ZADI, KOF, RESH, hSHIN, TAV};
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7469 static char_u map[26] =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7470 {(char_u)hALEF/*a*/, (char_u)BET /*b*/, (char_u)hKAF /*c*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7471 (char_u)DALET/*d*/, (char_u)-1 /*e*/, (char_u)PEIsofit/*f*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7472 (char_u)GIMEL/*g*/, (char_u)HEI /*h*/, (char_u)IUD /*i*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7473 (char_u)HET /*j*/, (char_u)KOF /*k*/, (char_u)LAMED /*l*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7474 (char_u)MEM /*m*/, (char_u)NUN /*n*/, (char_u)SAMEH /*o*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7475 (char_u)PEI /*p*/, (char_u)-1 /*q*/, (char_u)RESH /*r*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7476 (char_u)ZAIN /*s*/, (char_u)TAV /*t*/, (char_u)TET /*u*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7477 (char_u)VAV /*v*/, (char_u)hSHIN/*w*/, (char_u)-1 /*x*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7478 (char_u)AIN /*y*/, (char_u)ZADI /*z*/};
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7479
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7480 if (c == 'N' || c == 'M' || c == 'P' || c == 'C' || c == 'Z')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7481 return (int)(map[CharOrd(c)] - 1 + p_aleph);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7482 /* '-1'='sofit' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7483 else if (c == 'x')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7484 return 'X';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7485 else if (c == 'q')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7486 return '\''; /* {geresh}={'} */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7487 else if (c == 246)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7488 return ' '; /* \"o --> ' ' for a german keyboard */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7489 else if (c == 228)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7490 return ' '; /* \"a --> ' ' -- / -- */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7491 else if (c == 252)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7492 return ' '; /* \"u --> ' ' -- / -- */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7493 #ifdef EBCDIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7494 else if (islower(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7495 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7496 /* NOTE: islower() does not do the right thing for us on Linux so we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7497 * do this the same was as 5.7 and previous, so it works correctly on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7498 * all systems. Specifically, the e.g. Delete and Arrow keys are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7499 * munged and won't work if e.g. searching for Hebrew text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7500 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7501 else if (c >= 'a' && c <= 'z')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7502 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7503 return (int)(map[CharOrdLow(c)] + p_aleph);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7504 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7505 return c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7506 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7507 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7508 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7509 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7510 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7511 case '`': return ';';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7512 case '/': return '.';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7513 case '\'': return ',';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7514 case 'q': return '/';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7515 case 'w': return '\'';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7516
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7517 /* Hebrew letters - set offset from 'a' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7518 case ',': c = '{'; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7519 case '.': c = 'v'; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7520 case ';': c = 't'; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7521 default: {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7522 static char str[] = "zqbcxlsjphmkwonu ydafe rig";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7523
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7524 #ifdef EBCDIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7525 /* see note about islower() above */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7526 if (!islower(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7527 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7528 if (c < 'a' || c > 'z')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7529 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7530 return c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7531 c = str[CharOrdLow(c)];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7532 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7533 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7534 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7535
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7536 return (int)(CharOrdLow(c) + p_aleph);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7537 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7538 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7539 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7540
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7541 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7542 ins_reg()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7543 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7544 int need_redraw = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7545 int regname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7546 int literally = 0;
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
7547 #ifdef FEAT_VISUAL
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
7548 int vis_active = VIsual_active;
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
7549 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7550
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7551 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7552 * If we are going to wait for a character, show a '"'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7553 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7554 pc_status = PC_STATUS_UNSET;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7555 if (redrawing() && !char_avail())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7556 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7557 /* may need to redraw when no more chars available now */
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
7558 ins_redraw(FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7559
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7560 edit_putchar('"', TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7561 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7562 add_to_showcmd_c(Ctrl_R);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7563 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7564 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7565
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7566 #ifdef USE_ON_FLY_SCROLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7567 dont_scroll = TRUE; /* disallow scrolling here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7568 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7569
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7570 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7571 * Don't map the register name. This also prevents the mode message to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7572 * deleted when ESC is hit.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7573 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7574 ++no_mapping;
1389
bdcfe793d49f updated for version 7.1-104
vimboss
parents: 1353
diff changeset
7575 regname = plain_vgetc();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7576 #ifdef FEAT_LANGMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7577 LANGMAP_ADJUST(regname, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7578 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7579 if (regname == Ctrl_R || regname == Ctrl_O || regname == Ctrl_P)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7580 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7581 /* Get a third key for literal register insertion */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7582 literally = regname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7583 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7584 add_to_showcmd_c(literally);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7585 #endif
1389
bdcfe793d49f updated for version 7.1-104
vimboss
parents: 1353
diff changeset
7586 regname = plain_vgetc();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7587 #ifdef FEAT_LANGMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7588 LANGMAP_ADJUST(regname, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7589 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7590 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7591 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7592
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7593 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7594 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7595 * Don't call u_sync() while getting the expression,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7596 * evaluating it or giving an error message for it!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7597 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7598 ++no_u_sync;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7599 if (regname == '=')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7600 {
133
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
7601 # ifdef USE_IM_CONTROL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7602 int im_on = im_get_status();
133
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
7603 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7604 regname = get_expr_register();
133
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
7605 # ifdef USE_IM_CONTROL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7606 /* Restore the Input Method. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7607 if (im_on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7608 im_set_active(TRUE);
133
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
7609 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7610 }
140
8ecb0db93e9a updated for version 7.0045
vimboss
parents: 133
diff changeset
7611 if (regname == NUL || !valid_yank_reg(regname, FALSE))
8ecb0db93e9a updated for version 7.0045
vimboss
parents: 133
diff changeset
7612 {
8ecb0db93e9a updated for version 7.0045
vimboss
parents: 133
diff changeset
7613 vim_beep();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7614 need_redraw = TRUE; /* remove the '"' */
140
8ecb0db93e9a updated for version 7.0045
vimboss
parents: 133
diff changeset
7615 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7616 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7617 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7618 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7619 if (literally == Ctrl_O || literally == Ctrl_P)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7620 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7621 /* Append the command to the redo buffer. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7622 AppendCharToRedobuff(Ctrl_R);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7623 AppendCharToRedobuff(literally);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7624 AppendCharToRedobuff(regname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7625
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7626 do_put(regname, BACKWARD, 1L,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7627 (literally == Ctrl_P ? PUT_FIXINDENT : 0) | PUT_CURSEND);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7628 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7629 else if (insert_reg(regname, literally) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7630 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7631 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7632 need_redraw = TRUE; /* remove the '"' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7633 }
133
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
7634 else if (stop_insert_mode)
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
7635 /* When the '=' register was used and a function was invoked that
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
7636 * did ":stopinsert" then stuff_empty() returns FALSE but we won't
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
7637 * insert anything, need to remove the '"' */
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
7638 need_redraw = TRUE;
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
7639
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7640 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7641 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7642 --no_u_sync;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7643 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7644 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7645 clear_showcmd();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7646 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7647
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7648 /* If the inserted register is empty, we need to remove the '"' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7649 if (need_redraw || stuff_empty())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7650 edit_unputchar();
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
7651
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
7652 #ifdef FEAT_VISUAL
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
7653 /* Disallow starting Visual mode here, would get a weird mode. */
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
7654 if (!vis_active && VIsual_active)
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
7655 end_visual_mode();
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
7656 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7657 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7658
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7659 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7660 * CTRL-G commands in Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7661 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7662 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7663 ins_ctrl_g()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7664 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7665 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7666
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7667 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7668 /* Right after CTRL-X the cursor will be after the ruler. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7669 setcursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7670 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7671
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7672 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7673 * Don't map the second key. This also prevents the mode message to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7674 * deleted when ESC is hit.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7675 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7676 ++no_mapping;
1389
bdcfe793d49f updated for version 7.1-104
vimboss
parents: 1353
diff changeset
7677 c = plain_vgetc();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7678 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7679 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7680 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7681 /* CTRL-G k and CTRL-G <Up>: cursor up to Insstart.col */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7682 case K_UP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7683 case Ctrl_K:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7684 case 'k': ins_up(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7685 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7686
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7687 /* CTRL-G j and CTRL-G <Down>: cursor down to Insstart.col */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7688 case K_DOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7689 case Ctrl_J:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7690 case 'j': ins_down(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7691 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7692
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7693 /* CTRL-G u: start new undoable edit */
825
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
7694 case 'u': u_sync(TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7695 ins_need_undo = TRUE;
626
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
7696
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
7697 /* Need to reset Insstart, esp. because a BS that joins
1219
aea597af5b4e updated for version 7.1b
vimboss
parents: 1159
diff changeset
7698 * a line to the previous one must save for undo. */
626
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
7699 Insstart = curwin->w_cursor;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7700 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7701
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7702 /* Unknown CTRL-G command, reserved for future expansion. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7703 default: vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7704 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7705 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7706
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7707 /*
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7708 * CTRL-^ in Insert mode.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7709 */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7710 static void
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7711 ins_ctrl_hat()
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7712 {
782
d20041a02ee5 updated for version 7.0228
vimboss
parents: 773
diff changeset
7713 if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE))
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7714 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7715 /* ":lmap" mappings exists, Toggle use of ":lmap" mappings. */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7716 if (State & LANGMAP)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7717 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7718 curbuf->b_p_iminsert = B_IMODE_NONE;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7719 State &= ~LANGMAP;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7720 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7721 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7722 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7723 curbuf->b_p_iminsert = B_IMODE_LMAP;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7724 State |= LANGMAP;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7725 #ifdef USE_IM_CONTROL
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7726 im_set_active(FALSE);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7727 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7728 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7729 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7730 #ifdef USE_IM_CONTROL
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7731 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7732 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7733 /* There are no ":lmap" mappings, toggle IM */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7734 if (im_get_status())
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7735 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7736 curbuf->b_p_iminsert = B_IMODE_NONE;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7737 im_set_active(FALSE);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7738 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7739 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7740 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7741 curbuf->b_p_iminsert = B_IMODE_IM;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7742 State &= ~LANGMAP;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7743 im_set_active(TRUE);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7744 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7745 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7746 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7747 set_iminsert_global();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7748 showmode();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7749 #ifdef FEAT_GUI
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7750 /* may show different cursor shape or color */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7751 if (gui.in_use)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7752 gui_update_cursor(TRUE, FALSE);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7753 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7754 #if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7755 /* Show/unshow value of 'keymap' in status lines. */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7756 status_redraw_curbuf();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7757 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7758 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7759
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7760 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7761 * Handle ESC in insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7762 * Returns TRUE when leaving insert mode, FALSE when going to repeat the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7763 * insert.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7764 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7765 static int
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
7766 ins_esc(count, cmdchar, nomove)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7767 long *count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7768 int cmdchar;
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
7769 int nomove; /* don't move cursor */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7770 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7771 int temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7772 static int disabled_redraw = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7773
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
7774 #ifdef FEAT_SPELL
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7775 check_spell_redraw();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7776 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7777 #if defined(FEAT_HANGULIN)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7778 # if defined(ESC_CHG_TO_ENG_MODE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7779 hangul_input_state_set(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7780 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7781 if (composing_hangul)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7782 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7783 push_raw_key(composing_hangul_buffer, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7784 composing_hangul = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7785 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7786 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7787
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7788 temp = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7789 if (disabled_redraw)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7790 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7791 --RedrawingDisabled;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7792 disabled_redraw = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7793 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7794 if (!arrow_used)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7795 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7796 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7797 * Don't append the ESC for "r<CR>" and "grx".
75
388f285bda1b updated for version 7.0031
vimboss
parents: 41
diff changeset
7798 * When 'insertmode' is set only CTRL-L stops Insert mode. Needed for
388f285bda1b updated for version 7.0031
vimboss
parents: 41
diff changeset
7799 * when "count" is non-zero.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7800 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7801 if (cmdchar != 'r' && cmdchar != 'v')
75
388f285bda1b updated for version 7.0031
vimboss
parents: 41
diff changeset
7802 AppendToRedobuff(p_im ? (char_u *)"\014" : ESC_STR);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7803
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7804 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7805 * Repeating insert may take a long time. Check for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7806 * interrupt now and then.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7807 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7808 if (*count > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7809 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7810 line_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7811 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7812 *count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7813 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7814
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7815 if (--*count > 0) /* repeat what was typed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7816 {
164
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 161
diff changeset
7817 /* Vi repeats the insert without replacing characters. */
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 161
diff changeset
7818 if (vim_strchr(p_cpo, CPO_REPLCNT) != NULL)
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 161
diff changeset
7819 State &= ~REPLACE_FLAG;
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 161
diff changeset
7820
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7821 (void)start_redo_ins();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7822 if (cmdchar == 'r' || cmdchar == 'v')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7823 stuffReadbuff(ESC_STR); /* no ESC in redo buffer */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7824 ++RedrawingDisabled;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7825 disabled_redraw = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7826 return FALSE; /* repeat the insert */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7827 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7828 stop_insert(&curwin->w_cursor, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7829 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7830 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7831
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7832 /* When an autoindent was removed, curswant stays after the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7833 * indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7834 if (restart_edit == NUL && (colnr_T)temp == curwin->w_cursor.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7835 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7836
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7837 /* Remember the last Insert position in the '^ mark. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7838 if (!cmdmod.keepjumps)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7839 curbuf->b_last_insert = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7840
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7841 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7842 * The cursor should end up on the last inserted character.
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
7843 * Don't do it for CTRL-O, unless past the end of the line.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7844 */
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
7845 if (!nomove
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
7846 && (curwin->w_cursor.col != 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7847 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7848 || curwin->w_cursor.coladd > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7849 #endif
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
7850 )
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
7851 && (restart_edit == NUL
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
7852 || (gchar_cursor() == NUL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7853 #ifdef FEAT_VISUAL
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
7854 && !VIsual_active
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
7855 #endif
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
7856 ))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7857 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7858 && !revins_on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7859 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7860 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7861 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7862 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7863 if (curwin->w_cursor.coladd > 0 || ve_flags == VE_ALL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7864 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7865 oneleft();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7866 if (restart_edit != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7867 ++curwin->w_cursor.coladd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7868 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7869 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7870 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7871 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7872 --curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7873 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7874 /* Correct cursor for multi-byte character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7875 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7876 mb_adjust_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7877 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7878 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7879 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7880
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7881 #ifdef USE_IM_CONTROL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7882 /* Disable IM to allow typing English directly for Normal mode commands.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7883 * When ":lmap" is enabled don't change 'iminsert' (IM can be enabled as
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7884 * well). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7885 if (!(State & LANGMAP))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7886 im_save_status(&curbuf->b_p_iminsert);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7887 im_set_active(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7888 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7889
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7890 State = NORMAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7891 /* need to position cursor again (e.g. when on a TAB ) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7892 changed_cline_bef_curs();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7893
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7894 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7895 setmouse();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7896 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7897 #ifdef CURSOR_SHAPE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7898 ui_cursor_shape(); /* may show different cursor shape */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7899 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7900
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7901 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7902 * When recording or for CTRL-O, need to display the new mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7903 * Otherwise remove the mode message.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7904 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7905 if (Recording || restart_edit != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7906 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7907 else if (p_smd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7908 MSG("");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7909
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7910 return TRUE; /* exit Insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7911 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7912
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7913 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7914 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7915 * Toggle language: hkmap and revins_on.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7916 * Move to end of reverse inserted text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7917 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7918 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7919 ins_ctrl_()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7920 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7921 if (revins_on && revins_chars && revins_scol >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7922 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7923 while (gchar_cursor() != NUL && revins_chars--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7924 ++curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7925 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7926 p_ri = !p_ri;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7927 revins_on = (State == INSERT && p_ri);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7928 if (revins_on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7929 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7930 revins_scol = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7931 revins_legal++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7932 revins_chars = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7933 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7934 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7935 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7936 revins_scol = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7937 #ifdef FEAT_FKMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7938 if (p_altkeymap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7939 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7940 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7941 * to be consistent also for redo command, using '.'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7942 * set arrow_used to true and stop it - causing to redo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7943 * characters entered in one mode (normal/reverse insert).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7944 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7945 arrow_used = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7946 (void)stop_arrow();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7947 p_fkmap = curwin->w_p_rl ^ p_ri;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7948 if (p_fkmap && p_ri)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7949 State = INSERT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7950 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7951 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7952 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7953 p_hkmap = curwin->w_p_rl ^ p_ri; /* be consistent! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7954 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7955 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7956 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7957
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7958 #ifdef FEAT_VISUAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7959 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7960 * If 'keymodel' contains "startsel", may start selection.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7961 * Returns TRUE when a CTRL-O and other keys stuffed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7962 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7963 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7964 ins_start_select(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7965 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7966 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7967 if (km_startsel)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7968 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7969 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7970 case K_KHOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7971 case K_KEND:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7972 case K_PAGEUP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7973 case K_KPAGEUP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7974 case K_PAGEDOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7975 case K_KPAGEDOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7976 # ifdef MACOS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7977 case K_LEFT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7978 case K_RIGHT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7979 case K_UP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7980 case K_DOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7981 case K_END:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7982 case K_HOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7983 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7984 if (!(mod_mask & MOD_MASK_SHIFT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7985 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7986 /* FALLTHROUGH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7987 case K_S_LEFT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7988 case K_S_RIGHT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7989 case K_S_UP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7990 case K_S_DOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7991 case K_S_END:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7992 case K_S_HOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7993 /* Start selection right away, the cursor can move with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7994 * CTRL-O when beyond the end of the line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7995 start_selection();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7996
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7997 /* Execute the key in (insert) Select mode. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7998 stuffcharReadbuff(Ctrl_O);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7999 if (mod_mask)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8000 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8001 char_u buf[4];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8002
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8003 buf[0] = K_SPECIAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8004 buf[1] = KS_MODIFIER;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8005 buf[2] = mod_mask;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8006 buf[3] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8007 stuffReadbuff(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8008 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8009 stuffcharReadbuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8010 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8011 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8012 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8013 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8014 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8015
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8016 /*
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8017 * <Insert> key in Insert mode: toggle insert/remplace mode.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8018 */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8019 static void
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8020 ins_insert(replaceState)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8021 int replaceState;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8022 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8023 #ifdef FEAT_FKMAP
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8024 if (p_fkmap && p_ri)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8025 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8026 beep_flush();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8027 EMSG(farsi_text_3); /* encoded in Farsi */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8028 return;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8029 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8030 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8031
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8032 #ifdef FEAT_AUTOCMD
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 523
diff changeset
8033 # ifdef FEAT_EVAL
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8034 set_vim_var_string(VV_INSERTMODE,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8035 (char_u *)((State & REPLACE_FLAG) ? "i" :
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
8036 # ifdef FEAT_VREPLACE
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
8037 replaceState == VREPLACE ? "v" :
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
8038 # endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
8039 "r"), 1);
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 523
diff changeset
8040 # endif
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8041 apply_autocmds(EVENT_INSERTCHANGE, NULL, NULL, FALSE, curbuf);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8042 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8043 if (State & REPLACE_FLAG)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8044 State = INSERT | (State & LANGMAP);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8045 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8046 State = replaceState | (State & LANGMAP);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8047 AppendCharToRedobuff(K_INS);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8048 showmode();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8049 #ifdef CURSOR_SHAPE
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8050 ui_cursor_shape(); /* may show different cursor shape */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8051 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8052 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8053
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8054 /*
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8055 * Pressed CTRL-O in Insert mode.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8056 */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8057 static void
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8058 ins_ctrl_o()
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8059 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8060 #ifdef FEAT_VREPLACE
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8061 if (State & VREPLACE_FLAG)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8062 restart_edit = 'V';
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8063 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8064 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8065 if (State & REPLACE_FLAG)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8066 restart_edit = 'R';
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8067 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8068 restart_edit = 'I';
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8069 #ifdef FEAT_VIRTUALEDIT
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8070 if (virtual_active())
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8071 ins_at_eol = FALSE; /* cursor always keeps its column */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8072 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8073 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8074 ins_at_eol = (gchar_cursor() == NUL);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8075 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8076
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8077 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8078 * If the cursor is on an indent, ^T/^D insert/delete one
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8079 * shiftwidth. Otherwise ^T/^D behave like a "<<" or ">>".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8080 * Always round the indent to 'shiftwith', this is compatible
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8081 * with vi. But vi only supports ^T and ^D after an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8082 * autoindent, we support it everywhere.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8083 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8084 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8085 ins_shift(c, lastc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8086 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8087 int lastc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8088 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8089 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8090 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8091 AppendCharToRedobuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8092
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8093 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8094 * 0^D and ^^D: remove all indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8095 */
1330
9fb5bb1ea79b updated for version 7.1-044
vimboss
parents: 1300
diff changeset
8096 if (c == Ctrl_D && (lastc == '0' || lastc == '^')
9fb5bb1ea79b updated for version 7.1-044
vimboss
parents: 1300
diff changeset
8097 && curwin->w_cursor.col > 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8098 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8099 --curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8100 (void)del_char(FALSE); /* delete the '^' or '0' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8101 /* In Replace mode, restore the characters that '^' or '0' replaced. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8102 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8103 replace_pop_ins();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8104 if (lastc == '^')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8105 old_indent = get_indent(); /* remember curr. indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8106 change_indent(INDENT_SET, 0, TRUE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8107 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8108 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8109 change_indent(c == Ctrl_D ? INDENT_DEC : INDENT_INC, 0, TRUE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8110
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8111 if (did_ai && *skipwhite(ml_get_curline()) != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8112 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8113 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8114 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8115 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8116 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8117 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8118 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8119 can_cindent = FALSE; /* no cindenting after ^D or ^T */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8120 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8121 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8122
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8123 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8124 ins_del()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8125 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8126 int temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8127
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8128 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8129 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8130 if (gchar_cursor() == NUL) /* delete newline */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8131 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8132 temp = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8133 if (!can_bs(BS_EOL) /* only if "eol" included */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8134 || u_save((linenr_T)(curwin->w_cursor.lnum - 1),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8135 (linenr_T)(curwin->w_cursor.lnum + 2)) == FAIL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8136 || do_join(FALSE) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8137 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8138 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8139 curwin->w_cursor.col = temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8140 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8141 else if (del_char(FALSE) == FAIL) /* delete char under cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8142 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8143 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8144 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8145 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8146 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8147 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8148 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8149 AppendCharToRedobuff(K_DEL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8150 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8151
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8152 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8153 * Handle Backspace, delete-word and delete-line in Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8154 * Return TRUE when backspace was actually used.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8155 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8156 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8157 ins_bs(c, mode, inserted_space_p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8158 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8159 int mode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8160 int *inserted_space_p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8161 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8162 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8163 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8164 int temp = 0; /* init for GCC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8165 colnr_T mincol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8166 int did_backspace = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8167 int in_indent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8168 int oldState;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8169 #ifdef FEAT_MBYTE
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 712
diff changeset
8170 int cpc[MAX_MCO]; /* composing characters */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8171 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8172
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8173 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8174 * can't delete anything in an empty file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8175 * can't backup past first character in buffer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8176 * can't backup past starting point unless 'backspace' > 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8177 * can backup to a previous line if 'backspace' == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8178 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8179 if ( bufempty()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8180 || (
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8181 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8182 !revins_on &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8183 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8184 ((curwin->w_cursor.lnum == 1 && curwin->w_cursor.col == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8185 || (!can_bs(BS_START)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8186 && (arrow_used
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8187 || (curwin->w_cursor.lnum == Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8188 && curwin->w_cursor.col <= Insstart.col)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8189 || (!can_bs(BS_INDENT) && !arrow_used && ai_col > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8190 && curwin->w_cursor.col <= ai_col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8191 || (!can_bs(BS_EOL) && curwin->w_cursor.col == 0))))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8192 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8193 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8194 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8195 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8196
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8197 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8198 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8199 in_indent = inindent(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8200 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8201 if (in_indent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8202 can_cindent = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8203 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8204 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8205 end_comment_pending = NUL; /* After BS, don't auto-end comment */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8206 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8207 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8208 if (revins_on) /* put cursor after last inserted char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8209 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8210 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8211
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8212 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8213 /* Virtualedit:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8214 * BACKSPACE_CHAR eats a virtual space
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8215 * BACKSPACE_WORD eats all coladd
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8216 * BACKSPACE_LINE eats all coladd and keeps going
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8217 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8218 if (curwin->w_cursor.coladd > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8219 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8220 if (mode == BACKSPACE_CHAR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8221 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8222 --curwin->w_cursor.coladd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8223 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8224 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8225 if (mode == BACKSPACE_WORD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8226 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8227 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8228 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8229 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8230 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8231 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8232 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8233
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8234 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8235 * delete newline!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8236 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8237 if (curwin->w_cursor.col == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8238 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8239 lnum = Insstart.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8240 if (curwin->w_cursor.lnum == Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8241 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8242 || revins_on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8243 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8244 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8245 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8246 if (u_save((linenr_T)(curwin->w_cursor.lnum - 2),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8247 (linenr_T)(curwin->w_cursor.lnum + 1)) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8248 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8249 --Insstart.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8250 Insstart.col = MAXCOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8251 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8252 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8253 * In replace mode:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8254 * cc < 0: NL was inserted, delete it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8255 * cc >= 0: NL was replaced, put original characters back
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8256 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8257 cc = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8258 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8259 cc = replace_pop(); /* returns -1 if NL was inserted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8260 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8261 * In replace mode, in the line we started replacing, we only move the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8262 * cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8263 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8264 if ((State & REPLACE_FLAG) && curwin->w_cursor.lnum <= lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8265 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8266 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8267 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8268 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8269 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8270 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8271 if (!(State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8272 || curwin->w_cursor.lnum > orig_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8273 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8274 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8275 temp = gchar_cursor(); /* remember current char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8276 --curwin->w_cursor.lnum;
278
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8277
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8278 /* When "aw" is in 'formatoptions' we must delete the space at
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8279 * the end of the line, otherwise the line will be broken
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8280 * again when auto-formatting. */
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8281 if (has_format_option(FO_AUTO)
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8282 && has_format_option(FO_WHITE_PAR))
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8283 {
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8284 char_u *ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum,
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8285 TRUE);
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8286 int len;
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8287
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 829
diff changeset
8288 len = (int)STRLEN(ptr);
278
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8289 if (len > 0 && ptr[len - 1] == ' ')
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8290 ptr[len - 1] = NUL;
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8291 }
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8292
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8293 (void)do_join(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8294 if (temp == NUL && gchar_cursor() != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8295 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8296 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8297 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8298 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8299 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8300 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8301
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8302 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8303 * In REPLACE mode we have to put back the text that was replaced
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8304 * by the NL. On the replace stack is first a NUL-terminated
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8305 * sequence of characters that were deleted and then the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8306 * characters that NL replaced.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8307 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8308 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8309 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8310 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8311 * Do the next ins_char() in NORMAL state, to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8312 * prevent ins_char() from replacing characters and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8313 * avoiding showmatch().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8314 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8315 oldState = State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8316 State = NORMAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8317 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8318 * restore characters (blanks) deleted after cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8319 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8320 while (cc > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8321 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8322 temp = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8323 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8324 mb_replace_pop_ins(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8325 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8326 ins_char(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8327 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8328 curwin->w_cursor.col = temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8329 cc = replace_pop();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8330 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8331 /* restore the characters that NL replaced */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8332 replace_pop_ins();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8333 State = oldState;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8334 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8335 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8336 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8337 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8338 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8339 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8340 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8341 * Delete character(s) before the cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8342 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8343 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8344 if (revins_on) /* put cursor on last inserted char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8345 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8346 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8347 mincol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8348 /* keep indent */
1085
f299f0bf32d7 updated for version 7.0-211
vimboss
parents: 1074
diff changeset
8349 if (mode == BACKSPACE_LINE
f299f0bf32d7 updated for version 7.0-211
vimboss
parents: 1074
diff changeset
8350 && (curbuf->b_p_ai
f299f0bf32d7 updated for version 7.0-211
vimboss
parents: 1074
diff changeset
8351 #ifdef FEAT_CINDENT
f299f0bf32d7 updated for version 7.0-211
vimboss
parents: 1074
diff changeset
8352 || cindent_on()
f299f0bf32d7 updated for version 7.0-211
vimboss
parents: 1074
diff changeset
8353 #endif
f299f0bf32d7 updated for version 7.0-211
vimboss
parents: 1074
diff changeset
8354 )
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8355 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8356 && !revins_on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8357 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8358 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8359 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8360 temp = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8361 beginline(BL_WHITE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8362 if (curwin->w_cursor.col < (colnr_T)temp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8363 mincol = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8364 curwin->w_cursor.col = temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8365 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8366
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8367 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8368 * Handle deleting one 'shiftwidth' or 'softtabstop'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8369 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8370 if ( mode == BACKSPACE_CHAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8371 && ((p_sta && in_indent)
648
9032e4668296 updated for version 7.0189
vimboss
parents: 644
diff changeset
8372 || (curbuf->b_p_sts != 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8373 && (*(ml_get_cursor() - 1) == TAB
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8374 || (*(ml_get_cursor() - 1) == ' '
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8375 && (!*inserted_space_p
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8376 || arrow_used))))))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8377 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8378 int ts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8379 colnr_T vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8380 colnr_T want_vcol;
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8381 #if 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8382 int extra = 0;
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8383 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8384
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8385 *inserted_space_p = FALSE;
648
9032e4668296 updated for version 7.0189
vimboss
parents: 644
diff changeset
8386 if (p_sta && in_indent)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8387 ts = curbuf->b_p_sw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8388 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8389 ts = curbuf->b_p_sts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8390 /* Compute the virtual column where we want to be. Since
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8391 * 'showbreak' may get in the way, need to get the last column of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8392 * the previous character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8393 getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8394 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8395 getvcol(curwin, &curwin->w_cursor, NULL, NULL, &want_vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8396 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8397 want_vcol = (want_vcol / ts) * ts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8398
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8399 /* delete characters until we are at or before want_vcol */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8400 while (vcol > want_vcol
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8401 && (cc = *(ml_get_cursor() - 1), vim_iswhite(cc)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8402 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8403 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8404 getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8405 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8406 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8407 /* Don't delete characters before the insert point when in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8408 * Replace mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8409 if (curwin->w_cursor.lnum != Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8410 || curwin->w_cursor.col >= Insstart.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8411 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8412 #if 0 /* what was this for? It causes problems when sw != ts. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8413 if (State == REPLACE && (int)vcol < want_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8414 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8415 (void)del_char(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8416 extra = 2; /* don't pop too much */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8417 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8418 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8419 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8420 replace_do_bs();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8421 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8422 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8423 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8424 (void)del_char(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8425 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8426
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8427 /* insert extra spaces until we are at want_vcol */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8428 while (vcol < want_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8429 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8430 /* Remember the first char we inserted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8431 if (curwin->w_cursor.lnum == Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8432 && curwin->w_cursor.col < Insstart.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8433 Insstart.col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8434
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8435 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8436 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8437 ins_char(' ');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8438 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8439 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8440 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8441 ins_str((char_u *)" ");
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8442 if ((State & REPLACE_FLAG) /* && extra <= 1 */)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8443 {
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8444 #if 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8445 if (extra)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8446 replace_push_off(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8447 else
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8448 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8449 replace_push(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8450 }
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8451 #if 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8452 if (extra == 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8453 extra = 1;
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8454 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8455 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8456 getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8457 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8458 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8459
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8460 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8461 * Delete upto starting point, start of line or previous word.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8462 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8463 else do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8464 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8465 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8466 if (!revins_on) /* put cursor on char to be deleted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8467 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8468 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8469
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8470 /* start of word? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8471 if (mode == BACKSPACE_WORD && !vim_isspace(gchar_cursor()))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8472 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8473 mode = BACKSPACE_WORD_NOT_SPACE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8474 temp = vim_iswordc(gchar_cursor());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8475 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8476 /* end of word? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8477 else if (mode == BACKSPACE_WORD_NOT_SPACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8478 && (vim_isspace(cc = gchar_cursor())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8479 || vim_iswordc(cc) != temp))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8480 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8481 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8482 if (!revins_on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8483 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8484 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8485 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8486 else if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8487 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8488 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8489 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8490 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8491 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8492 replace_do_bs();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8493 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8494 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8495 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8496 if (enc_utf8 && p_deco)
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 712
diff changeset
8497 (void)utfc_ptr2char(ml_get_cursor(), cpc);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8498 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8499 (void)del_char(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8500 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8501 /*
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 712
diff changeset
8502 * If there are combining characters and 'delcombine' is set
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 712
diff changeset
8503 * move the cursor back. Don't back up before the base
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8504 * character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8505 */
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 712
diff changeset
8506 if (enc_utf8 && p_deco && cpc[0] != NUL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8507 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8508 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8509 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8510 if (revins_chars)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8511 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8512 revins_chars--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8513 revins_legal++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8514 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8515 if (revins_on && gchar_cursor() == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8516 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8517 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8518 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8519 /* Just a single backspace?: */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8520 if (mode == BACKSPACE_CHAR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8521 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8522 } while (
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8523 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8524 revins_on ||
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8525 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8526 (curwin->w_cursor.col > mincol
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8527 && (curwin->w_cursor.lnum != Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8528 || curwin->w_cursor.col != Insstart.col)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8529 did_backspace = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8530 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8531 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8532 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8533 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8534 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8535 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8536 if (curwin->w_cursor.col <= 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8537 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8538 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8539 * It's a little strange to put backspaces into the redo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8540 * buffer, but it makes auto-indent a lot easier to deal
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8541 * with.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8542 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8543 AppendCharToRedobuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8544
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8545 /* If deleted before the insertion point, adjust it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8546 if (curwin->w_cursor.lnum == Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8547 && curwin->w_cursor.col < Insstart.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8548 Insstart.col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8549
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8550 /* vi behaviour: the cursor moves backward but the character that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8551 * was there remains visible
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8552 * Vim behaviour: the cursor moves backward and the character that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8553 * was there is erased from the screen.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8554 * We can emulate the vi behaviour by pretending there is a dollar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8555 * displayed even when there isn't.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8556 * --pkv Sun Jan 19 01:56:40 EST 2003 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8557 if (vim_strchr(p_cpo, CPO_BACKSPACE) != NULL && dollar_vcol == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8558 dollar_vcol = curwin->w_virtcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8559
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8560 return did_backspace;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8561 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8562
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8563 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8564 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8565 ins_mouse(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8566 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8567 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8568 pos_T tpos;
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8569 win_T *old_curwin = curwin;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8570
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8571 # ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8572 /* When GUI is active, also move/paste when 'mouse' is empty */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8573 if (!gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8574 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8575 if (!mouse_has(MOUSE_INSERT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8576 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8577
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8578 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8579 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8580 if (do_mouse(NULL, c, BACKWARD, 1L, 0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8581 {
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8582 #ifdef FEAT_WINDOWS
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8583 win_T *new_curwin = curwin;
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8584
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8585 if (curwin != old_curwin && win_valid(old_curwin))
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8586 {
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8587 /* Mouse took us to another window. We need to go back to the
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8588 * previous one to stop insert there properly. */
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8589 curwin = old_curwin;
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8590 curbuf = curwin->w_buffer;
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8591 }
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8592 #endif
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8593 start_arrow(curwin == old_curwin ? &tpos : NULL);
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8594 #ifdef FEAT_WINDOWS
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8595 if (curwin != new_curwin && win_valid(new_curwin))
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8596 {
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8597 curwin = new_curwin;
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8598 curbuf = curwin->w_buffer;
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8599 }
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8600 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8601 # ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8602 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8603 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8604 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8605
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8606 #ifdef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8607 /* redraw status lines (in case another window became active) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8608 redraw_statuslines();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8609 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8610 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8611
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8612 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8613 ins_mousescroll(up)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8614 int up;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8615 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8616 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8617 # if defined(FEAT_GUI) && defined(FEAT_WINDOWS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8618 win_T *old_curwin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8619 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8620
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8621 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8622
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8623 # if defined(FEAT_GUI) && defined(FEAT_WINDOWS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8624 old_curwin = curwin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8625
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8626 /* Currently the mouse coordinates are only known in the GUI. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8627 if (gui.in_use && mouse_row >= 0 && mouse_col >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8628 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8629 int row, col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8630
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8631 row = mouse_row;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8632 col = mouse_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8633
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8634 /* find the window at the pointer coordinates */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8635 curwin = mouse_find_win(&row, &col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8636 curbuf = curwin->w_buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8637 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8638 if (curwin == old_curwin)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8639 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8640 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8641
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8642 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8643 scroll_redraw(up, (long)(curwin->w_botline - curwin->w_topline));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8644 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8645 scroll_redraw(up, 3L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8646
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8647 # if defined(FEAT_GUI) && defined(FEAT_WINDOWS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8648 curwin->w_redr_status = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8649
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8650 curwin = old_curwin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8651 curbuf = curwin->w_buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8652 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8653
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8654 if (!equalpos(curwin->w_cursor, tpos))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8655 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8656 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8657 # ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8658 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8659 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8660 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8661 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8662 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8663
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8664 #if defined(FEAT_GUI_TABLINE) || defined(PROTO)
724
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
8665 static void
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8666 ins_tabline(c)
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8667 int c;
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8668 {
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8669 /* We will be leaving the current window, unless closing another tab. */
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8670 if (c != K_TABMENU || current_tabmenu != TABLINE_MENU_CLOSE
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8671 || (current_tab != 0 && current_tab != tabpage_index(curtab)))
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8672 {
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8673 undisplay_dollar();
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8674 start_arrow(&curwin->w_cursor);
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8675 # ifdef FEAT_CINDENT
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8676 can_cindent = TRUE;
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8677 # endif
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8678 }
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8679
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8680 if (c == K_TABLINE)
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8681 goto_tabpage(current_tab);
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8682 else
846
db44f7b81373 updated for version 7.0f03
vimboss
parents: 844
diff changeset
8683 {
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8684 handle_tabmenu();
846
db44f7b81373 updated for version 7.0f03
vimboss
parents: 844
diff changeset
8685 redraw_statuslines(); /* will redraw the tabline when needed */
db44f7b81373 updated for version 7.0f03
vimboss
parents: 844
diff changeset
8686 }
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8687 }
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8688 #endif
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8689
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8690 #if defined(FEAT_GUI) || defined(PROTO)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8691 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8692 ins_scroll()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8693 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8694 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8695
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8696 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8697 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8698 if (gui_do_scroll())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8699 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8700 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8701 # ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8702 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8703 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8704 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8705 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8706
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8707 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8708 ins_horscroll()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8709 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8710 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8711
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8712 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8713 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8714 if (gui_do_horiz_scroll())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8715 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8716 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8717 # ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8718 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8719 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8720 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8721 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8722 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8723
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8724 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8725 ins_left()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8726 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8727 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8728
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8729 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8730 if ((fdo_flags & FDO_HOR) && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8731 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8732 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8733 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8734 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8735 if (oneleft() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8736 {
941
d95676480093 updated for version 7.0-067
vimboss
parents: 938
diff changeset
8737 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
d95676480093 updated for version 7.0-067
vimboss
parents: 938
diff changeset
8738 /* Only call start_arrow() when not busy with preediting, it will
d95676480093 updated for version 7.0-067
vimboss
parents: 938
diff changeset
8739 * break undo. K_LEFT is inserted in im_correct_cursor(). */
d95676480093 updated for version 7.0-067
vimboss
parents: 938
diff changeset
8740 if (!im_is_preediting())
d95676480093 updated for version 7.0-067
vimboss
parents: 938
diff changeset
8741 #endif
d95676480093 updated for version 7.0-067
vimboss
parents: 938
diff changeset
8742 start_arrow(&tpos);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8743 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8744 /* If exit reversed string, position is fixed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8745 if (revins_scol != -1 && (int)curwin->w_cursor.col >= revins_scol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8746 revins_legal++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8747 revins_chars++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8748 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8749 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8750
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8751 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8752 * if 'whichwrap' set for cursor in insert mode may go to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8753 * previous line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8754 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8755 else if (vim_strchr(p_ww, '[') != NULL && curwin->w_cursor.lnum > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8756 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8757 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8758 --(curwin->w_cursor.lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8759 coladvance((colnr_T)MAXCOL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8760 curwin->w_set_curswant = TRUE; /* so we stay at the end */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8761 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8762 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8763 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8764 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8765
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8766 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8767 ins_home(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8768 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8769 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8770 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8771
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8772 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8773 if ((fdo_flags & FDO_HOR) && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8774 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8775 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8776 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8777 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8778 if (c == K_C_HOME)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8779 curwin->w_cursor.lnum = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8780 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8781 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8782 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8783 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8784 curwin->w_curswant = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8785 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8786 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8787
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8788 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8789 ins_end(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8790 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8791 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8792 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8793
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8794 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8795 if ((fdo_flags & FDO_HOR) && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8796 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8797 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8798 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8799 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8800 if (c == K_C_END)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8801 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8802 coladvance((colnr_T)MAXCOL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8803 curwin->w_curswant = MAXCOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8804
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8805 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8806 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8807
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8808 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8809 ins_s_left()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8810 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8811 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8812 if ((fdo_flags & FDO_HOR) && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8813 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8814 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8815 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8816 if (curwin->w_cursor.lnum > 1 || curwin->w_cursor.col > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8817 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8818 start_arrow(&curwin->w_cursor);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8819 (void)bck_word(1L, FALSE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8820 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8821 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8822 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8823 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8824 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8825
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8826 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8827 ins_right()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8828 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8829 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8830 if ((fdo_flags & FDO_HOR) && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8831 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8832 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8833 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8834 if (gchar_cursor() != NUL || virtual_active()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8835 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8836 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8837 start_arrow(&curwin->w_cursor);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8838 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8839 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8840 if (virtual_active())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8841 oneright();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8842 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8843 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8844 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8845 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8846 if (has_mbyte)
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 470
diff changeset
8847 curwin->w_cursor.col += (*mb_ptr2len)(ml_get_cursor());
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8848 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8849 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8850 ++curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8851 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8852
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8853 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8854 revins_legal++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8855 if (revins_chars)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8856 revins_chars--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8857 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8858 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8859 /* if 'whichwrap' set for cursor in insert mode, may move the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8860 * cursor to the next line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8861 else if (vim_strchr(p_ww, ']') != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8862 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8863 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8864 start_arrow(&curwin->w_cursor);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8865 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8866 ++curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8867 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8868 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8869 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8870 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8871 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8872
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8873 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8874 ins_s_right()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8875 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8876 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8877 if ((fdo_flags & FDO_HOR) && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8878 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8879 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8880 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8881 if (curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8882 || gchar_cursor() != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8883 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8884 start_arrow(&curwin->w_cursor);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8885 (void)fwd_word(1L, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8886 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8887 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8888 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8889 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8890 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8891
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8892 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8893 ins_up(startcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8894 int startcol; /* when TRUE move to Insstart.col */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8895 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8896 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8897 linenr_T old_topline = curwin->w_topline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8898 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8899 int old_topfill = curwin->w_topfill;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8900 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8901
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8902 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8903 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8904 if (cursor_up(1L, TRUE) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8905 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8906 if (startcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8907 coladvance(getvcol_nolist(&Insstart));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8908 if (old_topline != curwin->w_topline
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8909 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8910 || old_topfill != curwin->w_topfill
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8911 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8912 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8913 redraw_later(VALID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8914 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8915 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8916 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8917 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8918 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8919 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8920 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8921 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8922
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8923 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8924 ins_pageup()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8925 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8926 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8927
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8928 undisplay_dollar();
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
8929
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
8930 #ifdef FEAT_WINDOWS
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
8931 if (mod_mask & MOD_MASK_CTRL)
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
8932 {
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
8933 /* <C-PageUp>: tab page back */
1013
61e5d40135d0 updated for version 7.0-139
vimboss
parents: 1007
diff changeset
8934 if (first_tabpage->tp_next != NULL)
61e5d40135d0 updated for version 7.0-139
vimboss
parents: 1007
diff changeset
8935 {
61e5d40135d0 updated for version 7.0-139
vimboss
parents: 1007
diff changeset
8936 start_arrow(&curwin->w_cursor);
61e5d40135d0 updated for version 7.0-139
vimboss
parents: 1007
diff changeset
8937 goto_tabpage(-1);
61e5d40135d0 updated for version 7.0-139
vimboss
parents: 1007
diff changeset
8938 }
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
8939 return;
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
8940 }
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
8941 #endif
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
8942
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8943 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8944 if (onepage(BACKWARD, 1L) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8945 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8946 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8947 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8948 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8949 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8950 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8951 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8952 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8953 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8954
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8955 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8956 ins_down(startcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8957 int startcol; /* when TRUE move to Insstart.col */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8958 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8959 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8960 linenr_T old_topline = curwin->w_topline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8961 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8962 int old_topfill = curwin->w_topfill;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8963 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8964
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8965 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8966 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8967 if (cursor_down(1L, TRUE) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8968 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8969 if (startcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8970 coladvance(getvcol_nolist(&Insstart));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8971 if (old_topline != curwin->w_topline
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8972 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8973 || old_topfill != curwin->w_topfill
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8974 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8975 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8976 redraw_later(VALID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8977 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8978 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8979 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8980 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8981 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8982 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8983 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8984 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8985
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8986 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8987 ins_pagedown()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8988 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8989 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8990
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8991 undisplay_dollar();
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
8992
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
8993 #ifdef FEAT_WINDOWS
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
8994 if (mod_mask & MOD_MASK_CTRL)
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
8995 {
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
8996 /* <C-PageDown>: tab page forward */
1013
61e5d40135d0 updated for version 7.0-139
vimboss
parents: 1007
diff changeset
8997 if (first_tabpage->tp_next != NULL)
61e5d40135d0 updated for version 7.0-139
vimboss
parents: 1007
diff changeset
8998 {
61e5d40135d0 updated for version 7.0-139
vimboss
parents: 1007
diff changeset
8999 start_arrow(&curwin->w_cursor);
61e5d40135d0 updated for version 7.0-139
vimboss
parents: 1007
diff changeset
9000 goto_tabpage(0);
61e5d40135d0 updated for version 7.0-139
vimboss
parents: 1007
diff changeset
9001 }
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
9002 return;
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
9003 }
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
9004 #endif
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
9005
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9006 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9007 if (onepage(FORWARD, 1L) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9008 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9009 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9010 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9011 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9012 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9013 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9014 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9015 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9016 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9017
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9018 #ifdef FEAT_DND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9019 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9020 ins_drop()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9021 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9022 do_put('~', BACKWARD, 1L, PUT_CURSEND);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9023 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9024 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9025
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9026 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9027 * Handle TAB in Insert or Replace mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9028 * Return TRUE when the TAB needs to be inserted like a normal character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9029 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9030 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9031 ins_tab()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9032 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9033 int ind;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9034 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9035 int temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9036
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9037 if (Insstart_blank_vcol == MAXCOL && curwin->w_cursor.lnum == Insstart.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9038 Insstart_blank_vcol = get_nolist_virtcol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9039 if (echeck_abbr(TAB + ABBR_OFF))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9040 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9041
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9042 ind = inindent(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9043 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9044 if (ind)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9045 can_cindent = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9046 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9047
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9048 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9049 * When nothing special, insert TAB like a normal character
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9050 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9051 if (!curbuf->b_p_et
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9052 && !(p_sta && ind && curbuf->b_p_ts != curbuf->b_p_sw)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9053 && curbuf->b_p_sts == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9054 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9055
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9056 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9057 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9058
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9059 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9060 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9061 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9062 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9063 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9064 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9065 AppendToRedobuff((char_u *)"\t");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9066
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9067 if (p_sta && ind) /* insert tab in indent, use 'shiftwidth' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9068 temp = (int)curbuf->b_p_sw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9069 else if (curbuf->b_p_sts > 0) /* use 'softtabstop' when set */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9070 temp = (int)curbuf->b_p_sts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9071 else /* otherwise use 'tabstop' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9072 temp = (int)curbuf->b_p_ts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9073 temp -= get_nolist_virtcol() % temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9074
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9075 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9076 * Insert the first space with ins_char(). It will delete one char in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9077 * replace mode. Insert the rest with ins_str(); it will not delete any
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9078 * chars. For VREPLACE mode, we use ins_char() for all characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9079 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9080 ins_char(' ');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9081 while (--temp > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9082 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9083 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9084 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9085 ins_char(' ');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9086 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9087 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9088 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9089 ins_str((char_u *)" ");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9090 if (State & REPLACE_FLAG) /* no char replaced */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9091 replace_push(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9092 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9093 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9094
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9095 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9096 * When 'expandtab' not set: Replace spaces by TABs where possible.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9097 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9098 if (!curbuf->b_p_et && (curbuf->b_p_sts || (p_sta && ind)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9099 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9100 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9101 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9102 char_u *saved_line = NULL; /* init for GCC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9103 pos_T pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9104 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9105 pos_T fpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9106 pos_T *cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9107 colnr_T want_vcol, vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9108 int change_col = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9109 int save_list = curwin->w_p_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9110
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9111 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9112 * Get the current line. For VREPLACE mode, don't make real changes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9113 * yet, just work on a copy of the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9114 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9115 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9116 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9117 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9118 pos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9119 cursor = &pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9120 saved_line = vim_strsave(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9121 if (saved_line == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9122 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9123 ptr = saved_line + pos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9124 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9125 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9126 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9127 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9128 ptr = ml_get_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9129 cursor = &curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9130 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9131
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9132 /* When 'L' is not in 'cpoptions' a tab always takes up 'ts' spaces. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9133 if (vim_strchr(p_cpo, CPO_LISTWM) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9134 curwin->w_p_list = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9135
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9136 /* Find first white before the cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9137 fpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9138 while (fpos.col > 0 && vim_iswhite(ptr[-1]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9139 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9140 --fpos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9141 --ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9142 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9143
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9144 /* In Replace mode, don't change characters before the insert point. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9145 if ((State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9146 && fpos.lnum == Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9147 && fpos.col < Insstart.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9148 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9149 ptr += Insstart.col - fpos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9150 fpos.col = Insstart.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9151 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9152
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9153 /* compute virtual column numbers of first white and cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9154 getvcol(curwin, &fpos, &vcol, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9155 getvcol(curwin, cursor, &want_vcol, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9156
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9157 /* Use as many TABs as possible. Beware of 'showbreak' and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9158 * 'linebreak' adding extra virtual columns. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9159 while (vim_iswhite(*ptr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9160 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9161 i = lbr_chartabsize((char_u *)"\t", vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9162 if (vcol + i > want_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9163 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9164 if (*ptr != TAB)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9165 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9166 *ptr = TAB;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9167 if (change_col < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9168 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9169 change_col = fpos.col; /* Column of first change */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9170 /* May have to adjust Insstart */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9171 if (fpos.lnum == Insstart.lnum && fpos.col < Insstart.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9172 Insstart.col = fpos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9173 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9174 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9175 ++fpos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9176 ++ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9177 vcol += i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9178 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9179
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9180 if (change_col >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9181 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9182 int repl_off = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9183
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9184 /* Skip over the spaces we need. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9185 while (vcol < want_vcol && *ptr == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9186 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9187 vcol += lbr_chartabsize(ptr, vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9188 ++ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9189 ++repl_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9190 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9191 if (vcol > want_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9192 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9193 /* Must have a char with 'showbreak' just before it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9194 --ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9195 --repl_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9196 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9197 fpos.col += repl_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9198
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9199 /* Delete following spaces. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9200 i = cursor->col - fpos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9201 if (i > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9202 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9203 mch_memmove(ptr, ptr + i, STRLEN(ptr + i) + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9204 /* correct replace stack. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9205 if ((State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9206 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9207 && !(State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9208 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9209 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9210 for (temp = i; --temp >= 0; )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9211 replace_join(repl_off);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9212 }
33
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
9213 #ifdef FEAT_NETBEANS_INTG
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
9214 if (usingNetbeans)
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
9215 {
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
9216 netbeans_removed(curbuf, fpos.lnum, cursor->col,
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
9217 (long)(i + 1));
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
9218 netbeans_inserted(curbuf, fpos.lnum, cursor->col,
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
9219 (char_u *)"\t", 1);
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
9220 }
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
9221 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9222 cursor->col -= i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9223
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9224 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9225 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9226 * In VREPLACE mode, we haven't changed anything yet. Do it now by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9227 * backspacing over the changed spacing and then inserting the new
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9228 * spacing.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9229 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9230 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9231 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9232 /* Backspace from real cursor to change_col */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9233 backspace_until_column(change_col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9234
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9235 /* Insert each char in saved_line from changed_col to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9236 * ptr-cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9237 ins_bytes_len(saved_line + change_col,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9238 cursor->col - change_col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9239 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9240 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9241 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9242
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9243 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9244 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9245 vim_free(saved_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9246 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9247 curwin->w_p_list = save_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9248 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9249
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9250 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9251 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9252
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9253 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9254 * Handle CR or NL in insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9255 * Return TRUE when out of memory or can't undo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9256 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9257 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9258 ins_eol(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9259 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9260 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9261 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9262
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9263 if (echeck_abbr(c + ABBR_OFF))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9264 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9265 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9266 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9267 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9268
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9269 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9270 * Strange Vi behaviour: In Replace mode, typing a NL will not delete the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9271 * character under the cursor. Only push a NUL on the replace stack,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9272 * nothing to put back when the NL is deleted.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9273 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9274 if ((State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9275 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9276 && !(State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9277 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9278 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9279 replace_push(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9280
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9281 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9282 * In VREPLACE mode, a NL replaces the rest of the line, and starts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9283 * replacing the next line, so we push all of the characters left on the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9284 * line onto the replace stack. This is not done here though, it is done
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9285 * in open_line().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9286 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9287
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
9288 #ifdef FEAT_VIRTUALEDIT
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
9289 /* Put cursor on NUL if on the last char and coladd is 1 (happens after
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
9290 * CTRL-O). */
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
9291 if (virtual_active() && curwin->w_cursor.coladd > 0)
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
9292 coladvance(getviscol());
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
9293 #endif
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
9294
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9295 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9296 # ifdef FEAT_FKMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9297 if (p_altkeymap && p_fkmap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9298 fkmap(NL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9299 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9300 /* NL in reverse insert will always start in the end of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9301 * current line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9302 if (revins_on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9303 curwin->w_cursor.col += (colnr_T)STRLEN(ml_get_cursor());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9304 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9305
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9306 AppendToRedobuff(NL_STR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9307 i = open_line(FORWARD,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9308 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9309 has_format_option(FO_RET_COMS) ? OPENLINE_DO_COM :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9310 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9311 0, old_indent);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9312 old_indent = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9313 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9314 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9315 #endif
1032
e6aed39f1264 updated for version 7.0-158
vimboss
parents: 1013
diff changeset
9316 #ifdef FEAT_FOLDING
e6aed39f1264 updated for version 7.0-158
vimboss
parents: 1013
diff changeset
9317 /* When inserting a line the cursor line must never be in a closed fold. */
e6aed39f1264 updated for version 7.0-158
vimboss
parents: 1013
diff changeset
9318 foldOpenCursor();
e6aed39f1264 updated for version 7.0-158
vimboss
parents: 1013
diff changeset
9319 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9320
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9321 return (!i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9322 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9323
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9324 #ifdef FEAT_DIGRAPHS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9325 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9326 * Handle digraph in insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9327 * Returns character still to be inserted, or NUL when nothing remaining to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9328 * done.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9329 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9330 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9331 ins_digraph()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9332 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9333 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9334 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9335
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9336 pc_status = PC_STATUS_UNSET;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9337 if (redrawing() && !char_avail())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9338 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9339 /* may need to redraw when no more chars available now */
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
9340 ins_redraw(FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9341
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9342 edit_putchar('?', TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9343 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9344 add_to_showcmd_c(Ctrl_K);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9345 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9346 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9347
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9348 #ifdef USE_ON_FLY_SCROLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9349 dont_scroll = TRUE; /* disallow scrolling here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9350 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9351
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9352 /* don't map the digraph chars. This also prevents the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9353 * mode message to be deleted when ESC is hit */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9354 ++no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9355 ++allow_keys;
1389
bdcfe793d49f updated for version 7.1-104
vimboss
parents: 1353
diff changeset
9356 c = plain_vgetc();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9357 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9358 --allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9359 if (IS_SPECIAL(c) || mod_mask) /* special key */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9360 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9361 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9362 clear_showcmd();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9363 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9364 insert_special(c, TRUE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9365 return NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9366 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9367 if (c != ESC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9368 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9369 if (redrawing() && !char_avail())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9370 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9371 /* may need to redraw when no more chars available now */
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
9372 ins_redraw(FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9373
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9374 if (char2cells(c) == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9375 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9376 /* first remove the '?', otherwise it's restored when typing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9377 * an ESC next */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9378 edit_unputchar();
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
9379 ins_redraw(FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9380 edit_putchar(c, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9381 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9382 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9383 add_to_showcmd_c(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9384 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9385 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9386 ++no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9387 ++allow_keys;
1389
bdcfe793d49f updated for version 7.1-104
vimboss
parents: 1353
diff changeset
9388 cc = plain_vgetc();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9389 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9390 --allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9391 if (cc != ESC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9392 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9393 AppendToRedobuff((char_u *)CTRL_V_STR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9394 c = getdigraph(c, cc, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9395 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9396 clear_showcmd();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9397 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9398 return c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9399 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9400 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9401 edit_unputchar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9402 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9403 clear_showcmd();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9404 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9405 return NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9406 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9407 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9408
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9409 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9410 * Handle CTRL-E and CTRL-Y in Insert mode: copy char from other line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9411 * Returns the char to be inserted, or NUL if none found.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9412 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9413 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9414 ins_copychar(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9415 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9416 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9417 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9418 int temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9419 char_u *ptr, *prev_ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9420
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9421 if (lnum < 1 || lnum > curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9422 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9423 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9424 return NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9425 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9426
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9427 /* try to advance to the cursor column */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9428 temp = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9429 ptr = ml_get(lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9430 prev_ptr = ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9431 validate_virtcol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9432 while ((colnr_T)temp < curwin->w_virtcol && *ptr != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9433 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9434 prev_ptr = ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9435 temp += lbr_chartabsize_adv(&ptr, (colnr_T)temp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9436 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9437 if ((colnr_T)temp > curwin->w_virtcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9438 ptr = prev_ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9439
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9440 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9441 c = (*mb_ptr2char)(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9442 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9443 c = *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9444 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9445 if (c == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9446 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9447 return c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9448 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9449
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9450 /*
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9451 * CTRL-Y or CTRL-E typed in Insert mode.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9452 */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9453 static int
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9454 ins_ctrl_ey(tc)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9455 int tc;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9456 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9457 int c = tc;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9458
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9459 #ifdef FEAT_INS_EXPAND
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9460 if (ctrl_x_mode == CTRL_X_SCROLL)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9461 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9462 if (c == Ctrl_Y)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9463 scrolldown_clamp();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9464 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9465 scrollup_clamp();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9466 redraw_later(VALID);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9467 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9468 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9469 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9470 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9471 c = ins_copychar(curwin->w_cursor.lnum + (c == Ctrl_Y ? -1 : 1));
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9472 if (c != NUL)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9473 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9474 long tw_save;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9475
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9476 /* The character must be taken literally, insert like it
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9477 * was typed after a CTRL-V, and pretend 'textwidth'
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9478 * wasn't set. Digits, 'o' and 'x' are special after a
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9479 * CTRL-V, don't use it for these. */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9480 if (c < 256 && !isalnum(c))
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9481 AppendToRedobuff((char_u *)CTRL_V_STR); /* CTRL-V */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9482 tw_save = curbuf->b_p_tw;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9483 curbuf->b_p_tw = -1;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9484 insert_special(c, TRUE, FALSE);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9485 curbuf->b_p_tw = tw_save;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9486 #ifdef FEAT_RIGHTLEFT
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9487 revins_chars++;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9488 revins_legal++;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9489 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9490 c = Ctrl_V; /* pretend CTRL-V is last character */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9491 auto_format(FALSE, TRUE);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9492 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9493 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9494 return c;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9495 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9496
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9497 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9498 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9499 * Try to do some very smart auto-indenting.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9500 * Used when inserting a "normal" character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9501 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9502 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9503 ins_try_si(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9504 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9505 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9506 pos_T *pos, old_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9507 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9508 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9509 int temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9510
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9511 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9512 * do some very smart indenting when entering '{' or '}'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9513 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9514 if (((did_si || can_si_back) && c == '{') || (can_si && c == '}'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9515 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9516 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9517 * for '}' set indent equal to indent of line containing matching '{'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9518 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9519 if (c == '}' && (pos = findmatch(NULL, '{')) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9520 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9521 old_pos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9522 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9523 * If the matching '{' has a ')' immediately before it (ignoring
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9524 * white-space), then line up with the start of the line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9525 * containing the matching '(' if there is one. This handles the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9526 * case where an "if (..\n..) {" statement continues over multiple
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9527 * lines -- webb
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9528 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9529 ptr = ml_get(pos->lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9530 i = pos->col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9531 if (i > 0) /* skip blanks before '{' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9532 while (--i > 0 && vim_iswhite(ptr[i]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9533 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9534 curwin->w_cursor.lnum = pos->lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9535 curwin->w_cursor.col = i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9536 if (ptr[i] == ')' && (pos = findmatch(NULL, '(')) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9537 curwin->w_cursor = *pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9538 i = get_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9539 curwin->w_cursor = old_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9540 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9541 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9542 change_indent(INDENT_SET, i, FALSE, NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9543 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9544 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9545 (void)set_indent(i, SIN_CHANGED);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9546 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9547 else if (curwin->w_cursor.col > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9548 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9549 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9550 * when inserting '{' after "O" reduce indent, but not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9551 * more than indent of previous line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9552 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9553 temp = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9554 if (c == '{' && can_si_back && curwin->w_cursor.lnum > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9555 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9556 old_pos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9557 i = get_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9558 while (curwin->w_cursor.lnum > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9559 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9560 ptr = skipwhite(ml_get(--(curwin->w_cursor.lnum)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9561
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9562 /* ignore empty lines and lines starting with '#'. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9563 if (*ptr != '#' && *ptr != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9564 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9565 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9566 if (get_indent() >= i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9567 temp = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9568 curwin->w_cursor = old_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9569 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9570 if (temp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9571 shift_line(TRUE, FALSE, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9572 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9573 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9574
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9575 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9576 * set indent of '#' always to 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9577 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9578 if (curwin->w_cursor.col > 0 && can_si && c == '#')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9579 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9580 /* remember current indent for next line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9581 old_indent = get_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9582 (void)set_indent(0, SIN_CHANGED);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9583 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9584
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9585 /* Adjust ai_col, the char at this position can be deleted. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9586 if (ai_col > curwin->w_cursor.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9587 ai_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9588 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9589 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9590
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9591 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9592 * Get the value that w_virtcol would have when 'list' is off.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9593 * Unless 'cpo' contains the 'L' flag.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9594 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9595 static colnr_T
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9596 get_nolist_virtcol()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9597 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9598 if (curwin->w_p_list && vim_strchr(p_cpo, CPO_LISTWM) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9599 return getvcol_nolist(&curwin->w_cursor);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9600 validate_virtcol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9601 return curwin->w_virtcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9602 }