Mercurial > vim
annotate src/ops.c @ 7896:16e8b23d8fd8
Added tag v7.4.1244 for changeset bff95e0d8885e0b5050e1404998c9d1904ba5849
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 02 Feb 2016 21:00:07 +0100 |
parents | 2a8d6b2dd925 |
children | 7d1c42e3ce11 |
rev | line source |
---|---|
7 | 1 /* vi:set ts=8 sts=4 sw=4: |
2 * | |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * ops.c: implementation of various operators: op_shift, op_delete, op_tilde, | |
12 * op_change, op_yank, do_put, do_join | |
13 */ | |
14 | |
15 #include "vim.h" | |
16 | |
17 /* | |
18 * Number of registers. | |
19 * 0 = unnamed register, for normal yanks and puts | |
20 * 1..9 = registers '1' to '9', for deletes | |
21 * 10..35 = registers 'a' to 'z' | |
22 * 36 = delete register '-' | |
23 * 37 = Selection register '*'. Only if FEAT_CLIPBOARD defined | |
24 * 38 = Clipboard register '+'. Only if FEAT_CLIPBOARD and FEAT_X11 defined | |
25 */ | |
26 /* | |
27 * Symbolic names for some registers. | |
28 */ | |
29 #define DELETION_REGISTER 36 | |
30 #ifdef FEAT_CLIPBOARD | |
31 # define STAR_REGISTER 37 | |
32 # ifdef FEAT_X11 | |
33 # define PLUS_REGISTER 38 | |
34 # else | |
35 # define PLUS_REGISTER STAR_REGISTER /* there is only one */ | |
36 # endif | |
37 #endif | |
38 #ifdef FEAT_DND | |
39 # define TILDE_REGISTER (PLUS_REGISTER + 1) | |
40 #endif | |
41 | |
42 #ifdef FEAT_CLIPBOARD | |
43 # ifdef FEAT_DND | |
44 # define NUM_REGISTERS (TILDE_REGISTER + 1) | |
45 # else | |
46 # define NUM_REGISTERS (PLUS_REGISTER + 1) | |
47 # endif | |
48 #else | |
49 # define NUM_REGISTERS 37 | |
50 #endif | |
51 | |
52 /* | |
53 * Each yank register is an array of pointers to lines. | |
54 */ | |
55 static struct yankreg | |
56 { | |
57 char_u **y_array; /* pointer to array of line pointers */ | |
58 linenr_T y_size; /* number of lines in y_array */ | |
59 char_u y_type; /* MLINE, MCHAR or MBLOCK */ | |
60 colnr_T y_width; /* only set if y_type == MBLOCK */ | |
61 } y_regs[NUM_REGISTERS]; | |
62 | |
63 static struct yankreg *y_current; /* ptr to current yankreg */ | |
64 static int y_append; /* TRUE when appending */ | |
65 static struct yankreg *y_previous = NULL; /* ptr to last written yankreg */ | |
66 | |
67 /* | |
68 * structure used by block_prep, op_delete and op_yank for blockwise operators | |
69 * also op_change, op_shift, op_insert, op_replace - AKelly | |
70 */ | |
71 struct block_def | |
72 { | |
1839 | 73 int startspaces; /* 'extra' cols before first char */ |
74 int endspaces; /* 'extra' cols after last char */ | |
7 | 75 int textlen; /* chars in block */ |
1839 | 76 char_u *textstart; /* pointer to 1st char (partially) in block */ |
77 colnr_T textcol; /* index of chars (partially) in block */ | |
7 | 78 colnr_T start_vcol; /* start col of 1st char wholly inside block */ |
79 colnr_T end_vcol; /* start col of 1st char wholly after block */ | |
80 #ifdef FEAT_VISUALEXTRA | |
81 int is_short; /* TRUE if line is too short to fit in block */ | |
82 int is_MAX; /* TRUE if curswant==MAXCOL when starting */ | |
83 int is_oneChar; /* TRUE if block within one character */ | |
84 int pre_whitesp; /* screen cols of ws before block */ | |
85 int pre_whitesp_c; /* chars of ws before block */ | |
86 colnr_T end_char_vcols; /* number of vcols of post-block char */ | |
87 #endif | |
88 colnr_T start_char_vcols; /* number of vcols of pre-block char */ | |
89 }; | |
90 | |
91 #ifdef FEAT_VISUALEXTRA | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
92 static void shift_block(oparg_T *oap, int amount); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
93 static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def*bdp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
94 #endif |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
95 static int stuff_yank(int, char_u *); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
96 static void put_reedit_in_typebuf(int silent); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
97 static int put_in_typebuf(char_u *s, int esc, int colon, |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
98 int silent); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
99 static void stuffescaped(char_u *arg, int literally); |
7 | 100 #ifdef FEAT_MBYTE |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
101 static void mb_adjust_opend(oparg_T *oap); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
102 #endif |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
103 static void free_yank(long); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
104 static void free_yank_all(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
105 static int yank_copy_line(struct block_def *bd, long y_idx); |
7 | 106 #ifdef FEAT_CLIPBOARD |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
107 static void copy_yank_reg(struct yankreg *reg); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
108 static void may_set_selection(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
109 #endif |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
110 static void dis_msg(char_u *p, int skip_esc); |
3562 | 111 #if defined(FEAT_COMMENTS) || defined(PROTO) |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
112 static char_u *skip_comment(char_u *line, int process, int include_space, int *is_comment); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
113 #endif |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
114 static void block_prep(oparg_T *oap, struct block_def *, linenr_T, int); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
115 static int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1); |
7 | 116 #if defined(FEAT_CLIPBOARD) || defined(FEAT_EVAL) |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
117 static void str_to_reg(struct yankreg *y_ptr, int yank_type, char_u *str, long len, long blocklen, int str_list); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
118 #endif |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
119 static int ends_in_white(linenr_T lnum); |
7 | 120 #ifdef FEAT_COMMENTS |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
121 static int same_leader(linenr_T lnum, int, char_u *, int, char_u *); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
122 static int fmt_check_par(linenr_T, int *, char_u **, int do_comments); |
7 | 123 #else |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
124 static int fmt_check_par(linenr_T); |
7 | 125 #endif |
126 | |
127 /* | |
128 * The names of operators. | |
129 * IMPORTANT: Index must correspond with defines in vim.h!!! | |
130 * The third field indicates whether the operator always works on lines. | |
131 */ | |
132 static char opchars[][3] = | |
133 { | |
134 {NUL, NUL, FALSE}, /* OP_NOP */ | |
135 {'d', NUL, FALSE}, /* OP_DELETE */ | |
136 {'y', NUL, FALSE}, /* OP_YANK */ | |
137 {'c', NUL, FALSE}, /* OP_CHANGE */ | |
138 {'<', NUL, TRUE}, /* OP_LSHIFT */ | |
139 {'>', NUL, TRUE}, /* OP_RSHIFT */ | |
140 {'!', NUL, TRUE}, /* OP_FILTER */ | |
141 {'g', '~', FALSE}, /* OP_TILDE */ | |
142 {'=', NUL, TRUE}, /* OP_INDENT */ | |
143 {'g', 'q', TRUE}, /* OP_FORMAT */ | |
144 {':', NUL, TRUE}, /* OP_COLON */ | |
145 {'g', 'U', FALSE}, /* OP_UPPER */ | |
146 {'g', 'u', FALSE}, /* OP_LOWER */ | |
147 {'J', NUL, TRUE}, /* DO_JOIN */ | |
148 {'g', 'J', TRUE}, /* DO_JOIN_NS */ | |
149 {'g', '?', FALSE}, /* OP_ROT13 */ | |
150 {'r', NUL, FALSE}, /* OP_REPLACE */ | |
151 {'I', NUL, FALSE}, /* OP_INSERT */ | |
152 {'A', NUL, FALSE}, /* OP_APPEND */ | |
153 {'z', 'f', TRUE}, /* OP_FOLD */ | |
154 {'z', 'o', TRUE}, /* OP_FOLDOPEN */ | |
155 {'z', 'O', TRUE}, /* OP_FOLDOPENREC */ | |
156 {'z', 'c', TRUE}, /* OP_FOLDCLOSE */ | |
157 {'z', 'C', TRUE}, /* OP_FOLDCLOSEREC */ | |
158 {'z', 'd', TRUE}, /* OP_FOLDDEL */ | |
159 {'z', 'D', TRUE}, /* OP_FOLDDELREC */ | |
160 {'g', 'w', TRUE}, /* OP_FORMAT2 */ | |
603 | 161 {'g', '@', FALSE}, /* OP_FUNCTION */ |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
162 {Ctrl_A, NUL, FALSE}, /* OP_NR_ADD */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
163 {Ctrl_X, NUL, FALSE}, /* OP_NR_SUB */ |
7 | 164 }; |
165 | |
166 /* | |
167 * Translate a command name into an operator type. | |
168 * Must only be called with a valid operator name! | |
169 */ | |
170 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
171 get_op_type(int char1, int char2) |
7 | 172 { |
173 int i; | |
174 | |
175 if (char1 == 'r') /* ignore second character */ | |
176 return OP_REPLACE; | |
177 if (char1 == '~') /* when tilde is an operator */ | |
178 return OP_TILDE; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
179 if (char1 == 'g' && char2 == Ctrl_A) /* add */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
180 return OP_NR_ADD; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
181 if (char1 == 'g' && char2 == Ctrl_X) /* subtract */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
182 return OP_NR_SUB; |
7 | 183 for (i = 0; ; ++i) |
184 if (opchars[i][0] == char1 && opchars[i][1] == char2) | |
185 break; | |
186 return i; | |
187 } | |
188 | |
189 /* | |
190 * Return TRUE if operator "op" always works on whole lines. | |
191 */ | |
192 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
193 op_on_lines(int op) |
7 | 194 { |
195 return opchars[op][2]; | |
196 } | |
197 | |
198 /* | |
199 * Get first operator command character. | |
200 * Returns 'g' or 'z' if there is another command character. | |
201 */ | |
202 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
203 get_op_char(int optype) |
7 | 204 { |
205 return opchars[optype][0]; | |
206 } | |
207 | |
208 /* | |
209 * Get second operator command character. | |
210 */ | |
211 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
212 get_extra_op_char(int optype) |
7 | 213 { |
214 return opchars[optype][1]; | |
215 } | |
216 | |
217 /* | |
218 * op_shift - handle a shift operation | |
219 */ | |
220 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
221 op_shift(oparg_T *oap, int curs_top, int amount) |
7 | 222 { |
223 long i; | |
224 int first_char; | |
225 char_u *s; | |
226 int block_col = 0; | |
227 | |
228 if (u_save((linenr_T)(oap->start.lnum - 1), | |
229 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
230 return; | |
231 | |
232 if (oap->block_mode) | |
233 block_col = curwin->w_cursor.col; | |
234 | |
235 for (i = oap->line_count; --i >= 0; ) | |
236 { | |
237 first_char = *ml_get_curline(); | |
238 if (first_char == NUL) /* empty line */ | |
239 curwin->w_cursor.col = 0; | |
240 #ifdef FEAT_VISUALEXTRA | |
241 else if (oap->block_mode) | |
242 shift_block(oap, amount); | |
243 #endif | |
244 else | |
245 /* Move the line right if it doesn't start with '#', 'smartindent' | |
246 * isn't set or 'cindent' isn't set or '#' isn't in 'cino'. */ | |
247 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) | |
248 if (first_char != '#' || !preprocs_left()) | |
249 #endif | |
250 { | |
1516 | 251 shift_line(oap->op_type == OP_LSHIFT, p_sr, amount, FALSE); |
7 | 252 } |
253 ++curwin->w_cursor.lnum; | |
254 } | |
255 | |
256 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); | |
5182
4cbff53717d4
updated for version 7.4a.017
Bram Moolenaar <bram@vim.org>
parents:
5100
diff
changeset
|
257 #ifdef FEAT_FOLDING |
4cbff53717d4
updated for version 7.4a.017
Bram Moolenaar <bram@vim.org>
parents:
5100
diff
changeset
|
258 /* The cursor line is not in a closed fold */ |
4cbff53717d4
updated for version 7.4a.017
Bram Moolenaar <bram@vim.org>
parents:
5100
diff
changeset
|
259 foldOpenCursor(); |
4cbff53717d4
updated for version 7.4a.017
Bram Moolenaar <bram@vim.org>
parents:
5100
diff
changeset
|
260 #endif |
7 | 261 |
262 if (oap->block_mode) | |
263 { | |
264 curwin->w_cursor.lnum = oap->start.lnum; | |
265 curwin->w_cursor.col = block_col; | |
266 } | |
5735 | 267 else if (curs_top) /* put cursor on first line, for ">>" */ |
7 | 268 { |
269 curwin->w_cursor.lnum = oap->start.lnum; | |
270 beginline(BL_SOL | BL_FIX); /* shift_line() may have set cursor.col */ | |
271 } | |
272 else | |
273 --curwin->w_cursor.lnum; /* put cursor on last line, for ":>" */ | |
274 | |
275 if (oap->line_count > p_report) | |
276 { | |
277 if (oap->op_type == OP_RSHIFT) | |
278 s = (char_u *)">"; | |
279 else | |
280 s = (char_u *)"<"; | |
281 if (oap->line_count == 1) | |
282 { | |
283 if (amount == 1) | |
284 sprintf((char *)IObuff, _("1 line %sed 1 time"), s); | |
285 else | |
286 sprintf((char *)IObuff, _("1 line %sed %d times"), s, amount); | |
287 } | |
288 else | |
289 { | |
290 if (amount == 1) | |
291 sprintf((char *)IObuff, _("%ld lines %sed 1 time"), | |
292 oap->line_count, s); | |
293 else | |
294 sprintf((char *)IObuff, _("%ld lines %sed %d times"), | |
295 oap->line_count, s, amount); | |
296 } | |
297 msg(IObuff); | |
298 } | |
299 | |
300 /* | |
301 * Set "'[" and "']" marks. | |
302 */ | |
303 curbuf->b_op_start = oap->start; | |
304 curbuf->b_op_end.lnum = oap->end.lnum; | |
305 curbuf->b_op_end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
306 if (curbuf->b_op_end.col > 0) | |
307 --curbuf->b_op_end.col; | |
308 } | |
309 | |
310 /* | |
311 * shift the current line one shiftwidth left (if left != 0) or right | |
312 * leaves cursor on first blank in the line | |
313 */ | |
314 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
315 shift_line( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
316 int left, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
317 int round, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
318 int amount, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
319 int call_changed_bytes) /* call changed_bytes() */ |
7 | 320 { |
321 int count; | |
322 int i, j; | |
5438 | 323 int p_sw = (int)get_sw_value(curbuf); |
7 | 324 |
325 count = get_indent(); /* get current indent */ | |
326 | |
327 if (round) /* round off indent */ | |
328 { | |
329 i = count / p_sw; /* number of p_sw rounded down */ | |
330 j = count % p_sw; /* extra spaces */ | |
331 if (j && left) /* first remove extra spaces */ | |
332 --amount; | |
333 if (left) | |
334 { | |
335 i -= amount; | |
336 if (i < 0) | |
337 i = 0; | |
338 } | |
339 else | |
340 i += amount; | |
341 count = i * p_sw; | |
342 } | |
343 else /* original vi indent */ | |
344 { | |
345 if (left) | |
346 { | |
347 count -= p_sw * amount; | |
348 if (count < 0) | |
349 count = 0; | |
350 } | |
351 else | |
352 count += p_sw * amount; | |
353 } | |
354 | |
355 /* Set new indent */ | |
356 #ifdef FEAT_VREPLACE | |
357 if (State & VREPLACE_FLAG) | |
1516 | 358 change_indent(INDENT_SET, count, FALSE, NUL, call_changed_bytes); |
7 | 359 else |
360 #endif | |
1516 | 361 (void)set_indent(count, call_changed_bytes ? SIN_CHANGED : 0); |
7 | 362 } |
363 | |
364 #if defined(FEAT_VISUALEXTRA) || defined(PROTO) | |
365 /* | |
366 * Shift one line of the current block one shiftwidth right or left. | |
367 * Leaves cursor on first character in block. | |
368 */ | |
369 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
370 shift_block(oparg_T *oap, int amount) |
7 | 371 { |
372 int left = (oap->op_type == OP_LSHIFT); | |
373 int oldstate = State; | |
1839 | 374 int total; |
375 char_u *newp, *oldp; | |
7 | 376 int oldcol = curwin->w_cursor.col; |
5438 | 377 int p_sw = (int)get_sw_value(curbuf); |
7 | 378 int p_ts = (int)curbuf->b_p_ts; |
379 struct block_def bd; | |
380 int incr; | |
1839 | 381 colnr_T ws_vcol; |
7 | 382 int i = 0, j = 0; |
383 int len; | |
384 #ifdef FEAT_RIGHTLEFT | |
385 int old_p_ri = p_ri; | |
386 | |
4352 | 387 p_ri = 0; /* don't want revins in indent */ |
7 | 388 #endif |
389 | |
390 State = INSERT; /* don't want REPLACE for State */ | |
391 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); | |
392 if (bd.is_short) | |
393 return; | |
394 | |
395 /* total is number of screen columns to be inserted/removed */ | |
396 total = amount * p_sw; | |
397 oldp = ml_get_curline(); | |
398 | |
399 if (!left) | |
400 { | |
401 /* | |
402 * 1. Get start vcol | |
403 * 2. Total ws vcols | |
404 * 3. Divvy into TABs & spp | |
405 * 4. Construct new string | |
406 */ | |
407 total += bd.pre_whitesp; /* all virtual WS upto & incl a split TAB */ | |
408 ws_vcol = bd.start_vcol - bd.pre_whitesp; | |
409 if (bd.startspaces) | |
410 { | |
411 #ifdef FEAT_MBYTE | |
412 if (has_mbyte) | |
474 | 413 bd.textstart += (*mb_ptr2len)(bd.textstart); |
1995 | 414 else |
415 #endif | |
416 ++bd.textstart; | |
7 | 417 } |
418 for ( ; vim_iswhite(*bd.textstart); ) | |
419 { | |
5995 | 420 /* TODO: is passing bd.textstart for start of the line OK? */ |
421 incr = lbr_chartabsize_adv(bd.textstart, &bd.textstart, | |
422 (colnr_T)(bd.start_vcol)); | |
7 | 423 total += incr; |
424 bd.start_vcol += incr; | |
425 } | |
426 /* OK, now total=all the VWS reqd, and textstart points at the 1st | |
427 * non-ws char in the block. */ | |
428 if (!curbuf->b_p_et) | |
429 i = ((ws_vcol % p_ts) + total) / p_ts; /* number of tabs */ | |
430 if (i) | |
431 j = ((ws_vcol % p_ts) + total) % p_ts; /* number of spp */ | |
432 else | |
433 j = total; | |
434 /* if we're splitting a TAB, allow for it */ | |
435 bd.textcol -= bd.pre_whitesp_c - (bd.startspaces != 0); | |
436 len = (int)STRLEN(bd.textstart) + 1; | |
437 newp = alloc_check((unsigned)(bd.textcol + i + j + len)); | |
438 if (newp == NULL) | |
439 return; | |
440 vim_memset(newp, NUL, (size_t)(bd.textcol + i + j + len)); | |
441 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
6929 | 442 vim_memset(newp + bd.textcol, TAB, (size_t)i); |
443 vim_memset(newp + bd.textcol + i, ' ', (size_t)j); | |
7 | 444 /* the end */ |
445 mch_memmove(newp + bd.textcol + i + j, bd.textstart, (size_t)len); | |
446 } | |
447 else /* left */ | |
448 { | |
1839 | 449 colnr_T destination_col; /* column to which text in block will |
450 be shifted */ | |
451 char_u *verbatim_copy_end; /* end of the part of the line which is | |
452 copied verbatim */ | |
453 colnr_T verbatim_copy_width;/* the (displayed) width of this part | |
454 of line */ | |
455 unsigned fill; /* nr of spaces that replace a TAB */ | |
456 unsigned new_line_len; /* the length of the line after the | |
457 block shift */ | |
458 size_t block_space_width; | |
459 size_t shift_amount; | |
460 char_u *non_white = bd.textstart; | |
461 colnr_T non_white_col; | |
462 | |
463 /* | |
464 * Firstly, let's find the first non-whitespace character that is | |
465 * displayed after the block's start column and the character's column | |
466 * number. Also, let's calculate the width of all the whitespace | |
467 * characters that are displayed in the block and precede the searched | |
468 * non-whitespace character. | |
469 */ | |
470 | |
471 /* If "bd.startspaces" is set, "bd.textstart" points to the character, | |
472 * the part of which is displayed at the block's beginning. Let's start | |
473 * searching from the next character. */ | |
474 if (bd.startspaces) | |
475 mb_ptr_adv(non_white); | |
476 | |
477 /* The character's column is in "bd.start_vcol". */ | |
478 non_white_col = bd.start_vcol; | |
479 | |
480 while (vim_iswhite(*non_white)) | |
7 | 481 { |
5995 | 482 incr = lbr_chartabsize_adv(bd.textstart, &non_white, non_white_col); |
1839 | 483 non_white_col += incr; |
7 | 484 } |
1839 | 485 |
486 block_space_width = non_white_col - oap->start_vcol; | |
487 /* We will shift by "total" or "block_space_width", whichever is less. | |
488 */ | |
1860 | 489 shift_amount = (block_space_width < (size_t)total |
490 ? block_space_width : (size_t)total); | |
1839 | 491 |
492 /* The column to which we will shift the text. */ | |
1860 | 493 destination_col = (colnr_T)(non_white_col - shift_amount); |
1839 | 494 |
495 /* Now let's find out how much of the beginning of the line we can | |
496 * reuse without modification. */ | |
497 verbatim_copy_end = bd.textstart; | |
498 verbatim_copy_width = bd.start_vcol; | |
499 | |
500 /* If "bd.startspaces" is set, "bd.textstart" points to the character | |
501 * preceding the block. We have to subtract its width to obtain its | |
502 * column number. */ | |
503 if (bd.startspaces) | |
504 verbatim_copy_width -= bd.start_char_vcols; | |
505 while (verbatim_copy_width < destination_col) | |
7 | 506 { |
5995 | 507 char_u *line = verbatim_copy_end; |
508 | |
509 /* TODO: is passing verbatim_copy_end for start of the line OK? */ | |
510 incr = lbr_chartabsize(line, verbatim_copy_end, | |
511 verbatim_copy_width); | |
1839 | 512 if (verbatim_copy_width + incr > destination_col) |
513 break; | |
514 verbatim_copy_width += incr; | |
515 mb_ptr_adv(verbatim_copy_end); | |
7 | 516 } |
517 | |
1839 | 518 /* If "destination_col" is different from the width of the initial |
519 * part of the line that will be copied, it means we encountered a tab | |
520 * character, which we will have to partly replace with spaces. */ | |
521 fill = destination_col - verbatim_copy_width; | |
522 | |
523 /* The replacement line will consist of: | |
524 * - the beginning of the original line up to "verbatim_copy_end", | |
525 * - "fill" number of spaces, | |
526 * - the rest of the line, pointed to by non_white. */ | |
527 new_line_len = (unsigned)(verbatim_copy_end - oldp) | |
528 + fill | |
529 + (unsigned)STRLEN(non_white) + 1; | |
530 | |
531 newp = alloc_check(new_line_len); | |
7 | 532 if (newp == NULL) |
533 return; | |
1839 | 534 mch_memmove(newp, oldp, (size_t)(verbatim_copy_end - oldp)); |
6929 | 535 vim_memset(newp + (verbatim_copy_end - oldp), ' ', (size_t)fill); |
1839 | 536 STRMOVE(newp + (verbatim_copy_end - oldp) + fill, non_white); |
7 | 537 } |
538 /* replace the line */ | |
539 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
540 changed_bytes(curwin->w_cursor.lnum, (colnr_T)bd.textcol); | |
541 State = oldstate; | |
542 curwin->w_cursor.col = oldcol; | |
543 #ifdef FEAT_RIGHTLEFT | |
544 p_ri = old_p_ri; | |
545 #endif | |
546 } | |
547 #endif | |
548 | |
549 #ifdef FEAT_VISUALEXTRA | |
550 /* | |
551 * Insert string "s" (b_insert ? before : after) block :AKelly | |
552 * Caller must prepare for undo. | |
553 */ | |
554 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
555 block_insert( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
556 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
557 char_u *s, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
558 int b_insert, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
559 struct block_def *bdp) |
7 | 560 { |
561 int p_ts; | |
562 int count = 0; /* extra spaces to replace a cut TAB */ | |
563 int spaces = 0; /* non-zero if cutting a TAB */ | |
564 colnr_T offset; /* pointer along new line */ | |
565 unsigned s_len; /* STRLEN(s) */ | |
566 char_u *newp, *oldp; /* new, old lines */ | |
567 linenr_T lnum; /* loop var */ | |
568 int oldstate = State; | |
569 | |
570 State = INSERT; /* don't want REPLACE for State */ | |
571 s_len = (unsigned)STRLEN(s); | |
572 | |
573 for (lnum = oap->start.lnum + 1; lnum <= oap->end.lnum; lnum++) | |
574 { | |
575 block_prep(oap, bdp, lnum, TRUE); | |
576 if (bdp->is_short && b_insert) | |
577 continue; /* OP_INSERT, line ends before block start */ | |
578 | |
579 oldp = ml_get(lnum); | |
580 | |
581 if (b_insert) | |
582 { | |
583 p_ts = bdp->start_char_vcols; | |
584 spaces = bdp->startspaces; | |
585 if (spaces != 0) | |
586 count = p_ts - 1; /* we're cutting a TAB */ | |
587 offset = bdp->textcol; | |
588 } | |
589 else /* append */ | |
590 { | |
591 p_ts = bdp->end_char_vcols; | |
592 if (!bdp->is_short) /* spaces = padding after block */ | |
593 { | |
594 spaces = (bdp->endspaces ? p_ts - bdp->endspaces : 0); | |
595 if (spaces != 0) | |
596 count = p_ts - 1; /* we're cutting a TAB */ | |
597 offset = bdp->textcol + bdp->textlen - (spaces != 0); | |
598 } | |
599 else /* spaces = padding to block edge */ | |
600 { | |
601 /* if $ used, just append to EOL (ie spaces==0) */ | |
602 if (!bdp->is_MAX) | |
603 spaces = (oap->end_vcol - bdp->end_vcol) + 1; | |
604 count = spaces; | |
605 offset = bdp->textcol + bdp->textlen; | |
606 } | |
607 } | |
608 | |
6140 | 609 #ifdef FEAT_MBYTE |
610 if (has_mbyte && spaces > 0) | |
611 { | |
6460 | 612 int off; |
613 | |
6140 | 614 /* Avoid starting halfway a multi-byte character. */ |
615 if (b_insert) | |
616 { | |
6460 | 617 off = (*mb_head_off)(oldp, oldp + offset + spaces); |
6140 | 618 } |
619 else | |
620 { | |
6460 | 621 off = (*mb_off_next)(oldp, oldp + offset); |
6140 | 622 offset += off; |
623 } | |
6460 | 624 spaces -= off; |
625 count -= off; | |
6140 | 626 } |
627 #endif | |
628 | |
7 | 629 newp = alloc_check((unsigned)(STRLEN(oldp)) + s_len + count + 1); |
630 if (newp == NULL) | |
631 continue; | |
632 | |
633 /* copy up to shifted part */ | |
634 mch_memmove(newp, oldp, (size_t)(offset)); | |
635 oldp += offset; | |
636 | |
637 /* insert pre-padding */ | |
6929 | 638 vim_memset(newp + offset, ' ', (size_t)spaces); |
7 | 639 |
640 /* copy the new text */ | |
641 mch_memmove(newp + offset + spaces, s, (size_t)s_len); | |
642 offset += s_len; | |
643 | |
644 if (spaces && !bdp->is_short) | |
645 { | |
646 /* insert post-padding */ | |
6929 | 647 vim_memset(newp + offset + spaces, ' ', (size_t)(p_ts - spaces)); |
7 | 648 /* We're splitting a TAB, don't copy it. */ |
649 oldp++; | |
650 /* We allowed for that TAB, remember this now */ | |
651 count++; | |
652 } | |
653 | |
654 if (spaces > 0) | |
655 offset += count; | |
1622 | 656 STRMOVE(newp + offset, oldp); |
7 | 657 |
658 ml_replace(lnum, newp, FALSE); | |
659 | |
660 if (lnum == oap->end.lnum) | |
661 { | |
662 /* Set "']" mark to the end of the block instead of the end of | |
663 * the insert in the first line. */ | |
664 curbuf->b_op_end.lnum = oap->end.lnum; | |
665 curbuf->b_op_end.col = offset; | |
666 } | |
667 } /* for all lnum */ | |
668 | |
669 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); | |
670 | |
671 State = oldstate; | |
672 } | |
673 #endif | |
674 | |
675 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) || defined(PROTO) | |
676 /* | |
677 * op_reindent - handle reindenting a block of lines. | |
678 */ | |
679 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
680 op_reindent(oparg_T *oap, int (*how)(void)) |
7 | 681 { |
682 long i; | |
683 char_u *l; | |
6971 | 684 int amount; |
7 | 685 linenr_T first_changed = 0; |
686 linenr_T last_changed = 0; | |
687 linenr_T start_lnum = curwin->w_cursor.lnum; | |
688 | |
216 | 689 /* Don't even try when 'modifiable' is off. */ |
690 if (!curbuf->b_p_ma) | |
691 { | |
692 EMSG(_(e_modifiable)); | |
693 return; | |
694 } | |
695 | |
7 | 696 for (i = oap->line_count; --i >= 0 && !got_int; ) |
697 { | |
698 /* it's a slow thing to do, so give feedback so there's no worry that | |
699 * the computer's just hung. */ | |
700 | |
701 if (i > 1 | |
702 && (i % 50 == 0 || i == oap->line_count - 1) | |
703 && oap->line_count > p_report) | |
704 smsg((char_u *)_("%ld lines to indent... "), i); | |
705 | |
706 /* | |
707 * Be vi-compatible: For lisp indenting the first line is not | |
708 * indented, unless there is only one line. | |
709 */ | |
710 #ifdef FEAT_LISP | |
711 if (i != oap->line_count - 1 || oap->line_count == 1 | |
712 || how != get_lisp_indent) | |
713 #endif | |
714 { | |
715 l = skipwhite(ml_get_curline()); | |
716 if (*l == NUL) /* empty or blank line */ | |
6971 | 717 amount = 0; |
7 | 718 else |
6971 | 719 amount = how(); /* get the indent for this line */ |
720 | |
721 if (amount >= 0 && set_indent(amount, SIN_UNDO)) | |
7 | 722 { |
723 /* did change the indent, call changed_lines() later */ | |
724 if (first_changed == 0) | |
725 first_changed = curwin->w_cursor.lnum; | |
726 last_changed = curwin->w_cursor.lnum; | |
727 } | |
728 } | |
729 ++curwin->w_cursor.lnum; | |
1550 | 730 curwin->w_cursor.col = 0; /* make sure it's valid */ |
7 | 731 } |
732 | |
733 /* put cursor on first non-blank of indented line */ | |
734 curwin->w_cursor.lnum = start_lnum; | |
735 beginline(BL_SOL | BL_FIX); | |
736 | |
737 /* Mark changed lines so that they will be redrawn. When Visual | |
738 * highlighting was present, need to continue until the last line. When | |
739 * there is no change still need to remove the Visual highlighting. */ | |
740 if (last_changed != 0) | |
741 changed_lines(first_changed, 0, | |
742 oap->is_VIsual ? start_lnum + oap->line_count : | |
743 last_changed + 1, 0L); | |
744 else if (oap->is_VIsual) | |
745 redraw_curbuf_later(INVERTED); | |
746 | |
747 if (oap->line_count > p_report) | |
748 { | |
749 i = oap->line_count - (i + 1); | |
750 if (i == 1) | |
751 MSG(_("1 line indented ")); | |
752 else | |
753 smsg((char_u *)_("%ld lines indented "), i); | |
754 } | |
755 /* set '[ and '] marks */ | |
756 curbuf->b_op_start = oap->start; | |
757 curbuf->b_op_end = oap->end; | |
758 } | |
759 #endif /* defined(FEAT_LISP) || defined(FEAT_CINDENT) */ | |
760 | |
761 #if defined(FEAT_EVAL) || defined(PROTO) | |
762 /* | |
763 * Keep the last expression line here, for repeating. | |
764 */ | |
765 static char_u *expr_line = NULL; | |
766 | |
767 /* | |
768 * Get an expression for the "\"=expr1" or "CTRL-R =expr1" | |
769 * Returns '=' when OK, NUL otherwise. | |
770 */ | |
771 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
772 get_expr_register(void) |
7 | 773 { |
774 char_u *new_line; | |
775 | |
776 new_line = getcmdline('=', 0L, 0); | |
777 if (new_line == NULL) | |
778 return NUL; | |
779 if (*new_line == NUL) /* use previous line */ | |
780 vim_free(new_line); | |
781 else | |
782 set_expr_line(new_line); | |
783 return '='; | |
784 } | |
785 | |
786 /* | |
787 * Set the expression for the '=' register. | |
788 * Argument must be an allocated string. | |
789 */ | |
790 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
791 set_expr_line(char_u *new_line) |
7 | 792 { |
793 vim_free(expr_line); | |
794 expr_line = new_line; | |
795 } | |
796 | |
797 /* | |
798 * Get the result of the '=' register expression. | |
799 * Returns a pointer to allocated memory, or NULL for failure. | |
800 */ | |
801 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
802 get_expr_line(void) |
7 | 803 { |
804 char_u *expr_copy; | |
805 char_u *rv; | |
994 | 806 static int nested = 0; |
7 | 807 |
808 if (expr_line == NULL) | |
809 return NULL; | |
810 | |
811 /* Make a copy of the expression, because evaluating it may cause it to be | |
812 * changed. */ | |
813 expr_copy = vim_strsave(expr_line); | |
814 if (expr_copy == NULL) | |
815 return NULL; | |
816 | |
994 | 817 /* When we are invoked recursively limit the evaluation to 10 levels. |
818 * Then return the string as-is. */ | |
819 if (nested >= 10) | |
820 return expr_copy; | |
821 | |
822 ++nested; | |
714 | 823 rv = eval_to_string(expr_copy, NULL, TRUE); |
994 | 824 --nested; |
7 | 825 vim_free(expr_copy); |
826 return rv; | |
827 } | |
283 | 828 |
829 /* | |
830 * Get the '=' register expression itself, without evaluating it. | |
831 */ | |
832 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
833 get_expr_line_src(void) |
283 | 834 { |
835 if (expr_line == NULL) | |
836 return NULL; | |
837 return vim_strsave(expr_line); | |
838 } | |
7 | 839 #endif /* FEAT_EVAL */ |
840 | |
841 /* | |
842 * Check if 'regname' is a valid name of a yank register. | |
843 * Note: There is no check for 0 (default register), caller should do this | |
844 */ | |
845 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
846 valid_yank_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
847 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
848 int writing) /* if TRUE check for writable registers */ |
7 | 849 { |
850 if ( (regname > 0 && ASCII_ISALNUM(regname)) | |
851 || (!writing && vim_strchr((char_u *) | |
852 #ifdef FEAT_EVAL | |
6557 | 853 "/.%:=" |
7 | 854 #else |
6557 | 855 "/.%:" |
7 | 856 #endif |
857 , regname) != NULL) | |
6557 | 858 || regname == '#' |
7 | 859 || regname == '"' |
860 || regname == '-' | |
861 || regname == '_' | |
862 #ifdef FEAT_CLIPBOARD | |
863 || regname == '*' | |
864 || regname == '+' | |
865 #endif | |
866 #ifdef FEAT_DND | |
867 || (!writing && regname == '~') | |
868 #endif | |
869 ) | |
870 return TRUE; | |
871 return FALSE; | |
872 } | |
873 | |
874 /* | |
875 * Set y_current and y_append, according to the value of "regname". | |
876 * Cannot handle the '_' register. | |
140 | 877 * Must only be called with a valid register name! |
7 | 878 * |
879 * If regname is 0 and writing, use register 0 | |
880 * If regname is 0 and reading, use previous register | |
881 */ | |
15 | 882 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
883 get_yank_register(int regname, int writing) |
7 | 884 { |
885 int i; | |
886 | |
887 y_append = FALSE; | |
888 if ((regname == 0 || regname == '"') && !writing && y_previous != NULL) | |
889 { | |
890 y_current = y_previous; | |
891 return; | |
892 } | |
893 i = regname; | |
894 if (VIM_ISDIGIT(i)) | |
895 i -= '0'; | |
896 else if (ASCII_ISLOWER(i)) | |
897 i = CharOrdLow(i) + 10; | |
898 else if (ASCII_ISUPPER(i)) | |
899 { | |
900 i = CharOrdUp(i) + 10; | |
901 y_append = TRUE; | |
902 } | |
903 else if (regname == '-') | |
904 i = DELETION_REGISTER; | |
905 #ifdef FEAT_CLIPBOARD | |
906 /* When selection is not available, use register 0 instead of '*' */ | |
907 else if (clip_star.available && regname == '*') | |
908 i = STAR_REGISTER; | |
909 /* When clipboard is not available, use register 0 instead of '+' */ | |
910 else if (clip_plus.available && regname == '+') | |
911 i = PLUS_REGISTER; | |
912 #endif | |
913 #ifdef FEAT_DND | |
914 else if (!writing && regname == '~') | |
915 i = TILDE_REGISTER; | |
916 #endif | |
917 else /* not 0-9, a-z, A-Z or '-': use register 0 */ | |
918 i = 0; | |
919 y_current = &(y_regs[i]); | |
920 if (writing) /* remember the register we write into for do_put() */ | |
921 y_previous = y_current; | |
922 } | |
923 | |
15 | 924 #if defined(FEAT_CLIPBOARD) || defined(PROTO) |
7 | 925 /* |
926 * When "regname" is a clipboard register, obtain the selection. If it's not | |
927 * available return zero, otherwise return "regname". | |
928 */ | |
15 | 929 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
930 may_get_selection(int regname) |
7 | 931 { |
932 if (regname == '*') | |
933 { | |
934 if (!clip_star.available) | |
935 regname = 0; | |
936 else | |
937 clip_get_selection(&clip_star); | |
938 } | |
939 else if (regname == '+') | |
940 { | |
941 if (!clip_plus.available) | |
942 regname = 0; | |
943 else | |
944 clip_get_selection(&clip_plus); | |
945 } | |
946 return regname; | |
947 } | |
948 #endif | |
949 | |
950 /* | |
951 * Obtain the contents of a "normal" register. The register is made empty. | |
952 * The returned pointer has allocated memory, use put_register() later. | |
953 */ | |
954 void * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
955 get_register( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
956 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
957 int copy) /* make a copy, if FALSE make register empty. */ |
7 | 958 { |
1451 | 959 struct yankreg *reg; |
960 int i; | |
7 | 961 |
962 #ifdef FEAT_CLIPBOARD | |
963 /* When Visual area changed, may have to update selection. Obtain the | |
964 * selection too. */ | |
1435 | 965 if (name == '*' && clip_star.available) |
7 | 966 { |
3674 | 967 if (clip_isautosel_star()) |
968 clip_update_selection(&clip_star); | |
969 may_get_selection(name); | |
970 } | |
971 if (name == '+' && clip_plus.available) | |
972 { | |
973 if (clip_isautosel_plus()) | |
974 clip_update_selection(&clip_plus); | |
7 | 975 may_get_selection(name); |
976 } | |
977 #endif | |
978 | |
979 get_yank_register(name, 0); | |
980 reg = (struct yankreg *)alloc((unsigned)sizeof(struct yankreg)); | |
981 if (reg != NULL) | |
982 { | |
983 *reg = *y_current; | |
984 if (copy) | |
985 { | |
986 /* If we run out of memory some or all of the lines are empty. */ | |
987 if (reg->y_size == 0) | |
988 reg->y_array = NULL; | |
989 else | |
990 reg->y_array = (char_u **)alloc((unsigned)(sizeof(char_u *) | |
991 * reg->y_size)); | |
992 if (reg->y_array != NULL) | |
993 { | |
994 for (i = 0; i < reg->y_size; ++i) | |
995 reg->y_array[i] = vim_strsave(y_current->y_array[i]); | |
996 } | |
997 } | |
998 else | |
999 y_current->y_array = NULL; | |
1000 } | |
1001 return (void *)reg; | |
1002 } | |
1003 | |
1004 /* | |
1451 | 1005 * Put "reg" into register "name". Free any previous contents and "reg". |
7 | 1006 */ |
1007 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1008 put_register(int name, void *reg) |
7 | 1009 { |
1010 get_yank_register(name, 0); | |
1011 free_yank_all(); | |
1012 *y_current = *(struct yankreg *)reg; | |
1451 | 1013 vim_free(reg); |
7 | 1014 |
5735 | 1015 #ifdef FEAT_CLIPBOARD |
7 | 1016 /* Send text written to clipboard register to the clipboard. */ |
1017 may_set_selection(); | |
5735 | 1018 #endif |
7 | 1019 } |
4209 | 1020 |
1021 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1022 free_register(void *reg) |
4209 | 1023 { |
1024 struct yankreg tmp; | |
1025 | |
1026 tmp = *y_current; | |
1027 *y_current = *(struct yankreg *)reg; | |
1028 free_yank_all(); | |
1029 vim_free(reg); | |
1030 *y_current = tmp; | |
1031 } | |
7 | 1032 |
1033 #if defined(FEAT_MOUSE) || defined(PROTO) | |
1034 /* | |
1035 * return TRUE if the current yank register has type MLINE | |
1036 */ | |
1037 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1038 yank_register_mline(int regname) |
7 | 1039 { |
1040 if (regname != 0 && !valid_yank_reg(regname, FALSE)) | |
1041 return FALSE; | |
1042 if (regname == '_') /* black hole is always empty */ | |
1043 return FALSE; | |
1044 get_yank_register(regname, FALSE); | |
1045 return (y_current->y_type == MLINE); | |
1046 } | |
1047 #endif | |
1048 | |
1049 /* | |
1157 | 1050 * Start or stop recording into a yank register. |
7 | 1051 * |
1157 | 1052 * Return FAIL for failure, OK otherwise. |
7 | 1053 */ |
1054 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1055 do_record(int c) |
7 | 1056 { |
1157 | 1057 char_u *p; |
1058 static int regname; | |
1059 struct yankreg *old_y_previous, *old_y_current; | |
1060 int retval; | |
7 | 1061 |
1062 if (Recording == FALSE) /* start recording */ | |
1063 { | |
1064 /* registers 0-9, a-z and " are allowed */ | |
1065 if (c < 0 || (!ASCII_ISALNUM(c) && c != '"')) | |
1066 retval = FAIL; | |
1067 else | |
1068 { | |
7233
9487ea110214
commit https://github.com/vim/vim/commit/a0ed84a26897c994512873a895b9fc54e90c6845
Christian Brabandt <cb@256bit.org>
parents:
7011
diff
changeset
|
1069 Recording = c; |
7 | 1070 showmode(); |
1071 regname = c; | |
1072 retval = OK; | |
1073 } | |
1074 } | |
1075 else /* stop recording */ | |
1076 { | |
1077 /* | |
1157 | 1078 * Get the recorded key hits. K_SPECIAL and CSI will be escaped, this |
1079 * needs to be removed again to put it in a register. exec_reg then | |
1080 * adds the escaping back later. | |
7 | 1081 */ |
1082 Recording = FALSE; | |
1083 MSG(""); | |
1084 p = get_recorded(); | |
1085 if (p == NULL) | |
1086 retval = FAIL; | |
1087 else | |
1088 { | |
1081 | 1089 /* Remove escaping for CSI and K_SPECIAL in multi-byte chars. */ |
1090 vim_unescape_csi(p); | |
1091 | |
7 | 1092 /* |
1093 * We don't want to change the default register here, so save and | |
1094 * restore the current register name. | |
1095 */ | |
1096 old_y_previous = y_previous; | |
1097 old_y_current = y_current; | |
1098 | |
1099 retval = stuff_yank(regname, p); | |
1100 | |
1101 y_previous = old_y_previous; | |
1102 y_current = old_y_current; | |
1103 } | |
1104 } | |
1105 return retval; | |
1106 } | |
1107 | |
1108 /* | |
1109 * Stuff string "p" into yank register "regname" as a single line (append if | |
1110 * uppercase). "p" must have been alloced. | |
1111 * | |
1112 * return FAIL for failure, OK otherwise | |
1113 */ | |
1114 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1115 stuff_yank(int regname, char_u *p) |
7 | 1116 { |
1117 char_u *lp; | |
1118 char_u **pp; | |
1119 | |
1120 /* check for read-only register */ | |
1121 if (regname != 0 && !valid_yank_reg(regname, TRUE)) | |
1122 { | |
1123 vim_free(p); | |
1124 return FAIL; | |
1125 } | |
1126 if (regname == '_') /* black hole: don't do anything */ | |
1127 { | |
1128 vim_free(p); | |
1129 return OK; | |
1130 } | |
1131 get_yank_register(regname, TRUE); | |
1132 if (y_append && y_current->y_array != NULL) | |
1133 { | |
1134 pp = &(y_current->y_array[y_current->y_size - 1]); | |
1135 lp = lalloc((long_u)(STRLEN(*pp) + STRLEN(p) + 1), TRUE); | |
1136 if (lp == NULL) | |
1137 { | |
1138 vim_free(p); | |
1139 return FAIL; | |
1140 } | |
1141 STRCPY(lp, *pp); | |
1142 STRCAT(lp, p); | |
1143 vim_free(p); | |
1144 vim_free(*pp); | |
1145 *pp = lp; | |
1146 } | |
1147 else | |
1148 { | |
1149 free_yank_all(); | |
1150 if ((y_current->y_array = | |
1151 (char_u **)alloc((unsigned)sizeof(char_u *))) == NULL) | |
1152 { | |
1153 vim_free(p); | |
1154 return FAIL; | |
1155 } | |
1156 y_current->y_array[0] = p; | |
1157 y_current->y_size = 1; | |
1158 y_current->y_type = MCHAR; /* used to be MLINE, why? */ | |
1159 } | |
1160 return OK; | |
1161 } | |
1162 | |
1893 | 1163 static int execreg_lastc = NUL; |
1164 | |
7 | 1165 /* |
1166 * execute a yank register: copy it into the stuff buffer | |
1167 * | |
1168 * return FAIL for failure, OK otherwise | |
1169 */ | |
1170 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1171 do_execreg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1172 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1173 int colon, /* insert ':' before each line */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1174 int addcr, /* always add '\n' to end of line */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1175 int silent) /* set "silent" flag in typeahead buffer */ |
7 | 1176 { |
1177 long i; | |
1178 char_u *p; | |
1179 int retval = OK; | |
1180 int remap; | |
1181 | |
1182 if (regname == '@') /* repeat previous one */ | |
168 | 1183 { |
1893 | 1184 if (execreg_lastc == NUL) |
168 | 1185 { |
1186 EMSG(_("E748: No previously used register")); | |
1187 return FAIL; | |
1188 } | |
1893 | 1189 regname = execreg_lastc; |
168 | 1190 } |
7 | 1191 /* check for valid regname */ |
1192 if (regname == '%' || regname == '#' || !valid_yank_reg(regname, FALSE)) | |
168 | 1193 { |
1194 emsg_invreg(regname); | |
7 | 1195 return FAIL; |
168 | 1196 } |
1893 | 1197 execreg_lastc = regname; |
7 | 1198 |
1199 #ifdef FEAT_CLIPBOARD | |
1200 regname = may_get_selection(regname); | |
1201 #endif | |
1202 | |
1203 if (regname == '_') /* black hole: don't stuff anything */ | |
1204 return OK; | |
1205 | |
1206 #ifdef FEAT_CMDHIST | |
1207 if (regname == ':') /* use last command line */ | |
1208 { | |
1209 if (last_cmdline == NULL) | |
1210 { | |
1211 EMSG(_(e_nolastcmd)); | |
1212 return FAIL; | |
1213 } | |
1214 vim_free(new_last_cmdline); /* don't keep the cmdline containing @: */ | |
1215 new_last_cmdline = NULL; | |
16 | 1216 /* Escape all control characters with a CTRL-V */ |
1217 p = vim_strsave_escaped_ext(last_cmdline, | |
20 | 1218 (char_u *)"\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037", Ctrl_V, FALSE); |
16 | 1219 if (p != NULL) |
480 | 1220 { |
1221 /* When in Visual mode "'<,'>" will be prepended to the command. | |
1222 * Remove it when it's already there. */ | |
1223 if (VIsual_active && STRNCMP(p, "'<,'>", 5) == 0) | |
1077 | 1224 retval = put_in_typebuf(p + 5, TRUE, TRUE, silent); |
480 | 1225 else |
1077 | 1226 retval = put_in_typebuf(p, TRUE, TRUE, silent); |
480 | 1227 } |
16 | 1228 vim_free(p); |
7 | 1229 } |
1230 #endif | |
1231 #ifdef FEAT_EVAL | |
1232 else if (regname == '=') | |
1233 { | |
1234 p = get_expr_line(); | |
1235 if (p == NULL) | |
1236 return FAIL; | |
1077 | 1237 retval = put_in_typebuf(p, TRUE, colon, silent); |
7 | 1238 vim_free(p); |
1239 } | |
1240 #endif | |
1241 else if (regname == '.') /* use last inserted text */ | |
1242 { | |
1243 p = get_last_insert_save(); | |
1244 if (p == NULL) | |
1245 { | |
1246 EMSG(_(e_noinstext)); | |
1247 return FAIL; | |
1248 } | |
1077 | 1249 retval = put_in_typebuf(p, FALSE, colon, silent); |
7 | 1250 vim_free(p); |
1251 } | |
1252 else | |
1253 { | |
1254 get_yank_register(regname, FALSE); | |
1255 if (y_current->y_array == NULL) | |
1256 return FAIL; | |
1257 | |
1258 /* Disallow remaping for ":@r". */ | |
1259 remap = colon ? REMAP_NONE : REMAP_YES; | |
1260 | |
1261 /* | |
1262 * Insert lines into typeahead buffer, from last one to first one. | |
1263 */ | |
1034 | 1264 put_reedit_in_typebuf(silent); |
7 | 1265 for (i = y_current->y_size; --i >= 0; ) |
1266 { | |
1077 | 1267 char_u *escaped; |
1268 | |
7 | 1269 /* insert NL between lines and after last line if type is MLINE */ |
1270 if (y_current->y_type == MLINE || i < y_current->y_size - 1 | |
1271 || addcr) | |
1272 { | |
1034 | 1273 if (ins_typebuf((char_u *)"\n", remap, 0, TRUE, silent) == FAIL) |
7 | 1274 return FAIL; |
1275 } | |
1077 | 1276 escaped = vim_strsave_escape_csi(y_current->y_array[i]); |
1277 if (escaped == NULL) | |
1278 return FAIL; | |
1279 retval = ins_typebuf(escaped, remap, 0, TRUE, silent); | |
1280 vim_free(escaped); | |
1281 if (retval == FAIL) | |
7 | 1282 return FAIL; |
1034 | 1283 if (colon && ins_typebuf((char_u *)":", remap, 0, TRUE, silent) |
7 | 1284 == FAIL) |
1285 return FAIL; | |
1286 } | |
1287 Exec_reg = TRUE; /* disable the 'q' command */ | |
1288 } | |
1289 return retval; | |
1290 } | |
1291 | |
1292 /* | |
1293 * If "restart_edit" is not zero, put it in the typeahead buffer, so that it's | |
1294 * used only after other typeahead has been processed. | |
1295 */ | |
1296 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1297 put_reedit_in_typebuf(int silent) |
7 | 1298 { |
1299 char_u buf[3]; | |
1300 | |
1301 if (restart_edit != NUL) | |
1302 { | |
1303 if (restart_edit == 'V') | |
1304 { | |
1305 buf[0] = 'g'; | |
1306 buf[1] = 'R'; | |
1307 buf[2] = NUL; | |
1308 } | |
1309 else | |
1310 { | |
1311 buf[0] = restart_edit == 'I' ? 'i' : restart_edit; | |
1312 buf[1] = NUL; | |
1313 } | |
1034 | 1314 if (ins_typebuf(buf, REMAP_NONE, 0, TRUE, silent) == OK) |
7 | 1315 restart_edit = NUL; |
1316 } | |
1317 } | |
1318 | |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1319 /* |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1320 * Insert register contents "s" into the typeahead buffer, so that it will be |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1321 * executed again. |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1322 * When "esc" is TRUE it is to be taken literally: Escape CSI characters and |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1323 * no remapping. |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1324 */ |
7 | 1325 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1326 put_in_typebuf( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1327 char_u *s, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1328 int esc, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1329 int colon, /* add ':' before the line */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1330 int silent) |
7 | 1331 { |
1332 int retval = OK; | |
1333 | |
1034 | 1334 put_reedit_in_typebuf(silent); |
7 | 1335 if (colon) |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1336 retval = ins_typebuf((char_u *)"\n", REMAP_NONE, 0, TRUE, silent); |
7 | 1337 if (retval == OK) |
1077 | 1338 { |
1339 char_u *p; | |
1340 | |
1341 if (esc) | |
1342 p = vim_strsave_escape_csi(s); | |
1343 else | |
1344 p = s; | |
1345 if (p == NULL) | |
1346 retval = FAIL; | |
1347 else | |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1348 retval = ins_typebuf(p, esc ? REMAP_NONE : REMAP_YES, |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1349 0, TRUE, silent); |
1077 | 1350 if (esc) |
1351 vim_free(p); | |
1352 } | |
7 | 1353 if (colon && retval == OK) |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1354 retval = ins_typebuf((char_u *)":", REMAP_NONE, 0, TRUE, silent); |
7 | 1355 return retval; |
1356 } | |
1357 | |
1358 /* | |
1359 * Insert a yank register: copy it into the Read buffer. | |
1360 * Used by CTRL-R command and middle mouse button in insert mode. | |
1361 * | |
1362 * return FAIL for failure, OK otherwise | |
1363 */ | |
1364 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1365 insert_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1366 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1367 int literally) /* insert literally, not as if typed */ |
7 | 1368 { |
1369 long i; | |
1370 int retval = OK; | |
1371 char_u *arg; | |
1372 int allocated; | |
1373 | |
1374 /* | |
1375 * It is possible to get into an endless loop by having CTRL-R a in | |
1376 * register a and then, in insert mode, doing CTRL-R a. | |
1377 * If you hit CTRL-C, the loop will be broken here. | |
1378 */ | |
1379 ui_breakcheck(); | |
1380 if (got_int) | |
1381 return FAIL; | |
1382 | |
1383 /* check for valid regname */ | |
1384 if (regname != NUL && !valid_yank_reg(regname, FALSE)) | |
1385 return FAIL; | |
1386 | |
1387 #ifdef FEAT_CLIPBOARD | |
1388 regname = may_get_selection(regname); | |
1389 #endif | |
1390 | |
1391 if (regname == '.') /* insert last inserted text */ | |
1392 retval = stuff_inserted(NUL, 1L, TRUE); | |
1393 else if (get_spec_reg(regname, &arg, &allocated, TRUE)) | |
1394 { | |
1395 if (arg == NULL) | |
1396 return FAIL; | |
1397 stuffescaped(arg, literally); | |
1398 if (allocated) | |
1399 vim_free(arg); | |
1400 } | |
1401 else /* name or number register */ | |
1402 { | |
1403 get_yank_register(regname, FALSE); | |
1404 if (y_current->y_array == NULL) | |
1405 retval = FAIL; | |
1406 else | |
1407 { | |
1408 for (i = 0; i < y_current->y_size; ++i) | |
1409 { | |
1410 stuffescaped(y_current->y_array[i], literally); | |
1411 /* | |
1412 * Insert a newline between lines and after last line if | |
1413 * y_type is MLINE. | |
1414 */ | |
1415 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | |
1416 stuffcharReadbuff('\n'); | |
1417 } | |
1418 } | |
1419 } | |
1420 | |
1421 return retval; | |
1422 } | |
1423 | |
1424 /* | |
1425 * Stuff a string into the typeahead buffer, such that edit() will insert it | |
1426 * literally ("literally" TRUE) or interpret is as typed characters. | |
1427 */ | |
1428 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1429 stuffescaped(char_u *arg, int literally) |
7 | 1430 { |
1431 int c; | |
1432 char_u *start; | |
1433 | |
1434 while (*arg != NUL) | |
1435 { | |
1436 /* Stuff a sequence of normal ASCII characters, that's fast. Also | |
1437 * stuff K_SPECIAL to get the effect of a special key when "literally" | |
1438 * is TRUE. */ | |
1439 start = arg; | |
1440 while ((*arg >= ' ' | |
1441 #ifndef EBCDIC | |
1442 && *arg < DEL /* EBCDIC: chars above space are normal */ | |
1443 #endif | |
1444 ) | |
1445 || (*arg == K_SPECIAL && !literally)) | |
1446 ++arg; | |
1447 if (arg > start) | |
1448 stuffReadbuffLen(start, (long)(arg - start)); | |
1449 | |
1450 /* stuff a single special character */ | |
1451 if (*arg != NUL) | |
1452 { | |
1453 #ifdef FEAT_MBYTE | |
1454 if (has_mbyte) | |
2446
348f64c129df
Fixed: CTRL-R in Insert mode doesn't insert composing characters.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1455 c = mb_cptr2char_adv(&arg); |
7 | 1456 else |
1457 #endif | |
1458 c = *arg++; | |
1459 if (literally && ((c < ' ' && c != TAB) || c == DEL)) | |
1460 stuffcharReadbuff(Ctrl_V); | |
1461 stuffcharReadbuff(c); | |
1462 } | |
1463 } | |
1464 } | |
1465 | |
1466 /* | |
1157 | 1467 * If "regname" is a special register, return TRUE and store a pointer to its |
1468 * value in "argp". | |
7 | 1469 */ |
15 | 1470 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1471 get_spec_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1472 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1473 char_u **argp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1474 int *allocated, /* return: TRUE when value was allocated */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1475 int errmsg) /* give error message when failing */ |
7 | 1476 { |
1477 int cnt; | |
1478 | |
1479 *argp = NULL; | |
1480 *allocated = FALSE; | |
1481 switch (regname) | |
1482 { | |
1483 case '%': /* file name */ | |
1484 if (errmsg) | |
1485 check_fname(); /* will give emsg if not set */ | |
1486 *argp = curbuf->b_fname; | |
1487 return TRUE; | |
1488 | |
1489 case '#': /* alternate file name */ | |
1490 *argp = getaltfname(errmsg); /* may give emsg if not set */ | |
1491 return TRUE; | |
1492 | |
1493 #ifdef FEAT_EVAL | |
1494 case '=': /* result of expression */ | |
1495 *argp = get_expr_line(); | |
1496 *allocated = TRUE; | |
1497 return TRUE; | |
1498 #endif | |
1499 | |
1500 case ':': /* last command line */ | |
1501 if (last_cmdline == NULL && errmsg) | |
1502 EMSG(_(e_nolastcmd)); | |
1503 *argp = last_cmdline; | |
1504 return TRUE; | |
1505 | |
1506 case '/': /* last search-pattern */ | |
1507 if (last_search_pat() == NULL && errmsg) | |
1508 EMSG(_(e_noprevre)); | |
1509 *argp = last_search_pat(); | |
1510 return TRUE; | |
1511 | |
1512 case '.': /* last inserted text */ | |
1513 *argp = get_last_insert_save(); | |
1514 *allocated = TRUE; | |
1515 if (*argp == NULL && errmsg) | |
1516 EMSG(_(e_noinstext)); | |
1517 return TRUE; | |
1518 | |
1519 #ifdef FEAT_SEARCHPATH | |
1520 case Ctrl_F: /* Filename under cursor */ | |
1521 case Ctrl_P: /* Path under cursor, expand via "path" */ | |
1522 if (!errmsg) | |
1523 return FALSE; | |
1524 *argp = file_name_at_cursor(FNAME_MESS | FNAME_HYP | |
681 | 1525 | (regname == Ctrl_P ? FNAME_EXP : 0), 1L, NULL); |
7 | 1526 *allocated = TRUE; |
1527 return TRUE; | |
1528 #endif | |
1529 | |
1530 case Ctrl_W: /* word under cursor */ | |
1531 case Ctrl_A: /* WORD (mnemonic All) under cursor */ | |
1532 if (!errmsg) | |
1533 return FALSE; | |
1534 cnt = find_ident_under_cursor(argp, regname == Ctrl_W | |
1535 ? (FIND_IDENT|FIND_STRING) : FIND_STRING); | |
1536 *argp = cnt ? vim_strnsave(*argp, cnt) : NULL; | |
1537 *allocated = TRUE; | |
1538 return TRUE; | |
1539 | |
1540 case '_': /* black hole: always empty */ | |
1541 *argp = (char_u *)""; | |
1542 return TRUE; | |
1543 } | |
1544 | |
1545 return FALSE; | |
1546 } | |
1547 | |
1548 /* | |
15 | 1549 * Paste a yank register into the command line. |
1550 * Only for non-special registers. | |
1551 * Used by CTRL-R command in command-line mode | |
7 | 1552 * insert_reg() can't be used here, because special characters from the |
1553 * register contents will be interpreted as commands. | |
1554 * | |
1555 * return FAIL for failure, OK otherwise | |
1556 */ | |
1557 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1558 cmdline_paste_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1559 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1560 int literally, /* Insert text literally instead of "as typed" */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1561 int remcr) /* don't add CR characters */ |
7 | 1562 { |
1563 long i; | |
1564 | |
1565 get_yank_register(regname, FALSE); | |
1566 if (y_current->y_array == NULL) | |
1567 return FAIL; | |
1568 | |
1569 for (i = 0; i < y_current->y_size; ++i) | |
1570 { | |
1571 cmdline_paste_str(y_current->y_array[i], literally); | |
1572 | |
1015 | 1573 /* Insert ^M between lines and after last line if type is MLINE. |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
1574 * Don't do this when "remcr" is TRUE. */ |
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
1575 if ((y_current->y_type == MLINE || i < y_current->y_size - 1) && !remcr) |
7 | 1576 cmdline_paste_str((char_u *)"\r", literally); |
1577 | |
1578 /* Check for CTRL-C, in case someone tries to paste a few thousand | |
1579 * lines and gets bored. */ | |
1580 ui_breakcheck(); | |
1581 if (got_int) | |
1582 return FAIL; | |
1583 } | |
1584 return OK; | |
1585 } | |
1586 | |
1587 #if defined(FEAT_CLIPBOARD) || defined(PROTO) | |
1588 /* | |
1589 * Adjust the register name pointed to with "rp" for the clipboard being | |
1590 * used always and the clipboard being available. | |
1591 */ | |
1592 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1593 adjust_clip_reg(int *rp) |
7 | 1594 { |
2654 | 1595 /* If no reg. specified, and "unnamed" or "unnamedplus" is in 'clipboard', |
1596 * use '*' or '+' reg, respectively. "unnamedplus" prevails. */ | |
6116 | 1597 if (*rp == 0 && (clip_unnamed != 0 || clip_unnamed_saved != 0)) |
1598 { | |
1599 if (clip_unnamed != 0) | |
1600 *rp = ((clip_unnamed & CLIP_UNNAMED_PLUS) && clip_plus.available) | |
2654 | 1601 ? '+' : '*'; |
6116 | 1602 else |
1603 *rp = ((clip_unnamed_saved & CLIP_UNNAMED_PLUS) && clip_plus.available) | |
1604 ? '+' : '*'; | |
1605 } | |
7 | 1606 if (!clip_star.available && *rp == '*') |
1607 *rp = 0; | |
1608 if (!clip_plus.available && *rp == '+') | |
1609 *rp = 0; | |
1610 } | |
1611 #endif | |
1612 | |
1613 /* | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1614 * Handle a delete operation. |
7 | 1615 * |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1616 * Return FAIL if undo failed, OK otherwise. |
7 | 1617 */ |
1618 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1619 op_delete(oparg_T *oap) |
7 | 1620 { |
1621 int n; | |
1622 linenr_T lnum; | |
1623 char_u *ptr; | |
1624 char_u *newp, *oldp; | |
1625 struct block_def bd; | |
1626 linenr_T old_lcount = curbuf->b_ml.ml_line_count; | |
1627 int did_yank = FALSE; | |
3782 | 1628 int orig_regname = oap->regname; |
7 | 1629 |
1630 if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to do */ | |
1631 return OK; | |
1632 | |
1633 /* Nothing to delete, return here. Do prepare undo, for op_change(). */ | |
1634 if (oap->empty) | |
1635 return u_save_cursor(); | |
1636 | |
1637 if (!curbuf->b_p_ma) | |
1638 { | |
1639 EMSG(_(e_modifiable)); | |
1640 return FAIL; | |
1641 } | |
1642 | |
1643 #ifdef FEAT_CLIPBOARD | |
1644 adjust_clip_reg(&oap->regname); | |
1645 #endif | |
1646 | |
1647 #ifdef FEAT_MBYTE | |
1648 if (has_mbyte) | |
1649 mb_adjust_opend(oap); | |
1650 #endif | |
1651 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1652 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1653 * Imitate the strange Vi behaviour: If the delete spans more than one |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1654 * line and motion_type == MCHAR and the result is a blank line, make the |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1655 * delete linewise. Don't do this for the change command or Visual mode. |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1656 */ |
7 | 1657 if ( oap->motion_type == MCHAR |
1658 && !oap->is_VIsual | |
50 | 1659 && !oap->block_mode |
7 | 1660 && oap->line_count > 1 |
3254 | 1661 && oap->motion_force == NUL |
7 | 1662 && oap->op_type == OP_DELETE) |
1663 { | |
2957 | 1664 ptr = ml_get(oap->end.lnum) + oap->end.col; |
1665 if (*ptr != NUL) | |
1666 ptr += oap->inclusive; | |
7 | 1667 ptr = skipwhite(ptr); |
1668 if (*ptr == NUL && inindent(0)) | |
1669 oap->motion_type = MLINE; | |
1670 } | |
1671 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1672 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1673 * Check for trying to delete (e.g. "D") in an empty line. |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1674 * Note: For the change operator it is ok. |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1675 */ |
7 | 1676 if ( oap->motion_type == MCHAR |
1677 && oap->line_count == 1 | |
1678 && oap->op_type == OP_DELETE | |
1679 && *ml_get(oap->start.lnum) == NUL) | |
1680 { | |
1681 /* | |
446 | 1682 * It's an error to operate on an empty region, when 'E' included in |
7 | 1683 * 'cpoptions' (Vi compatible). |
1684 */ | |
446 | 1685 #ifdef FEAT_VIRTUALEDIT |
1686 if (virtual_op) | |
1687 /* Virtual editing: Nothing gets deleted, but we set the '[ and '] | |
1688 * marks as if it happened. */ | |
1689 goto setmarks; | |
1690 #endif | |
7 | 1691 if (vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL) |
1692 beep_flush(); | |
1693 return OK; | |
1694 } | |
1695 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1696 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1697 * Do a yank of whatever we're about to delete. |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1698 * If a yank register was specified, put the deleted text into that |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1699 * register. For the black hole register '_' don't yank anything. |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1700 */ |
7 | 1701 if (oap->regname != '_') |
1702 { | |
1703 if (oap->regname != 0) | |
1704 { | |
1705 /* check for read-only register */ | |
1706 if (!valid_yank_reg(oap->regname, TRUE)) | |
1707 { | |
1708 beep_flush(); | |
1709 return OK; | |
1710 } | |
1711 get_yank_register(oap->regname, TRUE); /* yank into specif'd reg. */ | |
1712 if (op_yank(oap, TRUE, FALSE) == OK) /* yank without message */ | |
1713 did_yank = TRUE; | |
1714 } | |
1715 | |
1716 /* | |
1717 * Put deleted text into register 1 and shift number registers if the | |
1718 * delete contains a line break, or when a regname has been specified. | |
3782 | 1719 * Use the register name from before adjust_clip_reg() may have |
1720 * changed it. | |
7 | 1721 */ |
3782 | 1722 if (orig_regname != 0 || oap->motion_type == MLINE |
7 | 1723 || oap->line_count > 1 || oap->use_reg_one) |
1724 { | |
1725 y_current = &y_regs[9]; | |
1726 free_yank_all(); /* free register nine */ | |
1727 for (n = 9; n > 1; --n) | |
1728 y_regs[n] = y_regs[n - 1]; | |
1729 y_previous = y_current = &y_regs[1]; | |
1730 y_regs[1].y_array = NULL; /* set register one to empty */ | |
1731 if (op_yank(oap, TRUE, FALSE) == OK) | |
1732 did_yank = TRUE; | |
1733 } | |
1734 | |
3468 | 1735 /* Yank into small delete register when no named register specified |
1736 * and the delete is within one line. */ | |
1737 if (( | |
1738 #ifdef FEAT_CLIPBOARD | |
3584 | 1739 ((clip_unnamed & CLIP_UNNAMED) && oap->regname == '*') || |
1740 ((clip_unnamed & CLIP_UNNAMED_PLUS) && oap->regname == '+') || | |
3468 | 1741 #endif |
1742 oap->regname == 0) && oap->motion_type != MLINE | |
7 | 1743 && oap->line_count == 1) |
1744 { | |
1745 oap->regname = '-'; | |
1746 get_yank_register(oap->regname, TRUE); | |
1747 if (op_yank(oap, TRUE, FALSE) == OK) | |
1748 did_yank = TRUE; | |
1749 oap->regname = 0; | |
1750 } | |
1751 | |
1752 /* | |
1753 * If there's too much stuff to fit in the yank register, then get a | |
1754 * confirmation before doing the delete. This is crude, but simple. | |
1755 * And it avoids doing a delete of something we can't put back if we | |
1756 * want. | |
1757 */ | |
1758 if (!did_yank) | |
1759 { | |
1760 int msg_silent_save = msg_silent; | |
1761 | |
1762 msg_silent = 0; /* must display the prompt */ | |
1763 n = ask_yesno((char_u *)_("cannot yank; delete anyway"), TRUE); | |
1764 msg_silent = msg_silent_save; | |
1765 if (n != 'y') | |
1766 { | |
1767 EMSG(_(e_abort)); | |
1768 return FAIL; | |
1769 } | |
1770 } | |
1771 } | |
1772 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1773 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1774 * block mode delete |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1775 */ |
7 | 1776 if (oap->block_mode) |
1777 { | |
1778 if (u_save((linenr_T)(oap->start.lnum - 1), | |
1779 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
1780 return FAIL; | |
1781 | |
1782 for (lnum = curwin->w_cursor.lnum; lnum <= oap->end.lnum; ++lnum) | |
1783 { | |
1784 block_prep(oap, &bd, lnum, TRUE); | |
1785 if (bd.textlen == 0) /* nothing to delete */ | |
1786 continue; | |
1787 | |
1788 /* Adjust cursor position for tab replaced by spaces and 'lbr'. */ | |
1789 if (lnum == curwin->w_cursor.lnum) | |
1790 { | |
1791 curwin->w_cursor.col = bd.textcol + bd.startspaces; | |
1792 # ifdef FEAT_VIRTUALEDIT | |
1793 curwin->w_cursor.coladd = 0; | |
1794 # endif | |
1795 } | |
1796 | |
1797 /* n == number of chars deleted | |
1798 * If we delete a TAB, it may be replaced by several characters. | |
1799 * Thus the number of characters may increase! | |
1800 */ | |
1801 n = bd.textlen - bd.startspaces - bd.endspaces; | |
1802 oldp = ml_get(lnum); | |
1803 newp = alloc_check((unsigned)STRLEN(oldp) + 1 - n); | |
1804 if (newp == NULL) | |
1805 continue; | |
1806 /* copy up to deleted part */ | |
1807 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
1808 /* insert spaces */ | |
6929 | 1809 vim_memset(newp + bd.textcol, ' ', |
7 | 1810 (size_t)(bd.startspaces + bd.endspaces)); |
1811 /* copy the part after the deleted part */ | |
1812 oldp += bd.textcol + bd.textlen; | |
1622 | 1813 STRMOVE(newp + bd.textcol + bd.startspaces + bd.endspaces, oldp); |
7 | 1814 /* replace the line */ |
1815 ml_replace(lnum, newp, FALSE); | |
1816 } | |
1817 | |
1818 check_cursor_col(); | |
1819 changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col, | |
1820 oap->end.lnum + 1, 0L); | |
1821 oap->line_count = 0; /* no lines deleted */ | |
1822 } | |
5735 | 1823 else if (oap->motion_type == MLINE) |
7 | 1824 { |
1825 if (oap->op_type == OP_CHANGE) | |
1826 { | |
1827 /* Delete the lines except the first one. Temporarily move the | |
1828 * cursor to the next line. Save the current line number, if the | |
1829 * last line is deleted it may be changed. | |
1830 */ | |
1831 if (oap->line_count > 1) | |
1832 { | |
1833 lnum = curwin->w_cursor.lnum; | |
1834 ++curwin->w_cursor.lnum; | |
1835 del_lines((long)(oap->line_count - 1), TRUE); | |
1836 curwin->w_cursor.lnum = lnum; | |
1837 } | |
1838 if (u_save_cursor() == FAIL) | |
1839 return FAIL; | |
1840 if (curbuf->b_p_ai) /* don't delete indent */ | |
1841 { | |
1842 beginline(BL_WHITE); /* cursor on first non-white */ | |
1843 did_ai = TRUE; /* delete the indent when ESC hit */ | |
1844 ai_col = curwin->w_cursor.col; | |
1845 } | |
1846 else | |
1847 beginline(0); /* cursor in column 0 */ | |
1848 truncate_line(FALSE); /* delete the rest of the line */ | |
1849 /* leave cursor past last char in line */ | |
1850 if (oap->line_count > 1) | |
1851 u_clearline(); /* "U" command not possible after "2cc" */ | |
1852 } | |
1853 else | |
1854 { | |
1855 del_lines(oap->line_count, TRUE); | |
1856 beginline(BL_WHITE | BL_FIX); | |
1857 u_clearline(); /* "U" command not possible after "dd" */ | |
1858 } | |
1859 } | |
1860 else | |
1861 { | |
1862 #ifdef FEAT_VIRTUALEDIT | |
1863 if (virtual_op) | |
1864 { | |
1865 int endcol = 0; | |
1866 | |
1867 /* For virtualedit: break the tabs that are partly included. */ | |
1868 if (gchar_pos(&oap->start) == '\t') | |
1869 { | |
1870 if (u_save_cursor() == FAIL) /* save first line for undo */ | |
1871 return FAIL; | |
1872 if (oap->line_count == 1) | |
1873 endcol = getviscol2(oap->end.col, oap->end.coladd); | |
1874 coladvance_force(getviscol2(oap->start.col, oap->start.coladd)); | |
1875 oap->start = curwin->w_cursor; | |
1876 if (oap->line_count == 1) | |
1877 { | |
1878 coladvance(endcol); | |
1879 oap->end.col = curwin->w_cursor.col; | |
1880 oap->end.coladd = curwin->w_cursor.coladd; | |
1881 curwin->w_cursor = oap->start; | |
1882 } | |
1883 } | |
1884 | |
1885 /* Break a tab only when it's included in the area. */ | |
1886 if (gchar_pos(&oap->end) == '\t' | |
1887 && (int)oap->end.coladd < oap->inclusive) | |
1888 { | |
1889 /* save last line for undo */ | |
1890 if (u_save((linenr_T)(oap->end.lnum - 1), | |
1891 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
1892 return FAIL; | |
1893 curwin->w_cursor = oap->end; | |
1894 coladvance_force(getviscol2(oap->end.col, oap->end.coladd)); | |
1895 oap->end = curwin->w_cursor; | |
1896 curwin->w_cursor = oap->start; | |
1897 } | |
1898 } | |
1899 #endif | |
1900 | |
1901 if (oap->line_count == 1) /* delete characters within one line */ | |
1902 { | |
1903 if (u_save_cursor() == FAIL) /* save line for undo */ | |
1904 return FAIL; | |
1905 | |
1906 /* if 'cpoptions' contains '$', display '$' at end of change */ | |
5735 | 1907 if ( vim_strchr(p_cpo, CPO_DOLLAR) != NULL |
7 | 1908 && oap->op_type == OP_CHANGE |
1909 && oap->end.lnum == curwin->w_cursor.lnum | |
5735 | 1910 && !oap->is_VIsual) |
7 | 1911 display_dollar(oap->end.col - !oap->inclusive); |
1912 | |
1913 n = oap->end.col - oap->start.col + 1 - !oap->inclusive; | |
1914 | |
1915 #ifdef FEAT_VIRTUALEDIT | |
1916 if (virtual_op) | |
1917 { | |
1918 /* fix up things for virtualedit-delete: | |
1919 * break the tabs which are going to get in our way | |
1920 */ | |
1921 char_u *curline = ml_get_curline(); | |
1922 int len = (int)STRLEN(curline); | |
1923 | |
1924 if (oap->end.coladd != 0 | |
1925 && (int)oap->end.col >= len - 1 | |
1926 && !(oap->start.coladd && (int)oap->end.col >= len - 1)) | |
1927 n++; | |
1928 /* Delete at least one char (e.g, when on a control char). */ | |
1929 if (n == 0 && oap->start.coladd != oap->end.coladd) | |
1930 n = 1; | |
1931 | |
1932 /* When deleted a char in the line, reset coladd. */ | |
1933 if (gchar_cursor() != NUL) | |
1934 curwin->w_cursor.coladd = 0; | |
1935 } | |
1936 #endif | |
6826 | 1937 (void)del_bytes((long)n, !virtual_op, |
1938 oap->op_type == OP_DELETE && !oap->is_VIsual); | |
7 | 1939 } |
1940 else /* delete characters between lines */ | |
1941 { | |
1942 pos_T curpos; | |
1943 | |
1944 /* save deleted and changed lines for undo */ | |
1945 if (u_save((linenr_T)(curwin->w_cursor.lnum - 1), | |
1946 (linenr_T)(curwin->w_cursor.lnum + oap->line_count)) == FAIL) | |
1947 return FAIL; | |
1948 | |
1949 truncate_line(TRUE); /* delete from cursor to end of line */ | |
1950 | |
1951 curpos = curwin->w_cursor; /* remember curwin->w_cursor */ | |
1952 ++curwin->w_cursor.lnum; | |
1953 del_lines((long)(oap->line_count - 2), FALSE); | |
1954 | |
6826 | 1955 /* delete from start of line until op_end */ |
2957 | 1956 n = (oap->end.col + 1 - !oap->inclusive); |
6826 | 1957 curwin->w_cursor.col = 0; |
1958 (void)del_bytes((long)n, !virtual_op, | |
1959 oap->op_type == OP_DELETE && !oap->is_VIsual); | |
1960 curwin->w_cursor = curpos; /* restore curwin->w_cursor */ | |
1961 (void)do_join(2, FALSE, FALSE, FALSE, FALSE); | |
7 | 1962 } |
1963 } | |
1964 | |
1965 msgmore(curbuf->b_ml.ml_line_count - old_lcount); | |
1966 | |
446 | 1967 #ifdef FEAT_VIRTUALEDIT |
1968 setmarks: | |
1969 #endif | |
7 | 1970 if (oap->block_mode) |
1971 { | |
1972 curbuf->b_op_end.lnum = oap->end.lnum; | |
1973 curbuf->b_op_end.col = oap->start.col; | |
1974 } | |
1975 else | |
1976 curbuf->b_op_end = oap->start; | |
1977 curbuf->b_op_start = oap->start; | |
1978 | |
1979 return OK; | |
1980 } | |
1981 | |
1982 #ifdef FEAT_MBYTE | |
1983 /* | |
1984 * Adjust end of operating area for ending on a multi-byte character. | |
1985 * Used for deletion. | |
1986 */ | |
1987 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1988 mb_adjust_opend(oparg_T *oap) |
7 | 1989 { |
1990 char_u *p; | |
1991 | |
1992 if (oap->inclusive) | |
1993 { | |
1994 p = ml_get(oap->end.lnum); | |
1995 oap->end.col += mb_tail_off(p, p + oap->end.col); | |
1996 } | |
1997 } | |
1998 #endif | |
1999 | |
2000 #if defined(FEAT_VISUALEXTRA) || defined(PROTO) | |
2001 /* | |
2002 * Replace a whole area with one character. | |
2003 */ | |
2004 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2005 op_replace(oparg_T *oap, int c) |
7 | 2006 { |
2007 int n, numc; | |
2008 #ifdef FEAT_MBYTE | |
2009 int num_chars; | |
2010 #endif | |
2011 char_u *newp, *oldp; | |
2012 size_t oldlen; | |
2013 struct block_def bd; | |
5428 | 2014 char_u *after_p = NULL; |
2015 int had_ctrl_v_cr = (c == -1 || c == -2); | |
7 | 2016 |
2017 if ((curbuf->b_ml.ml_flags & ML_EMPTY ) || oap->empty) | |
2018 return OK; /* nothing to do */ | |
2019 | |
5428 | 2020 if (had_ctrl_v_cr) |
2021 c = (c == -1 ? '\r' : '\n'); | |
2022 | |
7 | 2023 #ifdef FEAT_MBYTE |
2024 if (has_mbyte) | |
2025 mb_adjust_opend(oap); | |
2026 #endif | |
2027 | |
2028 if (u_save((linenr_T)(oap->start.lnum - 1), | |
2029 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
2030 return FAIL; | |
2031 | |
2032 /* | |
2033 * block mode replace | |
2034 */ | |
2035 if (oap->block_mode) | |
2036 { | |
2037 bd.is_MAX = (curwin->w_curswant == MAXCOL); | |
2038 for ( ; curwin->w_cursor.lnum <= oap->end.lnum; ++curwin->w_cursor.lnum) | |
2039 { | |
1982 | 2040 curwin->w_cursor.col = 0; /* make sure cursor position is valid */ |
7 | 2041 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); |
2042 if (bd.textlen == 0 && (!virtual_op || bd.is_MAX)) | |
2043 continue; /* nothing to replace */ | |
2044 | |
2045 /* n == number of extra chars required | |
2046 * If we split a TAB, it may be replaced by several characters. | |
2047 * Thus the number of characters may increase! | |
2048 */ | |
2049 #ifdef FEAT_VIRTUALEDIT | |
2050 /* If the range starts in virtual space, count the initial | |
2051 * coladd offset as part of "startspaces" */ | |
2052 if (virtual_op && bd.is_short && *bd.textstart == NUL) | |
2053 { | |
2054 pos_T vpos; | |
2055 | |
1982 | 2056 vpos.lnum = curwin->w_cursor.lnum; |
7 | 2057 getvpos(&vpos, oap->start_vcol); |
2058 bd.startspaces += vpos.coladd; | |
2059 n = bd.startspaces; | |
2060 } | |
2061 else | |
2062 #endif | |
2063 /* allow for pre spaces */ | |
2064 n = (bd.startspaces ? bd.start_char_vcols - 1 : 0); | |
2065 | |
2066 /* allow for post spp */ | |
2067 n += (bd.endspaces | |
2068 #ifdef FEAT_VIRTUALEDIT | |
2069 && !bd.is_oneChar | |
2070 #endif | |
2071 && bd.end_char_vcols > 0) ? bd.end_char_vcols - 1 : 0; | |
2072 /* Figure out how many characters to replace. */ | |
2073 numc = oap->end_vcol - oap->start_vcol + 1; | |
2074 if (bd.is_short && (!virtual_op || bd.is_MAX)) | |
2075 numc -= (oap->end_vcol - bd.end_vcol) + 1; | |
2076 | |
2077 #ifdef FEAT_MBYTE | |
2078 /* A double-wide character can be replaced only up to half the | |
2079 * times. */ | |
2080 if ((*mb_char2cells)(c) > 1) | |
2081 { | |
2082 if ((numc & 1) && !bd.is_short) | |
2083 { | |
2084 ++bd.endspaces; | |
2085 ++n; | |
2086 } | |
2087 numc = numc / 2; | |
2088 } | |
2089 | |
2090 /* Compute bytes needed, move character count to num_chars. */ | |
2091 num_chars = numc; | |
2092 numc *= (*mb_char2len)(c); | |
2093 #endif | |
2094 /* oldlen includes textlen, so don't double count */ | |
2095 n += numc - bd.textlen; | |
2096 | |
2097 oldp = ml_get_curline(); | |
2098 oldlen = STRLEN(oldp); | |
2099 newp = alloc_check((unsigned)oldlen + 1 + n); | |
2100 if (newp == NULL) | |
2101 continue; | |
2102 vim_memset(newp, NUL, (size_t)(oldlen + 1 + n)); | |
2103 /* copy up to deleted part */ | |
2104 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
2105 oldp += bd.textcol + bd.textlen; | |
2106 /* insert pre-spaces */ | |
6929 | 2107 vim_memset(newp + bd.textcol, ' ', (size_t)bd.startspaces); |
7 | 2108 /* insert replacement chars CHECK FOR ALLOCATED SPACE */ |
5428 | 2109 /* -1/-2 is used for entering CR literally. */ |
2110 if (had_ctrl_v_cr || (c != '\r' && c != '\n')) | |
7 | 2111 { |
5428 | 2112 #ifdef FEAT_MBYTE |
2113 if (has_mbyte) | |
2114 { | |
2115 n = (int)STRLEN(newp); | |
2116 while (--num_chars >= 0) | |
2117 n += (*mb_char2bytes)(c, newp + n); | |
2118 } | |
2119 else | |
2120 #endif | |
6929 | 2121 vim_memset(newp + STRLEN(newp), c, (size_t)numc); |
5428 | 2122 if (!bd.is_short) |
2123 { | |
2124 /* insert post-spaces */ | |
6929 | 2125 vim_memset(newp + STRLEN(newp), ' ', (size_t)bd.endspaces); |
5428 | 2126 /* copy the part after the changed part */ |
2127 STRMOVE(newp + STRLEN(newp), oldp); | |
2128 } | |
7 | 2129 } |
2130 else | |
2131 { | |
5428 | 2132 /* Replacing with \r or \n means splitting the line. */ |
5475 | 2133 after_p = alloc_check( |
2134 (unsigned)(oldlen + 1 + n - STRLEN(newp))); | |
5428 | 2135 if (after_p != NULL) |
2136 STRMOVE(after_p, oldp); | |
7 | 2137 } |
2138 /* replace the line */ | |
2139 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
5428 | 2140 if (after_p != NULL) |
2141 { | |
2142 ml_append(curwin->w_cursor.lnum++, after_p, 0, FALSE); | |
2143 appended_lines_mark(curwin->w_cursor.lnum, 1L); | |
2144 oap->end.lnum++; | |
2145 vim_free(after_p); | |
2146 } | |
7 | 2147 } |
2148 } | |
2149 else | |
2150 { | |
2151 /* | |
2152 * MCHAR and MLINE motion replace. | |
2153 */ | |
2154 if (oap->motion_type == MLINE) | |
2155 { | |
2156 oap->start.col = 0; | |
2157 curwin->w_cursor.col = 0; | |
2158 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
2159 if (oap->end.col) | |
2160 --oap->end.col; | |
2161 } | |
2162 else if (!oap->inclusive) | |
2163 dec(&(oap->end)); | |
2164 | |
2165 while (ltoreq(curwin->w_cursor, oap->end)) | |
2166 { | |
2167 n = gchar_cursor(); | |
2168 if (n != NUL) | |
2169 { | |
2170 #ifdef FEAT_MBYTE | |
2171 if ((*mb_char2len)(c) > 1 || (*mb_char2len)(n) > 1) | |
2172 { | |
2173 /* This is slow, but it handles replacing a single-byte | |
2174 * with a multi-byte and the other way around. */ | |
4203 | 2175 if (curwin->w_cursor.lnum == oap->end.lnum) |
2176 oap->end.col += (*mb_char2len)(c) - (*mb_char2len)(n); | |
7 | 2177 n = State; |
2178 State = REPLACE; | |
2179 ins_char(c); | |
2180 State = n; | |
2181 /* Backup to the replaced character. */ | |
2182 dec_cursor(); | |
2183 } | |
2184 else | |
2185 #endif | |
2186 { | |
2187 #ifdef FEAT_VIRTUALEDIT | |
2188 if (n == TAB) | |
2189 { | |
2190 int end_vcol = 0; | |
2191 | |
2192 if (curwin->w_cursor.lnum == oap->end.lnum) | |
2193 { | |
2194 /* oap->end has to be recalculated when | |
2195 * the tab breaks */ | |
2196 end_vcol = getviscol2(oap->end.col, | |
2197 oap->end.coladd); | |
2198 } | |
2199 coladvance_force(getviscol()); | |
2200 if (curwin->w_cursor.lnum == oap->end.lnum) | |
2201 getvpos(&oap->end, end_vcol); | |
2202 } | |
2203 #endif | |
2204 pchar(curwin->w_cursor, c); | |
2205 } | |
2206 } | |
2207 #ifdef FEAT_VIRTUALEDIT | |
2208 else if (virtual_op && curwin->w_cursor.lnum == oap->end.lnum) | |
2209 { | |
2210 int virtcols = oap->end.coladd; | |
2211 | |
2212 if (curwin->w_cursor.lnum == oap->start.lnum | |
2213 && oap->start.col == oap->end.col && oap->start.coladd) | |
2214 virtcols -= oap->start.coladd; | |
2215 | |
2216 /* oap->end has been trimmed so it's effectively inclusive; | |
2217 * as a result an extra +1 must be counted so we don't | |
2218 * trample the NUL byte. */ | |
2219 coladvance_force(getviscol2(oap->end.col, oap->end.coladd) + 1); | |
2220 curwin->w_cursor.col -= (virtcols + 1); | |
2221 for (; virtcols >= 0; virtcols--) | |
2222 { | |
2223 pchar(curwin->w_cursor, c); | |
2224 if (inc(&curwin->w_cursor) == -1) | |
2225 break; | |
2226 } | |
2227 } | |
2228 #endif | |
2229 | |
2230 /* Advance to next character, stop at the end of the file. */ | |
2231 if (inc_cursor() == -1) | |
2232 break; | |
2233 } | |
2234 } | |
2235 | |
2236 curwin->w_cursor = oap->start; | |
2237 check_cursor(); | |
2238 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, 0L); | |
2239 | |
2240 /* Set "'[" and "']" marks. */ | |
2241 curbuf->b_op_start = oap->start; | |
2242 curbuf->b_op_end = oap->end; | |
2243 | |
2244 return OK; | |
2245 } | |
2246 #endif | |
2247 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
2248 static int swapchars(int op_type, pos_T *pos, int length); |
1525 | 2249 |
7 | 2250 /* |
2251 * Handle the (non-standard vi) tilde operator. Also for "gu", "gU" and "g?". | |
2252 */ | |
2253 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2254 op_tilde(oparg_T *oap) |
7 | 2255 { |
2256 pos_T pos; | |
2257 struct block_def bd; | |
1528 | 2258 int did_change = FALSE; |
7 | 2259 |
2260 if (u_save((linenr_T)(oap->start.lnum - 1), | |
2261 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
2262 return; | |
2263 | |
2264 pos = oap->start; | |
2265 if (oap->block_mode) /* Visual block mode */ | |
2266 { | |
2267 for (; pos.lnum <= oap->end.lnum; ++pos.lnum) | |
2268 { | |
1766 | 2269 int one_change; |
2270 | |
7 | 2271 block_prep(oap, &bd, pos.lnum, FALSE); |
2272 pos.col = bd.textcol; | |
1766 | 2273 one_change = swapchars(oap->op_type, &pos, bd.textlen); |
2274 did_change |= one_change; | |
1525 | 2275 |
5735 | 2276 #ifdef FEAT_NETBEANS_INTG |
2210 | 2277 if (netbeans_active() && one_change) |
7 | 2278 { |
2279 char_u *ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
2280 | |
33 | 2281 netbeans_removed(curbuf, pos.lnum, bd.textcol, |
2282 (long)bd.textlen); | |
7 | 2283 netbeans_inserted(curbuf, pos.lnum, bd.textcol, |
2210 | 2284 &ptr[bd.textcol], bd.textlen); |
7 | 2285 } |
5735 | 2286 #endif |
7 | 2287 } |
2288 if (did_change) | |
2289 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); | |
2290 } | |
2291 else /* not block mode */ | |
2292 { | |
2293 if (oap->motion_type == MLINE) | |
2294 { | |
2295 oap->start.col = 0; | |
2296 pos.col = 0; | |
2297 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
2298 if (oap->end.col) | |
2299 --oap->end.col; | |
2300 } | |
2301 else if (!oap->inclusive) | |
2302 dec(&(oap->end)); | |
2303 | |
1528 | 2304 if (pos.lnum == oap->end.lnum) |
2305 did_change = swapchars(oap->op_type, &pos, | |
2306 oap->end.col - pos.col + 1); | |
2307 else | |
2308 for (;;) | |
2309 { | |
2310 did_change |= swapchars(oap->op_type, &pos, | |
2311 pos.lnum == oap->end.lnum ? oap->end.col + 1: | |
2312 (int)STRLEN(ml_get_pos(&pos))); | |
2313 if (ltoreq(oap->end, pos) || inc(&pos) == -1) | |
2314 break; | |
2315 } | |
7 | 2316 if (did_change) |
2317 { | |
2318 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, | |
2319 0L); | |
2320 #ifdef FEAT_NETBEANS_INTG | |
2210 | 2321 if (netbeans_active() && did_change) |
7 | 2322 { |
2323 char_u *ptr; | |
2324 int count; | |
2325 | |
2326 pos = oap->start; | |
2327 while (pos.lnum < oap->end.lnum) | |
2328 { | |
2329 ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
835 | 2330 count = (int)STRLEN(ptr) - pos.col; |
33 | 2331 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7 | 2332 netbeans_inserted(curbuf, pos.lnum, pos.col, |
2210 | 2333 &ptr[pos.col], count); |
7 | 2334 pos.col = 0; |
2335 pos.lnum++; | |
2336 } | |
2337 ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
2338 count = oap->end.col - pos.col + 1; | |
33 | 2339 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7 | 2340 netbeans_inserted(curbuf, pos.lnum, pos.col, |
2210 | 2341 &ptr[pos.col], count); |
7 | 2342 } |
2343 #endif | |
2344 } | |
2345 } | |
2346 | |
2347 if (!did_change && oap->is_VIsual) | |
2348 /* No change: need to remove the Visual selection */ | |
2349 redraw_curbuf_later(INVERTED); | |
2350 | |
2351 /* | |
2352 * Set '[ and '] marks. | |
2353 */ | |
2354 curbuf->b_op_start = oap->start; | |
2355 curbuf->b_op_end = oap->end; | |
2356 | |
2357 if (oap->line_count > p_report) | |
2358 { | |
2359 if (oap->line_count == 1) | |
2360 MSG(_("1 line changed")); | |
2361 else | |
2362 smsg((char_u *)_("%ld lines changed"), oap->line_count); | |
2363 } | |
2364 } | |
2365 | |
2366 /* | |
1525 | 2367 * Invoke swapchar() on "length" bytes at position "pos". |
2368 * "pos" is advanced to just after the changed characters. | |
2369 * "length" is rounded up to include the whole last multi-byte character. | |
2370 * Also works correctly when the number of bytes changes. | |
2371 * Returns TRUE if some character was changed. | |
2372 */ | |
2373 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2374 swapchars(int op_type, pos_T *pos, int length) |
1525 | 2375 { |
2376 int todo; | |
2377 int did_change = 0; | |
2378 | |
2379 for (todo = length; todo > 0; --todo) | |
2380 { | |
2381 # ifdef FEAT_MBYTE | |
2382 if (has_mbyte) | |
5288
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2383 { |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2384 int len = (*mb_ptr2len)(ml_get_pos(pos)); |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2385 |
1525 | 2386 /* we're counting bytes, not characters */ |
5288
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2387 if (len > 0) |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2388 todo -= len - 1; |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2389 } |
1525 | 2390 # endif |
2391 did_change |= swapchar(op_type, pos); | |
2392 if (inc(pos) == -1) /* at end of file */ | |
2393 break; | |
2394 } | |
2395 return did_change; | |
2396 } | |
2397 | |
2398 /* | |
7 | 2399 * If op_type == OP_UPPER: make uppercase, |
2400 * if op_type == OP_LOWER: make lowercase, | |
2401 * if op_type == OP_ROT13: do rot13 encoding, | |
2402 * else swap case of character at 'pos' | |
2403 * returns TRUE when something actually changed. | |
2404 */ | |
2405 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2406 swapchar(int op_type, pos_T *pos) |
7 | 2407 { |
2408 int c; | |
2409 int nc; | |
2410 | |
2411 c = gchar_pos(pos); | |
2412 | |
2413 /* Only do rot13 encoding for ASCII characters. */ | |
2414 if (c >= 0x80 && op_type == OP_ROT13) | |
2415 return FALSE; | |
2416 | |
2417 #ifdef FEAT_MBYTE | |
1525 | 2418 if (op_type == OP_UPPER && c == 0xdf |
2419 && (enc_latin1like || STRCMP(p_enc, "iso-8859-2") == 0)) | |
493 | 2420 { |
2421 pos_T sp = curwin->w_cursor; | |
2422 | |
2423 /* Special handling of German sharp s: change to "SS". */ | |
2424 curwin->w_cursor = *pos; | |
2425 del_char(FALSE); | |
2426 ins_char('S'); | |
2427 ins_char('S'); | |
2428 curwin->w_cursor = sp; | |
2429 inc(pos); | |
2430 } | |
2431 | |
7 | 2432 if (enc_dbcs != 0 && c >= 0x100) /* No lower/uppercase letter */ |
2433 return FALSE; | |
2434 #endif | |
2435 nc = c; | |
2436 if (MB_ISLOWER(c)) | |
2437 { | |
2438 if (op_type == OP_ROT13) | |
2439 nc = ROT13(c, 'a'); | |
2440 else if (op_type != OP_LOWER) | |
2441 nc = MB_TOUPPER(c); | |
2442 } | |
2443 else if (MB_ISUPPER(c)) | |
2444 { | |
2445 if (op_type == OP_ROT13) | |
2446 nc = ROT13(c, 'A'); | |
2447 else if (op_type != OP_UPPER) | |
2448 nc = MB_TOLOWER(c); | |
2449 } | |
2450 if (nc != c) | |
2451 { | |
2452 #ifdef FEAT_MBYTE | |
2453 if (enc_utf8 && (c >= 0x80 || nc >= 0x80)) | |
2454 { | |
2455 pos_T sp = curwin->w_cursor; | |
2456 | |
2457 curwin->w_cursor = *pos; | |
2451
0b8612c2814d
Fix: changing case of a character removed combining characters.
Bram Moolenaar <bram@vim.org>
parents:
2446
diff
changeset
|
2458 /* don't use del_char(), it also removes composing chars */ |
0b8612c2814d
Fix: changing case of a character removed combining characters.
Bram Moolenaar <bram@vim.org>
parents:
2446
diff
changeset
|
2459 del_bytes(utf_ptr2len(ml_get_cursor()), FALSE, FALSE); |
7 | 2460 ins_char(nc); |
2461 curwin->w_cursor = sp; | |
2462 } | |
2463 else | |
2464 #endif | |
2465 pchar(*pos, nc); | |
2466 return TRUE; | |
2467 } | |
2468 return FALSE; | |
2469 } | |
2470 | |
2471 #if defined(FEAT_VISUALEXTRA) || defined(PROTO) | |
2472 /* | |
2473 * op_insert - Insert and append operators for Visual mode. | |
2474 */ | |
2475 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2476 op_insert(oparg_T *oap, long count1) |
7 | 2477 { |
2478 long ins_len, pre_textlen = 0; | |
2479 char_u *firstline, *ins_text; | |
2480 struct block_def bd; | |
2481 int i; | |
6579 | 2482 pos_T t1; |
7 | 2483 |
2484 /* edit() changes this - record it for OP_APPEND */ | |
2485 bd.is_MAX = (curwin->w_curswant == MAXCOL); | |
2486 | |
2487 /* vis block is still marked. Get rid of it now. */ | |
2488 curwin->w_cursor.lnum = oap->start.lnum; | |
2489 update_screen(INVERTED); | |
2490 | |
2491 if (oap->block_mode) | |
2492 { | |
2493 #ifdef FEAT_VIRTUALEDIT | |
2494 /* When 'virtualedit' is used, need to insert the extra spaces before | |
2495 * doing block_prep(). When only "block" is used, virtual edit is | |
2496 * already disabled, but still need it when calling | |
2497 * coladvance_force(). */ | |
2498 if (curwin->w_cursor.coladd > 0) | |
2499 { | |
2500 int old_ve_flags = ve_flags; | |
2501 | |
2502 ve_flags = VE_ALL; | |
2503 if (u_save_cursor() == FAIL) | |
2504 return; | |
2505 coladvance_force(oap->op_type == OP_APPEND | |
2506 ? oap->end_vcol + 1 : getviscol()); | |
2507 if (oap->op_type == OP_APPEND) | |
2508 --curwin->w_cursor.col; | |
2509 ve_flags = old_ve_flags; | |
2510 } | |
2511 #endif | |
2512 /* Get the info about the block before entering the text */ | |
2513 block_prep(oap, &bd, oap->start.lnum, TRUE); | |
2514 firstline = ml_get(oap->start.lnum) + bd.textcol; | |
2515 if (oap->op_type == OP_APPEND) | |
2516 firstline += bd.textlen; | |
2517 pre_textlen = (long)STRLEN(firstline); | |
2518 } | |
2519 | |
2520 if (oap->op_type == OP_APPEND) | |
2521 { | |
2522 if (oap->block_mode | |
2523 #ifdef FEAT_VIRTUALEDIT | |
2524 && curwin->w_cursor.coladd == 0 | |
2525 #endif | |
2526 ) | |
2527 { | |
2528 /* Move the cursor to the character right of the block. */ | |
2529 curwin->w_set_curswant = TRUE; | |
2530 while (*ml_get_cursor() != NUL | |
2531 && (curwin->w_cursor.col < bd.textcol + bd.textlen)) | |
2532 ++curwin->w_cursor.col; | |
2533 if (bd.is_short && !bd.is_MAX) | |
2534 { | |
2535 /* First line was too short, make it longer and adjust the | |
2536 * values in "bd". */ | |
2537 if (u_save_cursor() == FAIL) | |
2538 return; | |
2539 for (i = 0; i < bd.endspaces; ++i) | |
2540 ins_char(' '); | |
2541 bd.textlen += bd.endspaces; | |
2542 } | |
2543 } | |
2544 else | |
2545 { | |
2546 curwin->w_cursor = oap->end; | |
893 | 2547 check_cursor_col(); |
7 | 2548 |
2549 /* Works just like an 'i'nsert on the next character. */ | |
2550 if (!lineempty(curwin->w_cursor.lnum) | |
2551 && oap->start_vcol != oap->end_vcol) | |
2552 inc_cursor(); | |
2553 } | |
2554 } | |
2555 | |
6579 | 2556 t1 = oap->start; |
7 | 2557 edit(NUL, FALSE, (linenr_T)count1); |
2558 | |
6579 | 2559 /* When a tab was inserted, and the characters in front of the tab |
2560 * have been converted to a tab as well, the column of the cursor | |
2561 * might have actually been reduced, so need to adjust here. */ | |
2562 if (t1.lnum == curbuf->b_op_start_orig.lnum | |
2563 && lt(curbuf->b_op_start_orig, t1)) | |
2564 oap->start = curbuf->b_op_start_orig; | |
2565 | |
1477 | 2566 /* If user has moved off this line, we don't know what to do, so do |
2567 * nothing. | |
2568 * Also don't repeat the insert when Insert mode ended with CTRL-C. */ | |
2569 if (curwin->w_cursor.lnum != oap->start.lnum || got_int) | |
7 | 2570 return; |
2571 | |
2572 if (oap->block_mode) | |
2573 { | |
2574 struct block_def bd2; | |
2575 | |
5471 | 2576 /* The user may have moved the cursor before inserting something, try |
2577 * to adjust the block for that. */ | |
5680 | 2578 if (oap->start.lnum == curbuf->b_op_start_orig.lnum && !bd.is_MAX) |
5471 | 2579 { |
2580 if (oap->op_type == OP_INSERT | |
5730 | 2581 && oap->start.col |
2582 #ifdef FEAT_VIRTUALEDIT | |
2583 + oap->start.coladd | |
2584 #endif | |
2585 != curbuf->b_op_start_orig.col | |
2586 #ifdef FEAT_VIRTUALEDIT | |
2587 + curbuf->b_op_start_orig.coladd | |
2588 #endif | |
2589 ) | |
5471 | 2590 { |
6579 | 2591 int t = getviscol2(curbuf->b_op_start_orig.col, |
2592 curbuf->b_op_start_orig.coladd); | |
5680 | 2593 oap->start.col = curbuf->b_op_start_orig.col; |
6579 | 2594 pre_textlen -= t - oap->start_vcol; |
2595 oap->start_vcol = t; | |
5471 | 2596 } |
2597 else if (oap->op_type == OP_APPEND | |
5730 | 2598 && oap->end.col |
2599 #ifdef FEAT_VIRTUALEDIT | |
2600 + oap->end.coladd | |
2601 #endif | |
2602 >= curbuf->b_op_start_orig.col | |
2603 #ifdef FEAT_VIRTUALEDIT | |
2604 + curbuf->b_op_start_orig.coladd | |
2605 #endif | |
2606 ) | |
5471 | 2607 { |
6579 | 2608 int t = getviscol2(curbuf->b_op_start_orig.col, |
2609 curbuf->b_op_start_orig.coladd); | |
5680 | 2610 oap->start.col = curbuf->b_op_start_orig.col; |
5471 | 2611 /* reset pre_textlen to the value of OP_INSERT */ |
2612 pre_textlen += bd.textlen; | |
6579 | 2613 pre_textlen -= t - oap->start_vcol; |
2614 oap->start_vcol = t; | |
5471 | 2615 oap->op_type = OP_INSERT; |
2616 } | |
2617 } | |
2618 | |
7 | 2619 /* |
2620 * Spaces and tabs in the indent may have changed to other spaces and | |
1392 | 2621 * tabs. Get the starting column again and correct the length. |
7 | 2622 * Don't do this when "$" used, end-of-line will have changed. |
2623 */ | |
2624 block_prep(oap, &bd2, oap->start.lnum, TRUE); | |
2625 if (!bd.is_MAX || bd2.textlen < bd.textlen) | |
2626 { | |
2627 if (oap->op_type == OP_APPEND) | |
2628 { | |
2629 pre_textlen += bd2.textlen - bd.textlen; | |
2630 if (bd2.endspaces) | |
2631 --bd2.textlen; | |
2632 } | |
2633 bd.textcol = bd2.textcol; | |
2634 bd.textlen = bd2.textlen; | |
2635 } | |
2636 | |
2637 /* | |
2638 * Subsequent calls to ml_get() flush the firstline data - take a | |
2639 * copy of the required string. | |
2640 */ | |
2641 firstline = ml_get(oap->start.lnum) + bd.textcol; | |
2642 if (oap->op_type == OP_APPEND) | |
2643 firstline += bd.textlen; | |
3421 | 2644 if (pre_textlen >= 0 |
2645 && (ins_len = (long)STRLEN(firstline) - pre_textlen) > 0) | |
7 | 2646 { |
2647 ins_text = vim_strnsave(firstline, (int)ins_len); | |
2648 if (ins_text != NULL) | |
2649 { | |
2650 /* block handled here */ | |
2651 if (u_save(oap->start.lnum, | |
2652 (linenr_T)(oap->end.lnum + 1)) == OK) | |
2653 block_insert(oap, ins_text, (oap->op_type == OP_INSERT), | |
2654 &bd); | |
2655 | |
2656 curwin->w_cursor.col = oap->start.col; | |
2657 check_cursor(); | |
2658 vim_free(ins_text); | |
2659 } | |
2660 } | |
2661 } | |
2662 } | |
2663 #endif | |
2664 | |
2665 /* | |
2666 * op_change - handle a change operation | |
2667 * | |
2668 * return TRUE if edit() returns because of a CTRL-O command | |
2669 */ | |
2670 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2671 op_change(oparg_T *oap) |
7 | 2672 { |
2673 colnr_T l; | |
2674 int retval; | |
2675 #ifdef FEAT_VISUALEXTRA | |
2676 long offset; | |
2677 linenr_T linenr; | |
1392 | 2678 long ins_len; |
2679 long pre_textlen = 0; | |
2680 long pre_indent = 0; | |
7 | 2681 char_u *firstline; |
2682 char_u *ins_text, *newp, *oldp; | |
2683 struct block_def bd; | |
2684 #endif | |
2685 | |
2686 l = oap->start.col; | |
2687 if (oap->motion_type == MLINE) | |
2688 { | |
2689 l = 0; | |
2690 #ifdef FEAT_SMARTINDENT | |
2691 if (!p_paste && curbuf->b_p_si | |
2692 # ifdef FEAT_CINDENT | |
2693 && !curbuf->b_p_cin | |
2694 # endif | |
2695 ) | |
2696 can_si = TRUE; /* It's like opening a new line, do si */ | |
2697 #endif | |
2698 } | |
2699 | |
2700 /* First delete the text in the region. In an empty buffer only need to | |
2701 * save for undo */ | |
2702 if (curbuf->b_ml.ml_flags & ML_EMPTY) | |
2703 { | |
2704 if (u_save_cursor() == FAIL) | |
2705 return FALSE; | |
2706 } | |
2707 else if (op_delete(oap) == FAIL) | |
2708 return FALSE; | |
2709 | |
2710 if ((l > curwin->w_cursor.col) && !lineempty(curwin->w_cursor.lnum) | |
2711 && !virtual_op) | |
2712 inc_cursor(); | |
2713 | |
2714 #ifdef FEAT_VISUALEXTRA | |
2715 /* check for still on same line (<CR> in inserted text meaningless) */ | |
2716 /* skip blank lines too */ | |
2717 if (oap->block_mode) | |
2718 { | |
2719 # ifdef FEAT_VIRTUALEDIT | |
2720 /* Add spaces before getting the current line length. */ | |
2721 if (virtual_op && (curwin->w_cursor.coladd > 0 | |
2722 || gchar_cursor() == NUL)) | |
2723 coladvance_force(getviscol()); | |
2724 # endif | |
1392 | 2725 firstline = ml_get(oap->start.lnum); |
2726 pre_textlen = (long)STRLEN(firstline); | |
2727 pre_indent = (long)(skipwhite(firstline) - firstline); | |
7 | 2728 bd.textcol = curwin->w_cursor.col; |
2729 } | |
2730 #endif | |
2731 | |
2732 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) | |
2733 if (oap->motion_type == MLINE) | |
2734 fix_indent(); | |
2735 #endif | |
2736 | |
2737 retval = edit(NUL, FALSE, (linenr_T)1); | |
2738 | |
2739 #ifdef FEAT_VISUALEXTRA | |
2740 /* | |
39 | 2741 * In Visual block mode, handle copying the new text to all lines of the |
7 | 2742 * block. |
1477 | 2743 * Don't repeat the insert when Insert mode ended with CTRL-C. |
7 | 2744 */ |
1477 | 2745 if (oap->block_mode && oap->start.lnum != oap->end.lnum && !got_int) |
7 | 2746 { |
1392 | 2747 /* Auto-indenting may have changed the indent. If the cursor was past |
2748 * the indent, exclude that indent change from the inserted text. */ | |
7 | 2749 firstline = ml_get(oap->start.lnum); |
1403 | 2750 if (bd.textcol > (colnr_T)pre_indent) |
7 | 2751 { |
1392 | 2752 long new_indent = (long)(skipwhite(firstline) - firstline); |
2753 | |
2754 pre_textlen += new_indent - pre_indent; | |
2755 bd.textcol += new_indent - pre_indent; | |
2756 } | |
2757 | |
2758 ins_len = (long)STRLEN(firstline) - pre_textlen; | |
2759 if (ins_len > 0) | |
2760 { | |
2761 /* Subsequent calls to ml_get() flush the firstline data - take a | |
2762 * copy of the inserted text. */ | |
7 | 2763 if ((ins_text = alloc_check((unsigned)(ins_len + 1))) != NULL) |
2764 { | |
419 | 2765 vim_strncpy(ins_text, firstline + bd.textcol, (size_t)ins_len); |
7 | 2766 for (linenr = oap->start.lnum + 1; linenr <= oap->end.lnum; |
2767 linenr++) | |
2768 { | |
2769 block_prep(oap, &bd, linenr, TRUE); | |
2770 if (!bd.is_short || virtual_op) | |
2771 { | |
2772 # ifdef FEAT_VIRTUALEDIT | |
2773 pos_T vpos; | |
2774 | |
2775 /* If the block starts in virtual space, count the | |
2776 * initial coladd offset as part of "startspaces" */ | |
2777 if (bd.is_short) | |
2778 { | |
1982 | 2779 vpos.lnum = linenr; |
7 | 2780 (void)getvpos(&vpos, oap->start_vcol); |
2781 } | |
2782 else | |
2783 vpos.coladd = 0; | |
2784 # endif | |
2785 oldp = ml_get(linenr); | |
2786 newp = alloc_check((unsigned)(STRLEN(oldp) | |
2787 # ifdef FEAT_VIRTUALEDIT | |
2788 + vpos.coladd | |
2789 # endif | |
2790 + ins_len + 1)); | |
2791 if (newp == NULL) | |
2792 continue; | |
2793 /* copy up to block start */ | |
2794 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
2795 offset = bd.textcol; | |
2796 # ifdef FEAT_VIRTUALEDIT | |
6929 | 2797 vim_memset(newp + offset, ' ', (size_t)vpos.coladd); |
7 | 2798 offset += vpos.coladd; |
2799 # endif | |
2800 mch_memmove(newp + offset, ins_text, (size_t)ins_len); | |
2801 offset += ins_len; | |
2802 oldp += bd.textcol; | |
1622 | 2803 STRMOVE(newp + offset, oldp); |
7 | 2804 ml_replace(linenr, newp, FALSE); |
2805 } | |
2806 } | |
2807 check_cursor(); | |
2808 | |
2809 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); | |
2810 } | |
2811 vim_free(ins_text); | |
2812 } | |
2813 } | |
2814 #endif | |
2815 | |
2816 return retval; | |
2817 } | |
2818 | |
2819 /* | |
2820 * set all the yank registers to empty (called from main()) | |
2821 */ | |
2822 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2823 init_yank(void) |
7 | 2824 { |
2825 int i; | |
2826 | |
2827 for (i = 0; i < NUM_REGISTERS; ++i) | |
2828 y_regs[i].y_array = NULL; | |
2829 } | |
2830 | |
356 | 2831 #if defined(EXITFREE) || defined(PROTO) |
2832 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2833 clear_registers(void) |
356 | 2834 { |
2835 int i; | |
2836 | |
2837 for (i = 0; i < NUM_REGISTERS; ++i) | |
2838 { | |
2839 y_current = &y_regs[i]; | |
2840 if (y_current->y_array != NULL) | |
2841 free_yank_all(); | |
2842 } | |
2843 } | |
2844 #endif | |
2845 | |
7 | 2846 /* |
2847 * Free "n" lines from the current yank register. | |
2848 * Called for normal freeing and in case of error. | |
2849 */ | |
2850 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2851 free_yank(long n) |
7 | 2852 { |
2853 if (y_current->y_array != NULL) | |
2854 { | |
2855 long i; | |
2856 | |
2857 for (i = n; --i >= 0; ) | |
2858 { | |
2859 #ifdef AMIGA /* only for very slow machines */ | |
2860 if ((i & 1023) == 1023) /* this may take a while */ | |
2861 { | |
2862 /* | |
2863 * This message should never cause a hit-return message. | |
2864 * Overwrite this message with any next message. | |
2865 */ | |
2866 ++no_wait_return; | |
2867 smsg((char_u *)_("freeing %ld lines"), i + 1); | |
2868 --no_wait_return; | |
2869 msg_didout = FALSE; | |
2870 msg_col = 0; | |
2871 } | |
2872 #endif | |
2873 vim_free(y_current->y_array[i]); | |
2874 } | |
2875 vim_free(y_current->y_array); | |
2876 y_current->y_array = NULL; | |
2877 #ifdef AMIGA | |
2878 if (n >= 1000) | |
2879 MSG(""); | |
2880 #endif | |
2881 } | |
2882 } | |
2883 | |
2884 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2885 free_yank_all(void) |
7 | 2886 { |
2887 free_yank(y_current->y_size); | |
2888 } | |
2889 | |
2890 /* | |
2891 * Yank the text between "oap->start" and "oap->end" into a yank register. | |
2892 * If we are to append (uppercase register), we first yank into a new yank | |
2893 * register and then concatenate the old and the new one (so we keep the old | |
2894 * one in case of out-of-memory). | |
2895 * | |
5245
8c6615a30951
updated for version 7.4a.047
Bram Moolenaar <bram@vim.org>
parents:
5182
diff
changeset
|
2896 * Return FAIL for failure, OK otherwise. |
7 | 2897 */ |
2898 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2899 op_yank(oparg_T *oap, int deleting, int mess) |
7 | 2900 { |
2901 long y_idx; /* index in y_array[] */ | |
2902 struct yankreg *curr; /* copy of y_current */ | |
2903 struct yankreg newreg; /* new yank register when appending */ | |
2904 char_u **new_ptr; | |
2905 linenr_T lnum; /* current line number */ | |
2906 long j; | |
2907 int yanktype = oap->motion_type; | |
2908 long yanklines = oap->line_count; | |
2909 linenr_T yankendlnum = oap->end.lnum; | |
2910 char_u *p; | |
2911 char_u *pnew; | |
2912 struct block_def bd; | |
2658 | 2913 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
2654 | 2914 int did_star = FALSE; |
2658 | 2915 #endif |
7 | 2916 |
2917 /* check for read-only register */ | |
2918 if (oap->regname != 0 && !valid_yank_reg(oap->regname, TRUE)) | |
2919 { | |
2920 beep_flush(); | |
2921 return FAIL; | |
2922 } | |
2923 if (oap->regname == '_') /* black hole: nothing to do */ | |
2924 return OK; | |
2925 | |
2926 #ifdef FEAT_CLIPBOARD | |
2927 if (!clip_star.available && oap->regname == '*') | |
2928 oap->regname = 0; | |
2929 else if (!clip_plus.available && oap->regname == '+') | |
2930 oap->regname = 0; | |
2931 #endif | |
2932 | |
2933 if (!deleting) /* op_delete() already set y_current */ | |
2934 get_yank_register(oap->regname, TRUE); | |
2935 | |
2936 curr = y_current; | |
2937 /* append to existing contents */ | |
2938 if (y_append && y_current->y_array != NULL) | |
2939 y_current = &newreg; | |
2940 else | |
2941 free_yank_all(); /* free previously yanked lines */ | |
2942 | |
593 | 2943 /* |
2944 * If the cursor was in column 1 before and after the movement, and the | |
2945 * operator is not inclusive, the yank is always linewise. | |
2946 */ | |
7 | 2947 if ( oap->motion_type == MCHAR |
2948 && oap->start.col == 0 | |
2949 && !oap->inclusive | |
2950 && (!oap->is_VIsual || *p_sel == 'o') | |
50 | 2951 && !oap->block_mode |
7 | 2952 && oap->end.col == 0 |
2953 && yanklines > 1) | |
2954 { | |
2955 yanktype = MLINE; | |
2956 --yankendlnum; | |
2957 --yanklines; | |
2958 } | |
2959 | |
2960 y_current->y_size = yanklines; | |
2961 y_current->y_type = yanktype; /* set the yank register type */ | |
2962 y_current->y_width = 0; | |
2963 y_current->y_array = (char_u **)lalloc_clear((long_u)(sizeof(char_u *) * | |
2964 yanklines), TRUE); | |
2965 | |
2966 if (y_current->y_array == NULL) | |
2967 { | |
2968 y_current = curr; | |
2969 return FAIL; | |
2970 } | |
2971 | |
2972 y_idx = 0; | |
2973 lnum = oap->start.lnum; | |
2974 | |
2975 if (oap->block_mode) | |
2976 { | |
2977 /* Visual block mode */ | |
2978 y_current->y_type = MBLOCK; /* set the yank register type */ | |
2979 y_current->y_width = oap->end_vcol - oap->start_vcol; | |
2980 | |
2981 if (curwin->w_curswant == MAXCOL && y_current->y_width > 0) | |
2982 y_current->y_width--; | |
2983 } | |
2984 | |
2985 for ( ; lnum <= yankendlnum; lnum++, y_idx++) | |
2986 { | |
2987 switch (y_current->y_type) | |
2988 { | |
2989 case MBLOCK: | |
2990 block_prep(oap, &bd, lnum, FALSE); | |
2991 if (yank_copy_line(&bd, y_idx) == FAIL) | |
2992 goto fail; | |
2993 break; | |
2994 | |
2995 case MLINE: | |
2996 if ((y_current->y_array[y_idx] = | |
2997 vim_strsave(ml_get(lnum))) == NULL) | |
2998 goto fail; | |
2999 break; | |
3000 | |
3001 case MCHAR: | |
3002 { | |
3003 colnr_T startcol = 0, endcol = MAXCOL; | |
3004 #ifdef FEAT_VIRTUALEDIT | |
3005 int is_oneChar = FALSE; | |
3006 colnr_T cs, ce; | |
3007 #endif | |
3008 p = ml_get(lnum); | |
3009 bd.startspaces = 0; | |
3010 bd.endspaces = 0; | |
3011 | |
3012 if (lnum == oap->start.lnum) | |
3013 { | |
3014 startcol = oap->start.col; | |
3015 #ifdef FEAT_VIRTUALEDIT | |
3016 if (virtual_op) | |
3017 { | |
3018 getvcol(curwin, &oap->start, &cs, NULL, &ce); | |
3019 if (ce != cs && oap->start.coladd > 0) | |
3020 { | |
3021 /* Part of a tab selected -- but don't | |
3022 * double-count it. */ | |
3023 bd.startspaces = (ce - cs + 1) | |
3024 - oap->start.coladd; | |
3025 startcol++; | |
3026 } | |
3027 } | |
3028 #endif | |
3029 } | |
3030 | |
3031 if (lnum == oap->end.lnum) | |
3032 { | |
3033 endcol = oap->end.col; | |
3034 #ifdef FEAT_VIRTUALEDIT | |
3035 if (virtual_op) | |
3036 { | |
3037 getvcol(curwin, &oap->end, &cs, NULL, &ce); | |
3038 if (p[endcol] == NUL || (cs + oap->end.coladd < ce | |
3039 # ifdef FEAT_MBYTE | |
3040 /* Don't add space for double-wide | |
3041 * char; endcol will be on last byte | |
3042 * of multi-byte char. */ | |
3043 && (*mb_head_off)(p, p + endcol) == 0 | |
3044 # endif | |
3045 )) | |
3046 { | |
3047 if (oap->start.lnum == oap->end.lnum | |
3048 && oap->start.col == oap->end.col) | |
3049 { | |
3050 /* Special case: inside a single char */ | |
3051 is_oneChar = TRUE; | |
3052 bd.startspaces = oap->end.coladd | |
3053 - oap->start.coladd + oap->inclusive; | |
3054 endcol = startcol; | |
3055 } | |
3056 else | |
3057 { | |
3058 bd.endspaces = oap->end.coladd | |
3059 + oap->inclusive; | |
3060 endcol -= oap->inclusive; | |
3061 } | |
3062 } | |
3063 } | |
3064 #endif | |
3065 } | |
3510 | 3066 if (endcol == MAXCOL) |
3067 endcol = (colnr_T)STRLEN(p); | |
7 | 3068 if (startcol > endcol |
3069 #ifdef FEAT_VIRTUALEDIT | |
3070 || is_oneChar | |
3071 #endif | |
3072 ) | |
3073 bd.textlen = 0; | |
3074 else | |
3075 { | |
3076 bd.textlen = endcol - startcol + oap->inclusive; | |
3077 } | |
3078 bd.textstart = p + startcol; | |
3079 if (yank_copy_line(&bd, y_idx) == FAIL) | |
3080 goto fail; | |
3081 break; | |
3082 } | |
3083 /* NOTREACHED */ | |
3084 } | |
3085 } | |
3086 | |
3087 if (curr != y_current) /* append the new block to the old block */ | |
3088 { | |
3089 new_ptr = (char_u **)lalloc((long_u)(sizeof(char_u *) * | |
3090 (curr->y_size + y_current->y_size)), TRUE); | |
3091 if (new_ptr == NULL) | |
3092 goto fail; | |
3093 for (j = 0; j < curr->y_size; ++j) | |
3094 new_ptr[j] = curr->y_array[j]; | |
3095 vim_free(curr->y_array); | |
3096 curr->y_array = new_ptr; | |
3097 | |
3098 if (yanktype == MLINE) /* MLINE overrides MCHAR and MBLOCK */ | |
3099 curr->y_type = MLINE; | |
3100 | |
164 | 3101 /* Concatenate the last line of the old block with the first line of |
3102 * the new block, unless being Vi compatible. */ | |
3103 if (curr->y_type == MCHAR && vim_strchr(p_cpo, CPO_REGAPPEND) == NULL) | |
7 | 3104 { |
3105 pnew = lalloc((long_u)(STRLEN(curr->y_array[curr->y_size - 1]) | |
3106 + STRLEN(y_current->y_array[0]) + 1), TRUE); | |
3107 if (pnew == NULL) | |
3108 { | |
3109 y_idx = y_current->y_size - 1; | |
3110 goto fail; | |
3111 } | |
3112 STRCPY(pnew, curr->y_array[--j]); | |
3113 STRCAT(pnew, y_current->y_array[0]); | |
3114 vim_free(curr->y_array[j]); | |
3115 vim_free(y_current->y_array[0]); | |
3116 curr->y_array[j++] = pnew; | |
3117 y_idx = 1; | |
3118 } | |
3119 else | |
3120 y_idx = 0; | |
3121 while (y_idx < y_current->y_size) | |
3122 curr->y_array[j++] = y_current->y_array[y_idx++]; | |
3123 curr->y_size = j; | |
3124 vim_free(y_current->y_array); | |
3125 y_current = curr; | |
3126 } | |
5981 | 3127 if (curwin->w_p_rnu) |
3128 redraw_later(SOME_VALID); /* cursor moved to start */ | |
7 | 3129 if (mess) /* Display message about yank? */ |
3130 { | |
3131 if (yanktype == MCHAR | |
3132 && !oap->block_mode | |
3133 && yanklines == 1) | |
3134 yanklines = 0; | |
3135 /* Some versions of Vi use ">=" here, some don't... */ | |
3136 if (yanklines > p_report) | |
3137 { | |
3138 /* redisplay now, so message is not deleted */ | |
3139 update_topline_redraw(); | |
3140 if (yanklines == 1) | |
205 | 3141 { |
3142 if (oap->block_mode) | |
3143 MSG(_("block of 1 line yanked")); | |
3144 else | |
3145 MSG(_("1 line yanked")); | |
3146 } | |
3147 else if (oap->block_mode) | |
3148 smsg((char_u *)_("block of %ld lines yanked"), yanklines); | |
7 | 3149 else |
3150 smsg((char_u *)_("%ld lines yanked"), yanklines); | |
3151 } | |
3152 } | |
3153 | |
3154 /* | |
3155 * Set "'[" and "']" marks. | |
3156 */ | |
3157 curbuf->b_op_start = oap->start; | |
3158 curbuf->b_op_end = oap->end; | |
5735 | 3159 if (yanktype == MLINE && !oap->block_mode) |
36 | 3160 { |
3161 curbuf->b_op_start.col = 0; | |
3162 curbuf->b_op_end.col = MAXCOL; | |
3163 } | |
7 | 3164 |
3165 #ifdef FEAT_CLIPBOARD | |
3166 /* | |
3167 * If we were yanking to the '*' register, send result to clipboard. | |
3168 * If no register was specified, and "unnamed" in 'clipboard', make a copy | |
3169 * to the '*' register. | |
3170 */ | |
3171 if (clip_star.available | |
3172 && (curr == &(y_regs[STAR_REGISTER]) | |
2654 | 3173 || (!deleting && oap->regname == 0 |
6116 | 3174 && ((clip_unnamed | clip_unnamed_saved) & CLIP_UNNAMED)))) |
7 | 3175 { |
3176 if (curr != &(y_regs[STAR_REGISTER])) | |
3177 /* Copy the text from register 0 to the clipboard register. */ | |
3178 copy_yank_reg(&(y_regs[STAR_REGISTER])); | |
3179 | |
3180 clip_own_selection(&clip_star); | |
3181 clip_gen_set_selection(&clip_star); | |
2658 | 3182 # ifdef FEAT_X11 |
2654 | 3183 did_star = TRUE; |
2658 | 3184 # endif |
7 | 3185 } |
3186 | |
3187 # ifdef FEAT_X11 | |
3188 /* | |
3189 * If we were yanking to the '+' register, send result to selection. | |
3190 * Also copy to the '*' register, in case auto-select is off. | |
3191 */ | |
2654 | 3192 if (clip_plus.available |
3193 && (curr == &(y_regs[PLUS_REGISTER]) | |
3194 || (!deleting && oap->regname == 0 | |
6116 | 3195 && ((clip_unnamed | clip_unnamed_saved) & |
3196 CLIP_UNNAMED_PLUS)))) | |
7 | 3197 { |
2654 | 3198 if (curr != &(y_regs[PLUS_REGISTER])) |
3199 /* Copy the text from register 0 to the clipboard register. */ | |
3200 copy_yank_reg(&(y_regs[PLUS_REGISTER])); | |
3201 | |
7 | 3202 clip_own_selection(&clip_plus); |
3203 clip_gen_set_selection(&clip_plus); | |
3674 | 3204 if (!clip_isautosel_star() && !did_star |
3205 && curr == &(y_regs[PLUS_REGISTER])) | |
7 | 3206 { |
3207 copy_yank_reg(&(y_regs[STAR_REGISTER])); | |
3208 clip_own_selection(&clip_star); | |
3209 clip_gen_set_selection(&clip_star); | |
3210 } | |
3211 } | |
3212 # endif | |
3213 #endif | |
3214 | |
3215 return OK; | |
3216 | |
3217 fail: /* free the allocated lines */ | |
3218 free_yank(y_idx + 1); | |
3219 y_current = curr; | |
3220 return FAIL; | |
3221 } | |
3222 | |
3223 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3224 yank_copy_line(struct block_def *bd, long y_idx) |
7 | 3225 { |
3226 char_u *pnew; | |
3227 | |
3228 if ((pnew = alloc(bd->startspaces + bd->endspaces + bd->textlen + 1)) | |
3229 == NULL) | |
3230 return FAIL; | |
3231 y_current->y_array[y_idx] = pnew; | |
6929 | 3232 vim_memset(pnew, ' ', (size_t)bd->startspaces); |
7 | 3233 pnew += bd->startspaces; |
3234 mch_memmove(pnew, bd->textstart, (size_t)bd->textlen); | |
3235 pnew += bd->textlen; | |
6929 | 3236 vim_memset(pnew, ' ', (size_t)bd->endspaces); |
7 | 3237 pnew += bd->endspaces; |
3238 *pnew = NUL; | |
3239 return OK; | |
3240 } | |
3241 | |
3242 #ifdef FEAT_CLIPBOARD | |
3243 /* | |
3244 * Make a copy of the y_current register to register "reg". | |
3245 */ | |
3246 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3247 copy_yank_reg(struct yankreg *reg) |
7 | 3248 { |
3249 struct yankreg *curr = y_current; | |
3250 long j; | |
3251 | |
3252 y_current = reg; | |
3253 free_yank_all(); | |
3254 *y_current = *curr; | |
3255 y_current->y_array = (char_u **)lalloc_clear( | |
3256 (long_u)(sizeof(char_u *) * y_current->y_size), TRUE); | |
3257 if (y_current->y_array == NULL) | |
3258 y_current->y_size = 0; | |
3259 else | |
3260 for (j = 0; j < y_current->y_size; ++j) | |
3261 if ((y_current->y_array[j] = vim_strsave(curr->y_array[j])) == NULL) | |
3262 { | |
3263 free_yank(j); | |
3264 y_current->y_size = 0; | |
3265 break; | |
3266 } | |
3267 y_current = curr; | |
3268 } | |
3269 #endif | |
3270 | |
3271 /* | |
140 | 3272 * Put contents of register "regname" into the text. |
3273 * Caller must check "regname" to be valid! | |
3274 * "flags": PUT_FIXINDENT make indent look nice | |
3275 * PUT_CURSEND leave cursor after end of new text | |
3276 * PUT_LINE force linewise put (":put") | |
7 | 3277 */ |
3278 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3279 do_put( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3280 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3281 int dir, /* BACKWARD for 'P', FORWARD for 'p' */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3282 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3283 int flags) |
7 | 3284 { |
3285 char_u *ptr; | |
3286 char_u *newp, *oldp; | |
3287 int yanklen; | |
3288 int totlen = 0; /* init for gcc */ | |
3289 linenr_T lnum; | |
3290 colnr_T col; | |
3291 long i; /* index in y_array[] */ | |
3292 int y_type; | |
3293 long y_size; | |
3294 int oldlen; | |
3295 long y_width = 0; | |
3296 colnr_T vcol; | |
3297 int delcount; | |
3298 int incr = 0; | |
3299 long j; | |
3300 struct block_def bd; | |
3301 char_u **y_array = NULL; | |
3302 long nr_lines = 0; | |
3303 pos_T new_cursor; | |
3304 int indent; | |
3305 int orig_indent = 0; /* init for gcc */ | |
3306 int indent_diff = 0; /* init for gcc */ | |
3307 int first_indent = TRUE; | |
3308 int lendiff = 0; | |
3309 pos_T old_pos; | |
3310 char_u *insert_string = NULL; | |
3311 int allocated = FALSE; | |
3312 long cnt; | |
3313 | |
3314 #ifdef FEAT_CLIPBOARD | |
3315 /* Adjust register name for "unnamed" in 'clipboard'. */ | |
3316 adjust_clip_reg(®name); | |
3317 (void)may_get_selection(regname); | |
3318 #endif | |
3319 | |
3320 if (flags & PUT_FIXINDENT) | |
3321 orig_indent = get_indent(); | |
3322 | |
3323 curbuf->b_op_start = curwin->w_cursor; /* default for '[ mark */ | |
3324 curbuf->b_op_end = curwin->w_cursor; /* default for '] mark */ | |
3325 | |
3326 /* | |
3327 * Using inserted text works differently, because the register includes | |
3328 * special characters (newlines, etc.). | |
3329 */ | |
3330 if (regname == '.') | |
3331 { | |
3332 (void)stuff_inserted((dir == FORWARD ? (count == -1 ? 'o' : 'a') : | |
3333 (count == -1 ? 'O' : 'i')), count, FALSE); | |
3334 /* Putting the text is done later, so can't really move the cursor to | |
3335 * the next character. Use "l" to simulate it. */ | |
3336 if ((flags & PUT_CURSEND) && gchar_cursor() != NUL) | |
3337 stuffcharReadbuff('l'); | |
3338 return; | |
3339 } | |
3340 | |
3341 /* | |
3342 * For special registers '%' (file name), '#' (alternate file name) and | |
3343 * ':' (last command line), etc. we have to create a fake yank register. | |
3344 */ | |
3345 if (get_spec_reg(regname, &insert_string, &allocated, TRUE)) | |
3346 { | |
3347 if (insert_string == NULL) | |
3348 return; | |
3349 } | |
3350 | |
4005 | 3351 #ifdef FEAT_AUTOCMD |
3352 /* Autocommands may be executed when saving lines for undo, which may make | |
3353 * y_array invalid. Start undo now to avoid that. */ | |
3354 u_save(curwin->w_cursor.lnum, curwin->w_cursor.lnum + 1); | |
3355 #endif | |
3356 | |
7 | 3357 if (insert_string != NULL) |
3358 { | |
3359 y_type = MCHAR; | |
3360 #ifdef FEAT_EVAL | |
3361 if (regname == '=') | |
3362 { | |
3363 /* For the = register we need to split the string at NL | |
3093 | 3364 * characters. |
3365 * Loop twice: count the number of lines and save them. */ | |
7 | 3366 for (;;) |
3367 { | |
3368 y_size = 0; | |
3369 ptr = insert_string; | |
3370 while (ptr != NULL) | |
3371 { | |
3372 if (y_array != NULL) | |
3373 y_array[y_size] = ptr; | |
3374 ++y_size; | |
3375 ptr = vim_strchr(ptr, '\n'); | |
3376 if (ptr != NULL) | |
3377 { | |
3378 if (y_array != NULL) | |
3379 *ptr = NUL; | |
3380 ++ptr; | |
3093 | 3381 /* A trailing '\n' makes the register linewise. */ |
7 | 3382 if (*ptr == NUL) |
3383 { | |
3384 y_type = MLINE; | |
3385 break; | |
3386 } | |
3387 } | |
3388 } | |
3389 if (y_array != NULL) | |
3390 break; | |
3391 y_array = (char_u **)alloc((unsigned) | |
3392 (y_size * sizeof(char_u *))); | |
3393 if (y_array == NULL) | |
3394 goto end; | |
3395 } | |
3396 } | |
3397 else | |
3398 #endif | |
3399 { | |
3400 y_size = 1; /* use fake one-line yank register */ | |
3401 y_array = &insert_string; | |
3402 } | |
3403 } | |
3404 else | |
3405 { | |
3406 get_yank_register(regname, FALSE); | |
3407 | |
3408 y_type = y_current->y_type; | |
3409 y_width = y_current->y_width; | |
3410 y_size = y_current->y_size; | |
3411 y_array = y_current->y_array; | |
3412 } | |
3413 | |
3414 if (y_type == MLINE) | |
3415 { | |
3416 if (flags & PUT_LINE_SPLIT) | |
3417 { | |
6845 | 3418 char_u *p; |
3419 | |
7 | 3420 /* "p" or "P" in Visual mode: split the lines to put the text in |
3421 * between. */ | |
3422 if (u_save_cursor() == FAIL) | |
3423 goto end; | |
6845 | 3424 p = ml_get_cursor(); |
3425 if (dir == FORWARD && *p != NUL) | |
3426 mb_ptr_adv(p); | |
3427 ptr = vim_strsave(p); | |
7 | 3428 if (ptr == NULL) |
3429 goto end; | |
3430 ml_append(curwin->w_cursor.lnum, ptr, (colnr_T)0, FALSE); | |
3431 vim_free(ptr); | |
3432 | |
6845 | 3433 oldp = ml_get_curline(); |
3434 p = oldp + curwin->w_cursor.col; | |
3435 if (dir == FORWARD && *p != NUL) | |
3436 mb_ptr_adv(p); | |
3437 ptr = vim_strnsave(oldp, p - oldp); | |
7 | 3438 if (ptr == NULL) |
3439 goto end; | |
3440 ml_replace(curwin->w_cursor.lnum, ptr, FALSE); | |
3441 ++nr_lines; | |
3442 dir = FORWARD; | |
3443 } | |
3444 if (flags & PUT_LINE_FORWARD) | |
3445 { | |
3446 /* Must be "p" for a Visual block, put lines below the block. */ | |
692 | 3447 curwin->w_cursor = curbuf->b_visual.vi_end; |
7 | 3448 dir = FORWARD; |
3449 } | |
3450 curbuf->b_op_start = curwin->w_cursor; /* default for '[ mark */ | |
3451 curbuf->b_op_end = curwin->w_cursor; /* default for '] mark */ | |
3452 } | |
3453 | |
3454 if (flags & PUT_LINE) /* :put command or "p" in Visual line mode. */ | |
3455 y_type = MLINE; | |
3456 | |
3457 if (y_size == 0 || y_array == NULL) | |
3458 { | |
3459 EMSG2(_("E353: Nothing in register %s"), | |
3460 regname == 0 ? (char_u *)"\"" : transchar(regname)); | |
3461 goto end; | |
3462 } | |
3463 | |
3464 if (y_type == MBLOCK) | |
3465 { | |
3466 lnum = curwin->w_cursor.lnum + y_size + 1; | |
3467 if (lnum > curbuf->b_ml.ml_line_count) | |
3468 lnum = curbuf->b_ml.ml_line_count + 1; | |
3469 if (u_save(curwin->w_cursor.lnum - 1, lnum) == FAIL) | |
3470 goto end; | |
3471 } | |
5735 | 3472 else if (y_type == MLINE) |
7 | 3473 { |
3474 lnum = curwin->w_cursor.lnum; | |
3475 #ifdef FEAT_FOLDING | |
3476 /* Correct line number for closed fold. Don't move the cursor yet, | |
3477 * u_save() uses it. */ | |
3478 if (dir == BACKWARD) | |
3479 (void)hasFolding(lnum, &lnum, NULL); | |
3480 else | |
3481 (void)hasFolding(lnum, NULL, &lnum); | |
3482 #endif | |
3483 if (dir == FORWARD) | |
3484 ++lnum; | |
5053
35b6fc57a286
updated for version 7.3.1270
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3485 /* In an empty buffer the empty line is going to be replaced, include |
35b6fc57a286
updated for version 7.3.1270
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3486 * it in the saved lines. */ |
5100
18b43970fb7a
updated for version 7.3.1293
Bram Moolenaar <bram@vim.org>
parents:
5053
diff
changeset
|
3487 if ((bufempty() ? u_save(0, 2) : u_save(lnum - 1, lnum)) == FAIL) |
7 | 3488 goto end; |
3489 #ifdef FEAT_FOLDING | |
3490 if (dir == FORWARD) | |
3491 curwin->w_cursor.lnum = lnum - 1; | |
3492 else | |
3493 curwin->w_cursor.lnum = lnum; | |
3494 curbuf->b_op_start = curwin->w_cursor; /* for mark_adjust() */ | |
3495 #endif | |
3496 } | |
3497 else if (u_save_cursor() == FAIL) | |
3498 goto end; | |
3499 | |
3500 yanklen = (int)STRLEN(y_array[0]); | |
3501 | |
3502 #ifdef FEAT_VIRTUALEDIT | |
3503 if (ve_flags == VE_ALL && y_type == MCHAR) | |
3504 { | |
3505 if (gchar_cursor() == TAB) | |
3506 { | |
3507 /* Don't need to insert spaces when "p" on the last position of a | |
3508 * tab or "P" on the first position. */ | |
3509 if (dir == FORWARD | |
3510 ? (int)curwin->w_cursor.coladd < curbuf->b_p_ts - 1 | |
3511 : curwin->w_cursor.coladd > 0) | |
3512 coladvance_force(getviscol()); | |
3513 else | |
3514 curwin->w_cursor.coladd = 0; | |
3515 } | |
3516 else if (curwin->w_cursor.coladd > 0 || gchar_cursor() == NUL) | |
3517 coladvance_force(getviscol() + (dir == FORWARD)); | |
3518 } | |
3519 #endif | |
3520 | |
3521 lnum = curwin->w_cursor.lnum; | |
3522 col = curwin->w_cursor.col; | |
3523 | |
3524 /* | |
3525 * Block mode | |
3526 */ | |
3527 if (y_type == MBLOCK) | |
3528 { | |
3529 char c = gchar_cursor(); | |
3530 colnr_T endcol2 = 0; | |
3531 | |
3532 if (dir == FORWARD && c != NUL) | |
3533 { | |
3534 #ifdef FEAT_VIRTUALEDIT | |
3535 if (ve_flags == VE_ALL) | |
3536 getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2); | |
3537 else | |
3538 #endif | |
3539 getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col); | |
3540 | |
3541 #ifdef FEAT_MBYTE | |
3542 if (has_mbyte) | |
3543 /* move to start of next multi-byte character */ | |
474 | 3544 curwin->w_cursor.col += (*mb_ptr2len)(ml_get_cursor()); |
7 | 3545 else |
3546 #endif | |
3547 #ifdef FEAT_VIRTUALEDIT | |
3548 if (c != TAB || ve_flags != VE_ALL) | |
3549 #endif | |
3550 ++curwin->w_cursor.col; | |
3551 ++col; | |
3552 } | |
3553 else | |
3554 getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2); | |
3555 | |
3556 #ifdef FEAT_VIRTUALEDIT | |
3557 col += curwin->w_cursor.coladd; | |
1304 | 3558 if (ve_flags == VE_ALL |
3559 && (curwin->w_cursor.coladd > 0 | |
3560 || endcol2 == curwin->w_cursor.col)) | |
7 | 3561 { |
3562 if (dir == FORWARD && c == NUL) | |
3563 ++col; | |
3564 if (dir != FORWARD && c != NUL) | |
3565 ++curwin->w_cursor.col; | |
3566 if (c == TAB) | |
3567 { | |
3568 if (dir == BACKWARD && curwin->w_cursor.col) | |
3569 curwin->w_cursor.col--; | |
3570 if (dir == FORWARD && col - 1 == endcol2) | |
3571 curwin->w_cursor.col++; | |
3572 } | |
3573 } | |
3574 curwin->w_cursor.coladd = 0; | |
3575 #endif | |
699 | 3576 bd.textcol = 0; |
7 | 3577 for (i = 0; i < y_size; ++i) |
3578 { | |
3579 int spaces; | |
3580 char shortline; | |
3581 | |
3582 bd.startspaces = 0; | |
3583 bd.endspaces = 0; | |
3584 vcol = 0; | |
3585 delcount = 0; | |
3586 | |
3587 /* add a new line */ | |
3588 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
3589 { | |
3590 if (ml_append(curbuf->b_ml.ml_line_count, (char_u *)"", | |
3591 (colnr_T)1, FALSE) == FAIL) | |
3592 break; | |
3593 ++nr_lines; | |
3594 } | |
3595 /* get the old line and advance to the position to insert at */ | |
3596 oldp = ml_get_curline(); | |
3597 oldlen = (int)STRLEN(oldp); | |
3598 for (ptr = oldp; vcol < col && *ptr; ) | |
3599 { | |
3600 /* Count a tab for what it's worth (if list mode not on) */ | |
5995 | 3601 incr = lbr_chartabsize_adv(oldp, &ptr, (colnr_T)vcol); |
7 | 3602 vcol += incr; |
3603 } | |
3604 bd.textcol = (colnr_T)(ptr - oldp); | |
3605 | |
3606 shortline = (vcol < col) || (vcol == col && !*ptr) ; | |
3607 | |
3608 if (vcol < col) /* line too short, padd with spaces */ | |
3609 bd.startspaces = col - vcol; | |
3610 else if (vcol > col) | |
3611 { | |
3612 bd.endspaces = vcol - col; | |
3613 bd.startspaces = incr - bd.endspaces; | |
3614 --bd.textcol; | |
3615 delcount = 1; | |
3616 #ifdef FEAT_MBYTE | |
3617 if (has_mbyte) | |
3618 bd.textcol -= (*mb_head_off)(oldp, oldp + bd.textcol); | |
3619 #endif | |
3620 if (oldp[bd.textcol] != TAB) | |
3621 { | |
3622 /* Only a Tab can be split into spaces. Other | |
3623 * characters will have to be moved to after the | |
3624 * block, causing misalignment. */ | |
3625 delcount = 0; | |
3626 bd.endspaces = 0; | |
3627 } | |
3628 } | |
3629 | |
3630 yanklen = (int)STRLEN(y_array[i]); | |
3631 | |
3632 /* calculate number of spaces required to fill right side of block*/ | |
3633 spaces = y_width + 1; | |
3634 for (j = 0; j < yanklen; j++) | |
5995 | 3635 spaces -= lbr_chartabsize(NULL, &y_array[i][j], 0); |
7 | 3636 if (spaces < 0) |
3637 spaces = 0; | |
3638 | |
3639 /* insert the new text */ | |
3640 totlen = count * (yanklen + spaces) + bd.startspaces + bd.endspaces; | |
3641 newp = alloc_check((unsigned)totlen + oldlen + 1); | |
3642 if (newp == NULL) | |
3643 break; | |
3644 /* copy part up to cursor to new line */ | |
3645 ptr = newp; | |
3646 mch_memmove(ptr, oldp, (size_t)bd.textcol); | |
3647 ptr += bd.textcol; | |
3648 /* may insert some spaces before the new text */ | |
6929 | 3649 vim_memset(ptr, ' ', (size_t)bd.startspaces); |
7 | 3650 ptr += bd.startspaces; |
3651 /* insert the new text */ | |
3652 for (j = 0; j < count; ++j) | |
3653 { | |
3654 mch_memmove(ptr, y_array[i], (size_t)yanklen); | |
3655 ptr += yanklen; | |
3656 | |
3657 /* insert block's trailing spaces only if there's text behind */ | |
3658 if ((j < count - 1 || !shortline) && spaces) | |
3659 { | |
6929 | 3660 vim_memset(ptr, ' ', (size_t)spaces); |
7 | 3661 ptr += spaces; |
3662 } | |
3663 } | |
3664 /* may insert some spaces after the new text */ | |
6929 | 3665 vim_memset(ptr, ' ', (size_t)bd.endspaces); |
7 | 3666 ptr += bd.endspaces; |
3667 /* move the text after the cursor to the end of the line. */ | |
3668 mch_memmove(ptr, oldp + bd.textcol + delcount, | |
3669 (size_t)(oldlen - bd.textcol - delcount + 1)); | |
3670 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
3671 | |
3672 ++curwin->w_cursor.lnum; | |
3673 if (i == 0) | |
3674 curwin->w_cursor.col += bd.startspaces; | |
3675 } | |
3676 | |
3677 changed_lines(lnum, 0, curwin->w_cursor.lnum, nr_lines); | |
3678 | |
3679 /* Set '[ mark. */ | |
3680 curbuf->b_op_start = curwin->w_cursor; | |
3681 curbuf->b_op_start.lnum = lnum; | |
3682 | |
3683 /* adjust '] mark */ | |
3684 curbuf->b_op_end.lnum = curwin->w_cursor.lnum - 1; | |
3685 curbuf->b_op_end.col = bd.textcol + totlen - 1; | |
237 | 3686 # ifdef FEAT_VIRTUALEDIT |
7 | 3687 curbuf->b_op_end.coladd = 0; |
237 | 3688 # endif |
7 | 3689 if (flags & PUT_CURSEND) |
3690 { | |
916 | 3691 colnr_T len; |
3692 | |
7 | 3693 curwin->w_cursor = curbuf->b_op_end; |
3694 curwin->w_cursor.col++; | |
916 | 3695 |
3696 /* in Insert mode we might be after the NUL, correct for that */ | |
3697 len = (colnr_T)STRLEN(ml_get_curline()); | |
3698 if (curwin->w_cursor.col > len) | |
3699 curwin->w_cursor.col = len; | |
7 | 3700 } |
3701 else | |
3702 curwin->w_cursor.lnum = lnum; | |
3703 } | |
3704 else | |
3705 { | |
3706 /* | |
3707 * Character or Line mode | |
3708 */ | |
3709 if (y_type == MCHAR) | |
3710 { | |
3711 /* if type is MCHAR, FORWARD is the same as BACKWARD on the next | |
3712 * char */ | |
3713 if (dir == FORWARD && gchar_cursor() != NUL) | |
3714 { | |
3715 #ifdef FEAT_MBYTE | |
3716 if (has_mbyte) | |
3717 { | |
474 | 3718 int bytelen = (*mb_ptr2len)(ml_get_cursor()); |
7 | 3719 |
3720 /* put it on the next of the multi-byte character. */ | |
3721 col += bytelen; | |
3722 if (yanklen) | |
3723 { | |
3724 curwin->w_cursor.col += bytelen; | |
3725 curbuf->b_op_end.col += bytelen; | |
3726 } | |
3727 } | |
3728 else | |
3729 #endif | |
3730 { | |
3731 ++col; | |
3732 if (yanklen) | |
3733 { | |
3734 ++curwin->w_cursor.col; | |
3735 ++curbuf->b_op_end.col; | |
3736 } | |
3737 } | |
3738 } | |
3739 curbuf->b_op_start = curwin->w_cursor; | |
3740 } | |
3741 /* | |
3742 * Line mode: BACKWARD is the same as FORWARD on the previous line | |
3743 */ | |
3744 else if (dir == BACKWARD) | |
3745 --lnum; | |
699 | 3746 new_cursor = curwin->w_cursor; |
7 | 3747 |
3748 /* | |
3749 * simple case: insert into current line | |
3750 */ | |
3751 if (y_type == MCHAR && y_size == 1) | |
3752 { | |
5365 | 3753 do { |
3754 totlen = count * yanklen; | |
3755 if (totlen > 0) | |
7 | 3756 { |
5365 | 3757 oldp = ml_get(lnum); |
3758 newp = alloc_check((unsigned)(STRLEN(oldp) + totlen + 1)); | |
3759 if (newp == NULL) | |
3760 goto end; /* alloc() gave an error message */ | |
3761 mch_memmove(newp, oldp, (size_t)col); | |
3762 ptr = newp + col; | |
3763 for (i = 0; i < count; ++i) | |
3764 { | |
3765 mch_memmove(ptr, y_array[0], (size_t)yanklen); | |
3766 ptr += yanklen; | |
3767 } | |
3768 STRMOVE(ptr, oldp + col); | |
3769 ml_replace(lnum, newp, FALSE); | |
3770 /* Place cursor on last putted char. */ | |
3771 if (lnum == curwin->w_cursor.lnum) | |
5496 | 3772 { |
3773 /* make sure curwin->w_virtcol is updated */ | |
3774 changed_cline_bef_curs(); | |
5365 | 3775 curwin->w_cursor.col += (colnr_T)(totlen - 1); |
5496 | 3776 } |
7 | 3777 } |
5365 | 3778 if (VIsual_active) |
3779 lnum++; | |
5735 | 3780 } while (VIsual_active && lnum <= curbuf->b_visual.vi_end.lnum); |
5365 | 3781 |
6379 | 3782 if (VIsual_active) /* reset lnum to the last visual line */ |
3783 lnum--; | |
3784 | |
7 | 3785 curbuf->b_op_end = curwin->w_cursor; |
3786 /* For "CTRL-O p" in Insert mode, put cursor after last char */ | |
3787 if (totlen && (restart_edit != 0 || (flags & PUT_CURSEND))) | |
3788 ++curwin->w_cursor.col; | |
3789 changed_bytes(lnum, col); | |
3790 } | |
3791 else | |
3792 { | |
3793 /* | |
3794 * Insert at least one line. When y_type is MCHAR, break the first | |
3795 * line in two. | |
3796 */ | |
3797 for (cnt = 1; cnt <= count; ++cnt) | |
3798 { | |
3799 i = 0; | |
3800 if (y_type == MCHAR) | |
3801 { | |
3802 /* | |
3803 * Split the current line in two at the insert position. | |
3804 * First insert y_array[size - 1] in front of second line. | |
3805 * Then append y_array[0] to first line. | |
3806 */ | |
3807 lnum = new_cursor.lnum; | |
3808 ptr = ml_get(lnum) + col; | |
3809 totlen = (int)STRLEN(y_array[y_size - 1]); | |
3810 newp = alloc_check((unsigned)(STRLEN(ptr) + totlen + 1)); | |
3811 if (newp == NULL) | |
3812 goto error; | |
3813 STRCPY(newp, y_array[y_size - 1]); | |
3814 STRCAT(newp, ptr); | |
3815 /* insert second line */ | |
3816 ml_append(lnum, newp, (colnr_T)0, FALSE); | |
3817 vim_free(newp); | |
3818 | |
3819 oldp = ml_get(lnum); | |
3820 newp = alloc_check((unsigned)(col + yanklen + 1)); | |
3821 if (newp == NULL) | |
3822 goto error; | |
3823 /* copy first part of line */ | |
3824 mch_memmove(newp, oldp, (size_t)col); | |
3825 /* append to first line */ | |
3826 mch_memmove(newp + col, y_array[0], (size_t)(yanklen + 1)); | |
3827 ml_replace(lnum, newp, FALSE); | |
3828 | |
3829 curwin->w_cursor.lnum = lnum; | |
3830 i = 1; | |
3831 } | |
3832 | |
3833 for (; i < y_size; ++i) | |
3834 { | |
3835 if ((y_type != MCHAR || i < y_size - 1) | |
3836 && ml_append(lnum, y_array[i], (colnr_T)0, FALSE) | |
3837 == FAIL) | |
3838 goto error; | |
3839 lnum++; | |
3840 ++nr_lines; | |
3841 if (flags & PUT_FIXINDENT) | |
3842 { | |
3843 old_pos = curwin->w_cursor; | |
3844 curwin->w_cursor.lnum = lnum; | |
3845 ptr = ml_get(lnum); | |
3846 if (cnt == count && i == y_size - 1) | |
3847 lendiff = (int)STRLEN(ptr); | |
3848 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) | |
3849 if (*ptr == '#' && preprocs_left()) | |
3850 indent = 0; /* Leave # lines at start */ | |
3851 else | |
3852 #endif | |
3853 if (*ptr == NUL) | |
3854 indent = 0; /* Ignore empty lines */ | |
3855 else if (first_indent) | |
3856 { | |
3857 indent_diff = orig_indent - get_indent(); | |
3858 indent = orig_indent; | |
3859 first_indent = FALSE; | |
3860 } | |
3861 else if ((indent = get_indent() + indent_diff) < 0) | |
3862 indent = 0; | |
3863 (void)set_indent(indent, 0); | |
3864 curwin->w_cursor = old_pos; | |
3865 /* remember how many chars were removed */ | |
3866 if (cnt == count && i == y_size - 1) | |
3867 lendiff -= (int)STRLEN(ml_get(lnum)); | |
3868 } | |
3869 } | |
3870 } | |
3871 | |
3872 error: | |
3873 /* Adjust marks. */ | |
3874 if (y_type == MLINE) | |
3875 { | |
3876 curbuf->b_op_start.col = 0; | |
3877 if (dir == FORWARD) | |
3878 curbuf->b_op_start.lnum++; | |
3879 } | |
3880 mark_adjust(curbuf->b_op_start.lnum + (y_type == MCHAR), | |
3881 (linenr_T)MAXLNUM, nr_lines, 0L); | |
3882 | |
3883 /* note changed text for displaying and folding */ | |
3884 if (y_type == MCHAR) | |
3885 changed_lines(curwin->w_cursor.lnum, col, | |
3886 curwin->w_cursor.lnum + 1, nr_lines); | |
3887 else | |
3888 changed_lines(curbuf->b_op_start.lnum, 0, | |
3889 curbuf->b_op_start.lnum, nr_lines); | |
3890 | |
3891 /* put '] mark at last inserted character */ | |
3892 curbuf->b_op_end.lnum = lnum; | |
3893 /* correct length for change in indent */ | |
3894 col = (colnr_T)STRLEN(y_array[y_size - 1]) - lendiff; | |
3895 if (col > 1) | |
3896 curbuf->b_op_end.col = col - 1; | |
3897 else | |
3898 curbuf->b_op_end.col = 0; | |
3899 | |
168 | 3900 if (flags & PUT_CURSLINE) |
3901 { | |
237 | 3902 /* ":put": put cursor on last inserted line */ |
168 | 3903 curwin->w_cursor.lnum = lnum; |
3904 beginline(BL_WHITE | BL_FIX); | |
3905 } | |
3906 else if (flags & PUT_CURSEND) | |
7 | 3907 { |
3908 /* put cursor after inserted text */ | |
3909 if (y_type == MLINE) | |
3910 { | |
3911 if (lnum >= curbuf->b_ml.ml_line_count) | |
3912 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
3913 else | |
3914 curwin->w_cursor.lnum = lnum + 1; | |
3915 curwin->w_cursor.col = 0; | |
3916 } | |
3917 else | |
3918 { | |
3919 curwin->w_cursor.lnum = lnum; | |
3920 curwin->w_cursor.col = col; | |
3921 } | |
3922 } | |
3923 else if (y_type == MLINE) | |
3924 { | |
168 | 3925 /* put cursor on first non-blank in first inserted line */ |
7 | 3926 curwin->w_cursor.col = 0; |
3927 if (dir == FORWARD) | |
3928 ++curwin->w_cursor.lnum; | |
3929 beginline(BL_WHITE | BL_FIX); | |
3930 } | |
3931 else /* put cursor on first inserted character */ | |
3932 curwin->w_cursor = new_cursor; | |
3933 } | |
3934 } | |
3935 | |
3936 msgmore(nr_lines); | |
3937 curwin->w_set_curswant = TRUE; | |
3938 | |
3939 end: | |
3940 if (allocated) | |
3941 vim_free(insert_string); | |
840 | 3942 if (regname == '=') |
3943 vim_free(y_array); | |
3944 | |
5380 | 3945 VIsual_active = FALSE; |
3946 | |
140 | 3947 /* If the cursor is past the end of the line put it at the end. */ |
844 | 3948 adjust_cursor_eol(); |
3949 } | |
3950 | |
3951 /* | |
3952 * When the cursor is on the NUL past the end of the line and it should not be | |
3953 * there move it left. | |
3954 */ | |
3955 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3956 adjust_cursor_eol(void) |
844 | 3957 { |
3958 if (curwin->w_cursor.col > 0 | |
3959 && gchar_cursor() == NUL | |
773 | 3960 #ifdef FEAT_VIRTUALEDIT |
3961 && (ve_flags & VE_ONEMORE) == 0 | |
3962 #endif | |
7 | 3963 && !(restart_edit || (State & INSERT))) |
3964 { | |
557 | 3965 /* Put the cursor on the last character in the line. */ |
555 | 3966 dec_cursor(); |
844 | 3967 |
7 | 3968 #ifdef FEAT_VIRTUALEDIT |
3969 if (ve_flags == VE_ALL) | |
557 | 3970 { |
3971 colnr_T scol, ecol; | |
3972 | |
3973 /* Coladd is set to the width of the last character. */ | |
3974 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); | |
3975 curwin->w_cursor.coladd = ecol - scol + 1; | |
3976 } | |
7 | 3977 #endif |
3978 } | |
3979 } | |
3980 | |
3981 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) || defined(PROTO) | |
3982 /* | |
3983 * Return TRUE if lines starting with '#' should be left aligned. | |
3984 */ | |
3985 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3986 preprocs_left(void) |
7 | 3987 { |
3988 return | |
3989 # ifdef FEAT_SMARTINDENT | |
3990 # ifdef FEAT_CINDENT | |
3991 (curbuf->b_p_si && !curbuf->b_p_cin) || | |
3992 # else | |
3993 curbuf->b_p_si | |
3994 # endif | |
3995 # endif | |
3996 # ifdef FEAT_CINDENT | |
5438 | 3997 (curbuf->b_p_cin && in_cinkeys('#', ' ', TRUE) |
3998 && curbuf->b_ind_hash_comment == 0) | |
7 | 3999 # endif |
4000 ; | |
4001 } | |
4002 #endif | |
4003 | |
4004 /* Return the character name of the register with the given number */ | |
4005 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4006 get_register_name(int num) |
7 | 4007 { |
4008 if (num == -1) | |
4009 return '"'; | |
4010 else if (num < 10) | |
4011 return num + '0'; | |
4012 else if (num == DELETION_REGISTER) | |
4013 return '-'; | |
4014 #ifdef FEAT_CLIPBOARD | |
4015 else if (num == STAR_REGISTER) | |
4016 return '*'; | |
4017 else if (num == PLUS_REGISTER) | |
4018 return '+'; | |
4019 #endif | |
4020 else | |
4021 { | |
4022 #ifdef EBCDIC | |
4023 int i; | |
4024 | |
4025 /* EBCDIC is really braindead ... */ | |
4026 i = 'a' + (num - 10); | |
4027 if (i > 'i') | |
4028 i += 7; | |
4029 if (i > 'r') | |
4030 i += 8; | |
4031 return i; | |
4032 #else | |
4033 return num + 'a' - 10; | |
4034 #endif | |
4035 } | |
4036 } | |
4037 | |
4038 /* | |
4039 * ":dis" and ":registers": Display the contents of the yank registers. | |
4040 */ | |
4041 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4042 ex_display(exarg_T *eap) |
7 | 4043 { |
4044 int i, n; | |
4045 long j; | |
4046 char_u *p; | |
4047 struct yankreg *yb; | |
4048 int name; | |
4049 int attr; | |
4050 char_u *arg = eap->arg; | |
22 | 4051 #ifdef FEAT_MBYTE |
4052 int clen; | |
4053 #else | |
4054 # define clen 1 | |
4055 #endif | |
7 | 4056 |
4057 if (arg != NULL && *arg == NUL) | |
4058 arg = NULL; | |
4059 attr = hl_attr(HLF_8); | |
4060 | |
4061 /* Highlight title */ | |
4062 MSG_PUTS_TITLE(_("\n--- Registers ---")); | |
4063 for (i = -1; i < NUM_REGISTERS && !got_int; ++i) | |
4064 { | |
4065 name = get_register_name(i); | |
2644 | 4066 if (arg != NULL && vim_strchr(arg, name) == NULL |
4067 #ifdef ONE_CLIPBOARD | |
4068 /* Star register and plus register contain the same thing. */ | |
4069 && (name != '*' || vim_strchr(arg, '+') == NULL) | |
4070 #endif | |
4071 ) | |
7 | 4072 continue; /* did not ask for this register */ |
4073 | |
4074 #ifdef FEAT_CLIPBOARD | |
4075 /* Adjust register name for "unnamed" in 'clipboard'. | |
4076 * When it's a clipboard register, fill it with the current contents | |
4077 * of the clipboard. */ | |
4078 adjust_clip_reg(&name); | |
4079 (void)may_get_selection(name); | |
4080 #endif | |
4081 | |
4082 if (i == -1) | |
4083 { | |
4084 if (y_previous != NULL) | |
4085 yb = y_previous; | |
4086 else | |
4087 yb = &(y_regs[0]); | |
4088 } | |
4089 else | |
4090 yb = &(y_regs[i]); | |
2000 | 4091 |
4092 #ifdef FEAT_EVAL | |
4093 if (name == MB_TOLOWER(redir_reg) | |
4094 || (redir_reg == '"' && yb == y_previous)) | |
4095 continue; /* do not list register being written to, the | |
4096 * pointer can be freed */ | |
4097 #endif | |
4098 | |
7 | 4099 if (yb->y_array != NULL) |
4100 { | |
4101 msg_putchar('\n'); | |
4102 msg_putchar('"'); | |
4103 msg_putchar(name); | |
4104 MSG_PUTS(" "); | |
4105 | |
4106 n = (int)Columns - 6; | |
4107 for (j = 0; j < yb->y_size && n > 1; ++j) | |
4108 { | |
4109 if (j) | |
4110 { | |
4111 MSG_PUTS_ATTR("^J", attr); | |
4112 n -= 2; | |
4113 } | |
4114 for (p = yb->y_array[j]; *p && (n -= ptr2cells(p)) >= 0; ++p) | |
4115 { | |
4116 #ifdef FEAT_MBYTE | |
474 | 4117 clen = (*mb_ptr2len)(p); |
22 | 4118 #endif |
4119 msg_outtrans_len(p, clen); | |
4120 #ifdef FEAT_MBYTE | |
4121 p += clen - 1; | |
7 | 4122 #endif |
4123 } | |
4124 } | |
4125 if (n > 1 && yb->y_type == MLINE) | |
4126 MSG_PUTS_ATTR("^J", attr); | |
4127 out_flush(); /* show one line at a time */ | |
4128 } | |
4129 ui_breakcheck(); | |
4130 } | |
4131 | |
4132 /* | |
4133 * display last inserted text | |
4134 */ | |
4135 if ((p = get_last_insert()) != NULL | |
4136 && (arg == NULL || vim_strchr(arg, '.') != NULL) && !got_int) | |
4137 { | |
4138 MSG_PUTS("\n\". "); | |
4139 dis_msg(p, TRUE); | |
4140 } | |
4141 | |
4142 /* | |
4143 * display last command line | |
4144 */ | |
4145 if (last_cmdline != NULL && (arg == NULL || vim_strchr(arg, ':') != NULL) | |
4146 && !got_int) | |
4147 { | |
4148 MSG_PUTS("\n\": "); | |
4149 dis_msg(last_cmdline, FALSE); | |
4150 } | |
4151 | |
4152 /* | |
4153 * display current file name | |
4154 */ | |
4155 if (curbuf->b_fname != NULL | |
4156 && (arg == NULL || vim_strchr(arg, '%') != NULL) && !got_int) | |
4157 { | |
4158 MSG_PUTS("\n\"% "); | |
4159 dis_msg(curbuf->b_fname, FALSE); | |
4160 } | |
4161 | |
4162 /* | |
4163 * display alternate file name | |
4164 */ | |
4165 if ((arg == NULL || vim_strchr(arg, '%') != NULL) && !got_int) | |
4166 { | |
4167 char_u *fname; | |
4168 linenr_T dummy; | |
4169 | |
4170 if (buflist_name_nr(0, &fname, &dummy) != FAIL) | |
4171 { | |
4172 MSG_PUTS("\n\"# "); | |
4173 dis_msg(fname, FALSE); | |
4174 } | |
4175 } | |
4176 | |
4177 /* | |
4178 * display last search pattern | |
4179 */ | |
4180 if (last_search_pat() != NULL | |
4181 && (arg == NULL || vim_strchr(arg, '/') != NULL) && !got_int) | |
4182 { | |
4183 MSG_PUTS("\n\"/ "); | |
4184 dis_msg(last_search_pat(), FALSE); | |
4185 } | |
4186 | |
4187 #ifdef FEAT_EVAL | |
4188 /* | |
4189 * display last used expression | |
4190 */ | |
4191 if (expr_line != NULL && (arg == NULL || vim_strchr(arg, '=') != NULL) | |
4192 && !got_int) | |
4193 { | |
4194 MSG_PUTS("\n\"= "); | |
4195 dis_msg(expr_line, FALSE); | |
4196 } | |
4197 #endif | |
4198 } | |
4199 | |
4200 /* | |
4201 * display a string for do_dis() | |
4202 * truncate at end of screen line | |
4203 */ | |
4204 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4205 dis_msg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4206 char_u *p, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4207 int skip_esc) /* if TRUE, ignore trailing ESC */ |
7 | 4208 { |
4209 int n; | |
4210 #ifdef FEAT_MBYTE | |
4211 int l; | |
4212 #endif | |
4213 | |
4214 n = (int)Columns - 6; | |
4215 while (*p != NUL | |
4216 && !(*p == ESC && skip_esc && *(p + 1) == NUL) | |
4217 && (n -= ptr2cells(p)) >= 0) | |
4218 { | |
4219 #ifdef FEAT_MBYTE | |
474 | 4220 if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) |
7 | 4221 { |
4222 msg_outtrans_len(p, l); | |
4223 p += l; | |
4224 } | |
4225 else | |
4226 #endif | |
4227 msg_outtrans_len(p++, 1); | |
4228 } | |
4229 ui_breakcheck(); | |
4230 } | |
4231 | |
3562 | 4232 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4233 /* | |
4234 * If "process" is TRUE and the line begins with a comment leader (possibly | |
4235 * after some white space), return a pointer to the text after it. Put a boolean | |
4236 * value indicating whether the line ends with an unclosed comment in | |
4237 * "is_comment". | |
4238 * line - line to be processed, | |
4239 * process - if FALSE, will only check whether the line ends with an unclosed | |
3584 | 4240 * comment, |
3562 | 4241 * include_space - whether to also skip space following the comment leader, |
4242 * is_comment - will indicate whether the current line ends with an unclosed | |
3584 | 4243 * comment. |
3562 | 4244 */ |
4245 static char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4246 skip_comment( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4247 char_u *line, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4248 int process, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4249 int include_space, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4250 int *is_comment) |
3562 | 4251 { |
4252 char_u *comment_flags = NULL; | |
4253 int lead_len; | |
4254 int leader_offset = get_last_leader_offset(line, &comment_flags); | |
4255 | |
4256 *is_comment = FALSE; | |
4257 if (leader_offset != -1) | |
4258 { | |
4259 /* Let's check whether the line ends with an unclosed comment. | |
4260 * If the last comment leader has COM_END in flags, there's no comment. | |
4261 */ | |
4262 while (*comment_flags) | |
4263 { | |
4264 if (*comment_flags == COM_END | |
4265 || *comment_flags == ':') | |
4266 break; | |
4267 ++comment_flags; | |
4268 } | |
4269 if (*comment_flags != COM_END) | |
4270 *is_comment = TRUE; | |
4271 } | |
4272 | |
4273 if (process == FALSE) | |
4274 return line; | |
4275 | |
4276 lead_len = get_leader_len(line, &comment_flags, FALSE, include_space); | |
4277 | |
4278 if (lead_len == 0) | |
4279 return line; | |
4280 | |
4281 /* Find: | |
4282 * - COM_END, | |
4283 * - colon, | |
4284 * whichever comes first. | |
4285 */ | |
4286 while (*comment_flags) | |
4287 { | |
3580 | 4288 if (*comment_flags == COM_END |
3562 | 4289 || *comment_flags == ':') |
4290 { | |
4291 break; | |
4292 } | |
4293 ++comment_flags; | |
4294 } | |
4295 | |
4296 /* If we found a colon, it means that we are not processing a line | |
3580 | 4297 * starting with a closing part of a three-part comment. That's good, |
4298 * because we don't want to remove those as this would be annoying. | |
3562 | 4299 */ |
4300 if (*comment_flags == ':' || *comment_flags == NUL) | |
4301 line += lead_len; | |
4302 | |
4303 return line; | |
4304 } | |
4305 #endif | |
4306 | |
7 | 4307 /* |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4308 * Join 'count' lines (minimal 2) at cursor position. |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4309 * When "save_undo" is TRUE save lines for undo first. |
5848 | 4310 * Set "use_formatoptions" to FALSE when e.g. processing backspace and comment |
4311 * leaders should not be removed. | |
4312 * When setmark is TRUE, sets the '[ and '] mark, else, the caller is expected | |
4313 * to set those marks. | |
7 | 4314 * |
1217 | 4315 * return FAIL for failure, OK otherwise |
7 | 4316 */ |
4317 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4318 do_join( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4319 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4320 int insert_space, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4321 int save_undo, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4322 int use_formatoptions UNUSED, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4323 int setmark) |
7 | 4324 { |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4325 char_u *curr = NULL; |
2597 | 4326 char_u *curr_start = NULL; |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4327 char_u *cend; |
7 | 4328 char_u *newp; |
2597 | 4329 char_u *spaces; /* number of spaces inserted before a line */ |
2310
3e4574a4b627
Fix a few compiler warnings.
Bram Moolenaar <bram@vim.org>
parents:
2298
diff
changeset
|
4330 int endcurr1 = NUL; |
3e4574a4b627
Fix a few compiler warnings.
Bram Moolenaar <bram@vim.org>
parents:
2298
diff
changeset
|
4331 int endcurr2 = NUL; |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4332 int currsize = 0; /* size of the current line */ |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4333 int sumsize = 0; /* size of the long new line */ |
7 | 4334 linenr_T t; |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4335 colnr_T col = 0; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4336 int ret = OK; |
3562 | 4337 #if defined(FEAT_COMMENTS) || defined(PROTO) |
3574 | 4338 int *comments = NULL; |
3562 | 4339 int remove_comments = (use_formatoptions == TRUE) |
4340 && has_format_option(FO_REMOVE_COMS); | |
4341 int prev_was_comment; | |
4342 #endif | |
4343 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4344 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4345 if (save_undo && u_save((linenr_T)(curwin->w_cursor.lnum - 1), |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4346 (linenr_T)(curwin->w_cursor.lnum + count)) == FAIL) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4347 return FAIL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4348 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4349 /* Allocate an array to store the number of spaces inserted before each |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4350 * line. We will use it to pre-compute the length of the new line and the |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4351 * proper placement of each original line in the new one. */ |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4352 spaces = lalloc_clear((long_u)count, TRUE); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4353 if (spaces == NULL) |
7 | 4354 return FAIL; |
3562 | 4355 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4356 if (remove_comments) | |
4357 { | |
4358 comments = (int *)lalloc_clear((long_u)count * sizeof(int), TRUE); | |
4359 if (comments == NULL) | |
4360 { | |
4361 vim_free(spaces); | |
4362 return FAIL; | |
4363 } | |
4364 } | |
4365 #endif | |
7 | 4366 |
4367 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4368 * Don't move anything, just compute the final line length |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4369 * and setup the array of space strings lengths |
7 | 4370 */ |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4371 for (t = 0; t < count; ++t) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4372 { |
2597 | 4373 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t)); |
5848 | 4374 if (t == 0 && setmark) |
5664 | 4375 { |
4376 /* Set the '[ mark. */ | |
4377 curwin->w_buffer->b_op_start.lnum = curwin->w_cursor.lnum; | |
4378 curwin->w_buffer->b_op_start.col = (colnr_T)STRLEN(curr); | |
4379 } | |
3562 | 4380 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4381 if (remove_comments) | |
4382 { | |
4383 /* We don't want to remove the comment leader if the | |
4384 * previous line is not a comment. */ | |
4385 if (t > 0 && prev_was_comment) | |
4386 { | |
4387 | |
4388 char_u *new_curr = skip_comment(curr, TRUE, insert_space, | |
4389 &prev_was_comment); | |
3576 | 4390 comments[t] = (int)(new_curr - curr); |
3562 | 4391 curr = new_curr; |
4392 } | |
4393 else | |
4394 curr = skip_comment(curr, FALSE, insert_space, | |
4395 &prev_was_comment); | |
4396 } | |
4397 #endif | |
4398 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4399 if (insert_space && t > 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4400 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4401 curr = skipwhite(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4402 if (*curr != ')' && currsize != 0 && endcurr1 != TAB |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4403 #ifdef FEAT_MBYTE |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4404 && (!has_format_option(FO_MBYTE_JOIN) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4405 || (mb_ptr2char(curr) < 0x100 && endcurr1 < 0x100)) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4406 && (!has_format_option(FO_MBYTE_JOIN2) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4407 || mb_ptr2char(curr) < 0x100 || endcurr1 < 0x100) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4408 #endif |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4409 ) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4410 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4411 /* don't add a space if the line is ending in a space */ |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4412 if (endcurr1 == ' ') |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4413 endcurr1 = endcurr2; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4414 else |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4415 ++spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4416 /* extra space when 'joinspaces' set and line ends in '.' */ |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4417 if ( p_js |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4418 && (endcurr1 == '.' |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4419 || (vim_strchr(p_cpo, CPO_JOINSP) == NULL |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4420 && (endcurr1 == '?' || endcurr1 == '!')))) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4421 ++spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4422 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4423 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4424 currsize = (int)STRLEN(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4425 sumsize += currsize + spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4426 endcurr1 = endcurr2 = NUL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4427 if (insert_space && currsize > 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4428 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4429 #ifdef FEAT_MBYTE |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4430 if (has_mbyte) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4431 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4432 cend = curr + currsize; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4433 mb_ptr_back(curr, cend); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4434 endcurr1 = (*mb_ptr2char)(cend); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4435 if (cend > curr) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4436 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4437 mb_ptr_back(curr, cend); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4438 endcurr2 = (*mb_ptr2char)(cend); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4439 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4440 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4441 else |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4442 #endif |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4443 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4444 endcurr1 = *(curr + currsize - 1); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4445 if (currsize > 1) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4446 endcurr2 = *(curr + currsize - 2); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4447 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4448 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4449 line_breakcheck(); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4450 if (got_int) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4451 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4452 ret = FAIL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4453 goto theend; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4454 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4455 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4456 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4457 /* store the column position before last line */ |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4458 col = sumsize - currsize - spaces[count - 1]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4459 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4460 /* allocate the space for the new line */ |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4461 newp = alloc_check((unsigned)(sumsize + 1)); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4462 cend = newp + sumsize; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4463 *cend = 0; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4464 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4465 /* |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4466 * Move affected lines to the new long one. |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4467 * |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4468 * Move marks from each deleted line to the joined line, adjusting the |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4469 * column. This is not Vi compatible, but Vi deletes the marks, thus that |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4470 * should not really be a problem. |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4471 */ |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4472 for (t = count - 1; ; --t) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4473 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4474 cend -= currsize; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4475 mch_memmove(cend, curr, (size_t)currsize); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4476 if (spaces[t] > 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4477 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4478 cend -= spaces[t]; |
6929 | 4479 vim_memset(cend, ' ', (size_t)(spaces[t])); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4480 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4481 mark_col_adjust(curwin->w_cursor.lnum + t, (colnr_T)0, (linenr_T)-t, |
2597 | 4482 (long)(cend - newp + spaces[t] - (curr - curr_start))); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4483 if (t == 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4484 break; |
2597 | 4485 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t - 1)); |
3562 | 4486 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4487 if (remove_comments) | |
4488 curr += comments[t - 1]; | |
4489 #endif | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4490 if (insert_space && t > 1) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4491 curr = skipwhite(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4492 currsize = (int)STRLEN(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4493 } |
7 | 4494 ml_replace(curwin->w_cursor.lnum, newp, FALSE); |
4495 | |
5848 | 4496 if (setmark) |
4497 { | |
4498 /* Set the '] mark. */ | |
4499 curwin->w_buffer->b_op_end.lnum = curwin->w_cursor.lnum; | |
4500 curwin->w_buffer->b_op_end.col = (colnr_T)STRLEN(newp); | |
4501 } | |
5664 | 4502 |
7 | 4503 /* Only report the change in the first line here, del_lines() will report |
4504 * the deleted line. */ | |
4505 changed_lines(curwin->w_cursor.lnum, currsize, | |
4506 curwin->w_cursor.lnum + 1, 0L); | |
4507 | |
4508 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4509 * Delete following lines. To do this we move the cursor there |
7 | 4510 * briefly, and then move it back. After del_lines() the cursor may |
4511 * have moved up (last line deleted), so the current lnum is kept in t. | |
4512 */ | |
4513 t = curwin->w_cursor.lnum; | |
4514 ++curwin->w_cursor.lnum; | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4515 del_lines(count - 1, FALSE); |
7 | 4516 curwin->w_cursor.lnum = t; |
4517 | |
4518 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4519 * Set the cursor column: |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4520 * Vi compatible: use the column of the first join |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2310
diff
changeset
|
4521 * vim: use the column of the last join |
7 | 4522 */ |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4523 curwin->w_cursor.col = |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4524 (vim_strchr(p_cpo, CPO_JOINCOL) != NULL ? currsize : col); |
7 | 4525 check_cursor_col(); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4526 |
7 | 4527 #ifdef FEAT_VIRTUALEDIT |
4528 curwin->w_cursor.coladd = 0; | |
4529 #endif | |
4530 curwin->w_set_curswant = TRUE; | |
4531 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4532 theend: |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4533 vim_free(spaces); |
3562 | 4534 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4535 if (remove_comments) | |
4536 vim_free(comments); | |
4537 #endif | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4538 return ret; |
7 | 4539 } |
4540 | |
4541 #ifdef FEAT_COMMENTS | |
4542 /* | |
4543 * Return TRUE if the two comment leaders given are the same. "lnum" is | |
4544 * the first line. White-space is ignored. Note that the whole of | |
4545 * 'leader1' must match 'leader2_len' characters from 'leader2' -- webb | |
4546 */ | |
4547 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4548 same_leader( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4549 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4550 int leader1_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4551 char_u *leader1_flags, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4552 int leader2_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4553 char_u *leader2_flags) |
7 | 4554 { |
4555 int idx1 = 0, idx2 = 0; | |
4556 char_u *p; | |
4557 char_u *line1; | |
4558 char_u *line2; | |
4559 | |
4560 if (leader1_len == 0) | |
4561 return (leader2_len == 0); | |
4562 | |
4563 /* | |
4564 * If first leader has 'f' flag, the lines can be joined only if the | |
4565 * second line does not have a leader. | |
4566 * If first leader has 'e' flag, the lines can never be joined. | |
4567 * If fist leader has 's' flag, the lines can only be joined if there is | |
4568 * some text after it and the second line has the 'm' flag. | |
4569 */ | |
4570 if (leader1_flags != NULL) | |
4571 { | |
4572 for (p = leader1_flags; *p && *p != ':'; ++p) | |
4573 { | |
4574 if (*p == COM_FIRST) | |
4575 return (leader2_len == 0); | |
4576 if (*p == COM_END) | |
4577 return FALSE; | |
4578 if (*p == COM_START) | |
4579 { | |
4580 if (*(ml_get(lnum) + leader1_len) == NUL) | |
4581 return FALSE; | |
4582 if (leader2_flags == NULL || leader2_len == 0) | |
4583 return FALSE; | |
4584 for (p = leader2_flags; *p && *p != ':'; ++p) | |
4585 if (*p == COM_MIDDLE) | |
4586 return TRUE; | |
4587 return FALSE; | |
4588 } | |
4589 } | |
4590 } | |
4591 | |
4592 /* | |
4593 * Get current line and next line, compare the leaders. | |
4594 * The first line has to be saved, only one line can be locked at a time. | |
4595 */ | |
4596 line1 = vim_strsave(ml_get(lnum)); | |
4597 if (line1 != NULL) | |
4598 { | |
4599 for (idx1 = 0; vim_iswhite(line1[idx1]); ++idx1) | |
4600 ; | |
4601 line2 = ml_get(lnum + 1); | |
4602 for (idx2 = 0; idx2 < leader2_len; ++idx2) | |
4603 { | |
4604 if (!vim_iswhite(line2[idx2])) | |
4605 { | |
4606 if (line1[idx1++] != line2[idx2]) | |
4607 break; | |
4608 } | |
4609 else | |
4610 while (vim_iswhite(line1[idx1])) | |
4611 ++idx1; | |
4612 } | |
4613 vim_free(line1); | |
4614 } | |
4615 return (idx2 == leader2_len && idx1 == leader1_len); | |
4616 } | |
4617 #endif | |
4618 | |
4619 /* | |
3252 | 4620 * Implementation of the format operator 'gq'. |
7 | 4621 */ |
4622 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4623 op_format( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4624 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4625 int keep_cursor) /* keep cursor on same text char */ |
7 | 4626 { |
4627 long old_line_count = curbuf->b_ml.ml_line_count; | |
4628 | |
4629 /* Place the cursor where the "gq" or "gw" command was given, so that "u" | |
4630 * can put it back there. */ | |
4631 curwin->w_cursor = oap->cursor_start; | |
4632 | |
4633 if (u_save((linenr_T)(oap->start.lnum - 1), | |
4634 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
4635 return; | |
4636 curwin->w_cursor = oap->start; | |
4637 | |
4638 if (oap->is_VIsual) | |
4639 /* When there is no change: need to remove the Visual selection */ | |
4640 redraw_curbuf_later(INVERTED); | |
4641 | |
4642 /* Set '[ mark at the start of the formatted area */ | |
4643 curbuf->b_op_start = oap->start; | |
4644 | |
4645 /* For "gw" remember the cursor position and put it back below (adjusted | |
4646 * for joined and split lines). */ | |
4647 if (keep_cursor) | |
4648 saved_cursor = oap->cursor_start; | |
4649 | |
1563 | 4650 format_lines(oap->line_count, keep_cursor); |
7 | 4651 |
4652 /* | |
4653 * Leave the cursor at the first non-blank of the last formatted line. | |
4654 * If the cursor was moved one line back (e.g. with "Q}") go to the next | |
4655 * line, so "." will do the next lines. | |
4656 */ | |
4657 if (oap->end_adjusted && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
4658 ++curwin->w_cursor.lnum; | |
4659 beginline(BL_WHITE | BL_FIX); | |
4660 old_line_count = curbuf->b_ml.ml_line_count - old_line_count; | |
4661 msgmore(old_line_count); | |
4662 | |
4663 /* put '] mark on the end of the formatted area */ | |
4664 curbuf->b_op_end = curwin->w_cursor; | |
4665 | |
4666 if (keep_cursor) | |
4667 { | |
4668 curwin->w_cursor = saved_cursor; | |
4669 saved_cursor.lnum = 0; | |
4670 } | |
4671 | |
4672 if (oap->is_VIsual) | |
4673 { | |
4674 win_T *wp; | |
4675 | |
4676 FOR_ALL_WINDOWS(wp) | |
4677 { | |
4678 if (wp->w_old_cursor_lnum != 0) | |
4679 { | |
4680 /* When lines have been inserted or deleted, adjust the end of | |
4681 * the Visual area to be redrawn. */ | |
4682 if (wp->w_old_cursor_lnum > wp->w_old_visual_lnum) | |
4683 wp->w_old_cursor_lnum += old_line_count; | |
4684 else | |
4685 wp->w_old_visual_lnum += old_line_count; | |
4686 } | |
4687 } | |
4688 } | |
4689 } | |
4690 | |
667 | 4691 #if defined(FEAT_EVAL) || defined(PROTO) |
4692 /* | |
4693 * Implementation of the format operator 'gq' for when using 'formatexpr'. | |
4694 */ | |
4695 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4696 op_formatexpr(oparg_T *oap) |
667 | 4697 { |
4698 if (oap->is_VIsual) | |
4699 /* When there is no change: need to remove the Visual selection */ | |
4700 redraw_curbuf_later(INVERTED); | |
4701 | |
2298
a3562a127cf6
When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
4702 if (fex_format(oap->start.lnum, oap->line_count, NUL) != 0) |
a3562a127cf6
When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
4703 /* As documented: when 'formatexpr' returns non-zero fall back to |
a3562a127cf6
When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
4704 * internal formatting. */ |
a3562a127cf6
When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
4705 op_format(oap, FALSE); |
667 | 4706 } |
4707 | |
4708 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4709 fex_format( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4710 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4711 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4712 int c) /* character to be inserted */ |
667 | 4713 { |
681 | 4714 int use_sandbox = was_set_insecurely((char_u *)"formatexpr", |
4715 OPT_LOCAL); | |
667 | 4716 int r; |
4717 | |
4718 /* | |
4719 * Set v:lnum to the first line number and v:count to the number of lines. | |
844 | 4720 * Set v:char to the character to be inserted (can be NUL). |
667 | 4721 */ |
4722 set_vim_var_nr(VV_LNUM, lnum); | |
4723 set_vim_var_nr(VV_COUNT, count); | |
1969 | 4724 set_vim_var_char(c); |
844 | 4725 |
667 | 4726 /* |
4727 * Evaluate the function. | |
4728 */ | |
4729 if (use_sandbox) | |
4730 ++sandbox; | |
4731 r = eval_to_number(curbuf->b_p_fex); | |
4732 if (use_sandbox) | |
4733 --sandbox; | |
844 | 4734 |
4735 set_vim_var_string(VV_CHAR, NULL, -1); | |
4736 | |
667 | 4737 return r; |
4738 } | |
4739 #endif | |
4740 | |
7 | 4741 /* |
4742 * Format "line_count" lines, starting at the cursor position. | |
4743 * When "line_count" is negative, format until the end of the paragraph. | |
4744 * Lines after the cursor line are saved for undo, caller must have saved the | |
4745 * first line. | |
4746 */ | |
4747 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4748 format_lines( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4749 linenr_T line_count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4750 int avoid_fex) /* don't use 'formatexpr' */ |
7 | 4751 { |
4752 int max_len; | |
4753 int is_not_par; /* current line not part of parag. */ | |
4754 int next_is_not_par; /* next line not part of paragraph */ | |
4755 int is_end_par; /* at end of paragraph */ | |
4756 int prev_is_end_par = FALSE;/* prev. line not part of parag. */ | |
4757 int next_is_start_par = FALSE; | |
4758 #ifdef FEAT_COMMENTS | |
4759 int leader_len = 0; /* leader len of current line */ | |
4760 int next_leader_len; /* leader len of next line */ | |
4761 char_u *leader_flags = NULL; /* flags for leader of current line */ | |
4762 char_u *next_leader_flags; /* flags for leader of next line */ | |
4763 int do_comments; /* format comments */ | |
3584 | 4764 int do_comments_list = 0; /* format comments with 'n' or '2' */ |
7 | 4765 #endif |
4766 int advance = TRUE; | |
3584 | 4767 int second_indent = -1; /* indent for second line (comment |
4768 * aware) */ | |
7 | 4769 int do_second_indent; |
4770 int do_number_indent; | |
4771 int do_trail_white; | |
4772 int first_par_line = TRUE; | |
4773 int smd_save; | |
4774 long count; | |
4775 int need_set_indent = TRUE; /* set indent of next paragraph */ | |
4776 int force_format = FALSE; | |
4777 int old_State = State; | |
4778 | |
4779 /* length of a line to force formatting: 3 * 'tw' */ | |
4780 max_len = comp_textwidth(TRUE) * 3; | |
4781 | |
4782 /* check for 'q', '2' and '1' in 'formatoptions' */ | |
4783 #ifdef FEAT_COMMENTS | |
4784 do_comments = has_format_option(FO_Q_COMS); | |
4785 #endif | |
4786 do_second_indent = has_format_option(FO_Q_SECOND); | |
4787 do_number_indent = has_format_option(FO_Q_NUMBER); | |
4788 do_trail_white = has_format_option(FO_WHITE_PAR); | |
4789 | |
4790 /* | |
4791 * Get info about the previous and current line. | |
4792 */ | |
4793 if (curwin->w_cursor.lnum > 1) | |
4794 is_not_par = fmt_check_par(curwin->w_cursor.lnum - 1 | |
4795 #ifdef FEAT_COMMENTS | |
4796 , &leader_len, &leader_flags, do_comments | |
4797 #endif | |
4798 ); | |
4799 else | |
4800 is_not_par = TRUE; | |
4801 next_is_not_par = fmt_check_par(curwin->w_cursor.lnum | |
4802 #ifdef FEAT_COMMENTS | |
4803 , &next_leader_len, &next_leader_flags, do_comments | |
4804 #endif | |
4805 ); | |
4806 is_end_par = (is_not_par || next_is_not_par); | |
4807 if (!is_end_par && do_trail_white) | |
4808 is_end_par = !ends_in_white(curwin->w_cursor.lnum - 1); | |
4809 | |
4810 curwin->w_cursor.lnum--; | |
4811 for (count = line_count; count != 0 && !got_int; --count) | |
4812 { | |
4813 /* | |
4814 * Advance to next paragraph. | |
4815 */ | |
4816 if (advance) | |
4817 { | |
4818 curwin->w_cursor.lnum++; | |
4819 prev_is_end_par = is_end_par; | |
4820 is_not_par = next_is_not_par; | |
4821 #ifdef FEAT_COMMENTS | |
4822 leader_len = next_leader_len; | |
4823 leader_flags = next_leader_flags; | |
4824 #endif | |
4825 } | |
4826 | |
4827 /* | |
4828 * The last line to be formatted. | |
4829 */ | |
4830 if (count == 1 || curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) | |
4831 { | |
4832 next_is_not_par = TRUE; | |
4833 #ifdef FEAT_COMMENTS | |
4834 next_leader_len = 0; | |
4835 next_leader_flags = NULL; | |
4836 #endif | |
4837 } | |
4838 else | |
4839 { | |
4840 next_is_not_par = fmt_check_par(curwin->w_cursor.lnum + 1 | |
4841 #ifdef FEAT_COMMENTS | |
4842 , &next_leader_len, &next_leader_flags, do_comments | |
4843 #endif | |
4844 ); | |
4845 if (do_number_indent) | |
4846 next_is_start_par = | |
4847 (get_number_indent(curwin->w_cursor.lnum + 1) > 0); | |
4848 } | |
4849 advance = TRUE; | |
4850 is_end_par = (is_not_par || next_is_not_par || next_is_start_par); | |
4851 if (!is_end_par && do_trail_white) | |
4852 is_end_par = !ends_in_white(curwin->w_cursor.lnum); | |
4853 | |
4854 /* | |
4855 * Skip lines that are not in a paragraph. | |
4856 */ | |
4857 if (is_not_par) | |
4858 { | |
4859 if (line_count < 0) | |
4860 break; | |
4861 } | |
4862 else | |
4863 { | |
4864 /* | |
4865 * For the first line of a paragraph, check indent of second line. | |
4866 * Don't do this for comments and empty lines. | |
4867 */ | |
4868 if (first_par_line | |
4869 && (do_second_indent || do_number_indent) | |
4870 && prev_is_end_par | |
3584 | 4871 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) |
4872 { | |
4873 if (do_second_indent && !lineempty(curwin->w_cursor.lnum + 1)) | |
4874 { | |
4875 #ifdef FEAT_COMMENTS | |
4876 if (leader_len == 0 && next_leader_len == 0) | |
4877 { | |
4878 /* no comment found */ | |
4879 #endif | |
4880 second_indent = | |
4881 get_indent_lnum(curwin->w_cursor.lnum + 1); | |
7 | 4882 #ifdef FEAT_COMMENTS |
3584 | 4883 } |
4884 else | |
4885 { | |
4886 second_indent = next_leader_len; | |
4887 do_comments_list = 1; | |
4888 } | |
4889 #endif | |
4890 } | |
7 | 4891 else if (do_number_indent) |
3584 | 4892 { |
4893 #ifdef FEAT_COMMENTS | |
4894 if (leader_len == 0 && next_leader_len == 0) | |
4895 { | |
4896 /* no comment found */ | |
4897 #endif | |
4898 second_indent = | |
4899 get_number_indent(curwin->w_cursor.lnum); | |
4900 #ifdef FEAT_COMMENTS | |
4901 } | |
4902 else | |
4903 { | |
4904 /* get_number_indent() is now "comment aware"... */ | |
4905 second_indent = | |
4906 get_number_indent(curwin->w_cursor.lnum); | |
4907 do_comments_list = 1; | |
4908 } | |
4909 #endif | |
4910 } | |
7 | 4911 } |
4912 | |
4913 /* | |
4914 * When the comment leader changes, it's the end of the paragraph. | |
4915 */ | |
4916 if (curwin->w_cursor.lnum >= curbuf->b_ml.ml_line_count | |
4917 #ifdef FEAT_COMMENTS | |
4918 || !same_leader(curwin->w_cursor.lnum, | |
4919 leader_len, leader_flags, | |
4920 next_leader_len, next_leader_flags) | |
4921 #endif | |
4922 ) | |
4923 is_end_par = TRUE; | |
4924 | |
4925 /* | |
4926 * If we have got to the end of a paragraph, or the line is | |
4927 * getting long, format it. | |
4928 */ | |
4929 if (is_end_par || force_format) | |
4930 { | |
4931 if (need_set_indent) | |
4932 /* replace indent in first line with minimal number of | |
4933 * tabs and spaces, according to current options */ | |
4934 (void)set_indent(get_indent(), SIN_CHANGED); | |
4935 | |
4936 /* put cursor on last non-space */ | |
4937 State = NORMAL; /* don't go past end-of-line */ | |
4938 coladvance((colnr_T)MAXCOL); | |
4939 while (curwin->w_cursor.col && vim_isspace(gchar_cursor())) | |
4940 dec_cursor(); | |
4941 | |
4942 /* do the formatting, without 'showmode' */ | |
4943 State = INSERT; /* for open_line() */ | |
4944 smd_save = p_smd; | |
4945 p_smd = FALSE; | |
4946 insertchar(NUL, INSCHAR_FORMAT | |
4947 #ifdef FEAT_COMMENTS | |
4948 + (do_comments ? INSCHAR_DO_COM : 0) | |
3584 | 4949 + (do_comments && do_comments_list |
4950 ? INSCHAR_COM_LIST : 0) | |
7 | 4951 #endif |
1563 | 4952 + (avoid_fex ? INSCHAR_NO_FEX : 0), second_indent); |
7 | 4953 State = old_State; |
4954 p_smd = smd_save; | |
4955 second_indent = -1; | |
4956 /* at end of par.: need to set indent of next par. */ | |
4957 need_set_indent = is_end_par; | |
4958 if (is_end_par) | |
4959 { | |
4960 /* When called with a negative line count, break at the | |
4961 * end of the paragraph. */ | |
4962 if (line_count < 0) | |
4963 break; | |
4964 first_par_line = TRUE; | |
4965 } | |
4966 force_format = FALSE; | |
4967 } | |
4968 | |
4969 /* | |
4970 * When still in same paragraph, join the lines together. But | |
5403 | 4971 * first delete the leader from the second line. |
7 | 4972 */ |
4973 if (!is_end_par) | |
4974 { | |
4975 advance = FALSE; | |
4976 curwin->w_cursor.lnum++; | |
4977 curwin->w_cursor.col = 0; | |
4978 if (line_count < 0 && u_save_cursor() == FAIL) | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4979 break; |
7 | 4980 #ifdef FEAT_COMMENTS |
4981 if (next_leader_len > 0) | |
5403 | 4982 { |
4983 (void)del_bytes((long)next_leader_len, FALSE, FALSE); | |
7 | 4984 mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L, |
4985 (long)-next_leader_len); | |
5403 | 4986 } else |
4987 #endif | |
4988 if (second_indent > 0) /* the "leader" for FO_Q_SECOND */ | |
4989 { | |
4990 char_u *p = ml_get_curline(); | |
5415 | 4991 int indent = (int)(skipwhite(p) - p); |
5403 | 4992 |
4993 if (indent > 0) | |
4994 { | |
4995 (void)del_bytes(indent, FALSE, FALSE); | |
4996 mark_col_adjust(curwin->w_cursor.lnum, | |
4997 (colnr_T)0, 0L, (long)-indent); | |
5415 | 4998 } |
5403 | 4999 } |
7 | 5000 curwin->w_cursor.lnum--; |
5848 | 5001 if (do_join(2, TRUE, FALSE, FALSE, FALSE) == FAIL) |
7 | 5002 { |
5003 beep_flush(); | |
5004 break; | |
5005 } | |
5006 first_par_line = FALSE; | |
5007 /* If the line is getting long, format it next time */ | |
5008 if (STRLEN(ml_get_curline()) > (size_t)max_len) | |
5009 force_format = TRUE; | |
5010 else | |
5011 force_format = FALSE; | |
5012 } | |
5013 } | |
5014 line_breakcheck(); | |
5015 } | |
5016 } | |
5017 | |
5018 /* | |
5019 * Return TRUE if line "lnum" ends in a white character. | |
5020 */ | |
5021 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5022 ends_in_white(linenr_T lnum) |
7 | 5023 { |
5024 char_u *s = ml_get(lnum); | |
5025 size_t l; | |
5026 | |
5027 if (*s == NUL) | |
5028 return FALSE; | |
5029 /* Don't use STRLEN() inside vim_iswhite(), SAS/C complains: "macro | |
5030 * invocation may call function multiple times". */ | |
5031 l = STRLEN(s) - 1; | |
5032 return vim_iswhite(s[l]); | |
5033 } | |
5034 | |
5035 /* | |
5036 * Blank lines, and lines containing only the comment leader, are left | |
5037 * untouched by the formatting. The function returns TRUE in this | |
5038 * case. It also returns TRUE when a line starts with the end of a comment | |
5039 * ('e' in comment flags), so that this line is skipped, and not joined to the | |
5040 * previous line. A new paragraph starts after a blank line, or when the | |
5041 * comment leader changes -- webb. | |
5042 */ | |
5043 #ifdef FEAT_COMMENTS | |
5044 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5045 fmt_check_par( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5046 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5047 int *leader_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5048 char_u **leader_flags, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5049 int do_comments) |
7 | 5050 { |
5051 char_u *flags = NULL; /* init for GCC */ | |
5052 char_u *ptr; | |
5053 | |
5054 ptr = ml_get(lnum); | |
5055 if (do_comments) | |
3562 | 5056 *leader_len = get_leader_len(ptr, leader_flags, FALSE, TRUE); |
7 | 5057 else |
5058 *leader_len = 0; | |
5059 | |
5060 if (*leader_len > 0) | |
5061 { | |
5062 /* | |
5063 * Search for 'e' flag in comment leader flags. | |
5064 */ | |
5065 flags = *leader_flags; | |
5066 while (*flags && *flags != ':' && *flags != COM_END) | |
5067 ++flags; | |
5068 } | |
5069 | |
5070 return (*skipwhite(ptr + *leader_len) == NUL | |
5071 || (*leader_len > 0 && *flags == COM_END) | |
5072 || startPS(lnum, NUL, FALSE)); | |
5073 } | |
5074 #else | |
5075 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5076 fmt_check_par(linenr_T lnum) |
7 | 5077 { |
5078 return (*skipwhite(ml_get(lnum)) == NUL || startPS(lnum, NUL, FALSE)); | |
5079 } | |
5080 #endif | |
5081 | |
5082 /* | |
5083 * Return TRUE when a paragraph starts in line "lnum". Return FALSE when the | |
5084 * previous line is in the same paragraph. Used for auto-formatting. | |
5085 */ | |
5086 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5087 paragraph_start(linenr_T lnum) |
7 | 5088 { |
5089 char_u *p; | |
5090 #ifdef FEAT_COMMENTS | |
5091 int leader_len = 0; /* leader len of current line */ | |
5092 char_u *leader_flags = NULL; /* flags for leader of current line */ | |
5093 int next_leader_len; /* leader len of next line */ | |
5094 char_u *next_leader_flags; /* flags for leader of next line */ | |
5095 int do_comments; /* format comments */ | |
5096 #endif | |
5097 | |
5098 if (lnum <= 1) | |
5099 return TRUE; /* start of the file */ | |
5100 | |
5101 p = ml_get(lnum - 1); | |
5102 if (*p == NUL) | |
5103 return TRUE; /* after empty line */ | |
5104 | |
5105 #ifdef FEAT_COMMENTS | |
5106 do_comments = has_format_option(FO_Q_COMS); | |
5107 #endif | |
5108 if (fmt_check_par(lnum - 1 | |
5109 #ifdef FEAT_COMMENTS | |
5110 , &leader_len, &leader_flags, do_comments | |
5111 #endif | |
5112 )) | |
5113 return TRUE; /* after non-paragraph line */ | |
5114 | |
5115 if (fmt_check_par(lnum | |
5116 #ifdef FEAT_COMMENTS | |
5117 , &next_leader_len, &next_leader_flags, do_comments | |
5118 #endif | |
5119 )) | |
5120 return TRUE; /* "lnum" is not a paragraph line */ | |
5121 | |
5122 if (has_format_option(FO_WHITE_PAR) && !ends_in_white(lnum - 1)) | |
5123 return TRUE; /* missing trailing space in previous line. */ | |
5124 | |
5125 if (has_format_option(FO_Q_NUMBER) && (get_number_indent(lnum) > 0)) | |
5126 return TRUE; /* numbered item starts in "lnum". */ | |
5127 | |
5128 #ifdef FEAT_COMMENTS | |
5129 if (!same_leader(lnum - 1, leader_len, leader_flags, | |
5130 next_leader_len, next_leader_flags)) | |
5131 return TRUE; /* change of comment leader. */ | |
5132 #endif | |
5133 | |
5134 return FALSE; | |
5135 } | |
5136 | |
5137 /* | |
5138 * prepare a few things for block mode yank/delete/tilde | |
5139 * | |
5140 * for delete: | |
5141 * - textlen includes the first/last char to be (partly) deleted | |
5142 * - start/endspaces is the number of columns that are taken by the | |
5143 * first/last deleted char minus the number of columns that have to be | |
1839 | 5144 * deleted. |
5145 * for yank and tilde: | |
7 | 5146 * - textlen includes the first/last char to be wholly yanked |
5147 * - start/endspaces is the number of columns of the first/last yanked char | |
5148 * that are to be yanked. | |
5149 */ | |
5150 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5151 block_prep( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5152 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5153 struct block_def *bdp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5154 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5155 int is_del) |
7 | 5156 { |
5157 int incr = 0; | |
5158 char_u *pend; | |
5159 char_u *pstart; | |
5160 char_u *line; | |
5161 char_u *prev_pstart; | |
5162 char_u *prev_pend; | |
5163 | |
5164 bdp->startspaces = 0; | |
5165 bdp->endspaces = 0; | |
5166 bdp->textlen = 0; | |
5167 bdp->start_vcol = 0; | |
5168 bdp->end_vcol = 0; | |
5169 #ifdef FEAT_VISUALEXTRA | |
5170 bdp->is_short = FALSE; | |
5171 bdp->is_oneChar = FALSE; | |
5172 bdp->pre_whitesp = 0; | |
5173 bdp->pre_whitesp_c = 0; | |
5174 bdp->end_char_vcols = 0; | |
5175 #endif | |
5176 bdp->start_char_vcols = 0; | |
5177 | |
5178 line = ml_get(lnum); | |
5179 pstart = line; | |
5180 prev_pstart = line; | |
5181 while (bdp->start_vcol < oap->start_vcol && *pstart) | |
5182 { | |
5183 /* Count a tab for what it's worth (if list mode not on) */ | |
5995 | 5184 incr = lbr_chartabsize(line, pstart, (colnr_T)bdp->start_vcol); |
7 | 5185 bdp->start_vcol += incr; |
5186 #ifdef FEAT_VISUALEXTRA | |
5187 if (vim_iswhite(*pstart)) | |
5188 { | |
5189 bdp->pre_whitesp += incr; | |
5190 bdp->pre_whitesp_c++; | |
5191 } | |
5192 else | |
5193 { | |
5194 bdp->pre_whitesp = 0; | |
5195 bdp->pre_whitesp_c = 0; | |
5196 } | |
5197 #endif | |
5198 prev_pstart = pstart; | |
39 | 5199 mb_ptr_adv(pstart); |
7 | 5200 } |
5201 bdp->start_char_vcols = incr; | |
5202 if (bdp->start_vcol < oap->start_vcol) /* line too short */ | |
5203 { | |
5204 bdp->end_vcol = bdp->start_vcol; | |
5205 #ifdef FEAT_VISUALEXTRA | |
5206 bdp->is_short = TRUE; | |
5207 #endif | |
5208 if (!is_del || oap->op_type == OP_APPEND) | |
5209 bdp->endspaces = oap->end_vcol - oap->start_vcol + 1; | |
5210 } | |
5211 else | |
5212 { | |
5213 /* notice: this converts partly selected Multibyte characters to | |
5214 * spaces, too. */ | |
5215 bdp->startspaces = bdp->start_vcol - oap->start_vcol; | |
5216 if (is_del && bdp->startspaces) | |
5217 bdp->startspaces = bdp->start_char_vcols - bdp->startspaces; | |
5218 pend = pstart; | |
5219 bdp->end_vcol = bdp->start_vcol; | |
5220 if (bdp->end_vcol > oap->end_vcol) /* it's all in one character */ | |
5221 { | |
5222 #ifdef FEAT_VISUALEXTRA | |
5223 bdp->is_oneChar = TRUE; | |
5224 #endif | |
5225 if (oap->op_type == OP_INSERT) | |
5226 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces; | |
5227 else if (oap->op_type == OP_APPEND) | |
5228 { | |
5229 bdp->startspaces += oap->end_vcol - oap->start_vcol + 1; | |
5230 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces; | |
5231 } | |
5232 else | |
5233 { | |
5234 bdp->startspaces = oap->end_vcol - oap->start_vcol + 1; | |
5235 if (is_del && oap->op_type != OP_LSHIFT) | |
5236 { | |
5237 /* just putting the sum of those two into | |
5238 * bdp->startspaces doesn't work for Visual replace, | |
5239 * so we have to split the tab in two */ | |
5240 bdp->startspaces = bdp->start_char_vcols | |
5241 - (bdp->start_vcol - oap->start_vcol); | |
5242 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; | |
5243 } | |
5244 } | |
5245 } | |
5246 else | |
5247 { | |
5248 prev_pend = pend; | |
5249 while (bdp->end_vcol <= oap->end_vcol && *pend != NUL) | |
5250 { | |
5251 /* Count a tab for what it's worth (if list mode not on) */ | |
5252 prev_pend = pend; | |
6535 | 5253 incr = lbr_chartabsize_adv(line, &pend, (colnr_T)bdp->end_vcol); |
7 | 5254 bdp->end_vcol += incr; |
5255 } | |
5256 if (bdp->end_vcol <= oap->end_vcol | |
5257 && (!is_del | |
5258 || oap->op_type == OP_APPEND | |
5259 || oap->op_type == OP_REPLACE)) /* line too short */ | |
5260 { | |
5261 #ifdef FEAT_VISUALEXTRA | |
5262 bdp->is_short = TRUE; | |
5263 #endif | |
5264 /* Alternative: include spaces to fill up the block. | |
5265 * Disadvantage: can lead to trailing spaces when the line is | |
5266 * short where the text is put */ | |
5267 /* if (!is_del || oap->op_type == OP_APPEND) */ | |
5268 if (oap->op_type == OP_APPEND || virtual_op) | |
5269 bdp->endspaces = oap->end_vcol - bdp->end_vcol | |
593 | 5270 + oap->inclusive; |
7 | 5271 else |
5272 bdp->endspaces = 0; /* replace doesn't add characters */ | |
5273 } | |
5274 else if (bdp->end_vcol > oap->end_vcol) | |
5275 { | |
5276 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; | |
5277 if (!is_del && bdp->endspaces) | |
5278 { | |
5279 bdp->endspaces = incr - bdp->endspaces; | |
5280 if (pend != pstart) | |
5281 pend = prev_pend; | |
5282 } | |
5283 } | |
5284 } | |
5285 #ifdef FEAT_VISUALEXTRA | |
5286 bdp->end_char_vcols = incr; | |
5287 #endif | |
5288 if (is_del && bdp->startspaces) | |
5289 pstart = prev_pstart; | |
5290 bdp->textlen = (int)(pend - pstart); | |
5291 } | |
5292 bdp->textcol = (colnr_T) (pstart - line); | |
5293 bdp->textstart = pstart; | |
5294 } | |
5295 | |
5296 /* | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5297 * Handle the add/subtract operator. |
7 | 5298 */ |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5299 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5300 op_addsub( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5301 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5302 linenr_T Prenum1, /* Amount of add/subtract */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5303 int g_cmd) /* was g<c-a>/g<c-x> */ |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5304 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5305 pos_T pos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5306 struct block_def bd; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5307 int change_cnt = 0; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5308 linenr_T amount = Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5309 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5310 if (!VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5311 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5312 pos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5313 if (u_save_cursor() == FAIL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5314 return; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5315 change_cnt = do_addsub(oap->op_type, &pos, 0, amount); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5316 if (change_cnt) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5317 changed_lines(pos.lnum, 0, pos.lnum + 1, 0L); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5318 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5319 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5320 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5321 int one_change; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5322 int length; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5323 pos_T startpos; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5324 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5325 if (u_save((linenr_T)(oap->start.lnum - 1), |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5326 (linenr_T)(oap->end.lnum + 1)) == FAIL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5327 return; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5328 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5329 pos = oap->start; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5330 for (; pos.lnum <= oap->end.lnum; ++pos.lnum) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5331 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5332 if (oap->block_mode) /* Visual block mode */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5333 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5334 block_prep(oap, &bd, pos.lnum, FALSE); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5335 pos.col = bd.textcol; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5336 length = bd.textlen; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5337 } |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5338 else if (oap->motion_type == MLINE) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5339 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5340 curwin->w_cursor.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5341 pos.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5342 length = (colnr_T)STRLEN(ml_get(pos.lnum)); |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5343 } |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5344 else /* oap->motion_type == MCHAR */ |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5345 { |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5346 if (!oap->inclusive) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5347 dec(&(oap->end)); |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5348 length = (colnr_T)STRLEN(ml_get(pos.lnum)); |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5349 pos.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5350 if (pos.lnum == oap->start.lnum) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5351 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5352 pos.col += oap->start.col; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5353 length -= oap->start.col; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5354 } |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5355 if (pos.lnum == oap->end.lnum) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5356 { |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5357 length = (int)STRLEN(ml_get(oap->end.lnum)); |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5358 if (oap->end.col >= length) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5359 oap->end.col = length - 1; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5360 length = oap->end.col - pos.col + 1; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5361 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5362 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5363 one_change = do_addsub(oap->op_type, &pos, length, amount); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5364 if (one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5365 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5366 /* Remember the start position of the first change. */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5367 if (change_cnt == 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5368 startpos = curbuf->b_op_start; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5369 ++change_cnt; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5370 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5371 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5372 #ifdef FEAT_NETBEANS_INTG |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5373 if (netbeans_active() && one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5374 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5375 char_u *ptr = ml_get_buf(curbuf, pos.lnum, FALSE); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5376 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5377 netbeans_removed(curbuf, pos.lnum, pos.col, (long)length); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5378 netbeans_inserted(curbuf, pos.lnum, pos.col, |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5379 &ptr[pos.col], length); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5380 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5381 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5382 if (g_cmd && one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5383 amount += Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5384 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5385 if (change_cnt) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5386 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5387 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5388 if (!change_cnt && oap->is_VIsual) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5389 /* No change: need to remove the Visual selection */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5390 redraw_curbuf_later(INVERTED); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5391 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5392 /* Set '[ mark if something changed. Keep the last end |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5393 * position from do_addsub(). */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5394 if (change_cnt > 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5395 curbuf->b_op_start = startpos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5396 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5397 if (change_cnt > p_report) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5398 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5399 if (change_cnt == 1) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5400 MSG(_("1 line changed")); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5401 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5402 smsg((char_u *)_("%ld lines changed"), change_cnt); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5403 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5404 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5405 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5406 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5407 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5408 * Add or subtract 'Prenum1' from a number in a line |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5409 * op_type is OP_NR_ADD or OP_NR_SUB |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5410 * |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5411 * Returns TRUE if some character was changed. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5412 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5413 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5414 do_addsub( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5415 int op_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5416 pos_T *pos, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5417 int length, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5418 linenr_T Prenum1) |
7 | 5419 { |
5420 int col; | |
5421 char_u *buf1; | |
5422 char_u buf2[NUMBUFLEN]; | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5423 int pre; /* 'X'/'x': hex; '0': octal; 'B'/'b': bin */ |
7 | 5424 static int hexupper = FALSE; /* 0xABC */ |
835 | 5425 unsigned long n; |
7 | 5426 long_u oldn; |
5427 char_u *ptr; | |
5428 int c; | |
5429 int todel; | |
5430 int dohex; | |
5431 int dooct; | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5432 int dobin; |
7 | 5433 int doalp; |
5434 int firstdigit; | |
5435 int subtract; | |
6868 | 5436 int negative = FALSE; |
6891 | 5437 int was_positive = TRUE; |
6868 | 5438 int visual = VIsual_active; |
6921 | 5439 int did_change = FALSE; |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5440 pos_T save_cursor = curwin->w_cursor; |
6927 | 5441 int maxlen = 0; |
7570
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5442 pos_T startpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5443 pos_T endpos; |
7 | 5444 |
5445 dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); /* "heX" */ | |
5446 dooct = (vim_strchr(curbuf->b_p_nf, 'o') != NULL); /* "Octal" */ | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5447 dobin = (vim_strchr(curbuf->b_p_nf, 'b') != NULL); /* "Bin" */ |
7 | 5448 doalp = (vim_strchr(curbuf->b_p_nf, 'p') != NULL); /* "alPha" */ |
5449 | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5450 curwin->w_cursor = *pos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5451 ptr = ml_get(pos->lnum); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5452 col = pos->col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5453 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5454 if (*ptr == NUL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5455 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5456 |
7 | 5457 /* |
5458 * First check if we are on a hexadecimal number, after the "0x". | |
5459 */ | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5460 if (!VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5461 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5462 if (dobin) |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5463 while (col > 0 && vim_isbdigit(ptr[col])) |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5464 --col; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5465 |
6868 | 5466 if (dohex) |
5467 while (col > 0 && vim_isxdigit(ptr[col])) | |
5468 --col; | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5469 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5470 if ( dobin |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5471 && dohex |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5472 && ! ((col > 0 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5473 && (ptr[col] == 'X' |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5474 || ptr[col] == 'x') |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5475 && ptr[col - 1] == '0' |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5476 && vim_isxdigit(ptr[col + 1])))) |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5477 { |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5478 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5479 /* In case of binary/hexadecimal pattern overlap match, rescan */ |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5480 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5481 col = pos->col; |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5482 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5483 while (col > 0 && vim_isdigit(ptr[col])) |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5484 col--; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5485 } |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5486 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5487 if (( dohex |
6868 | 5488 && col > 0 |
5489 && (ptr[col] == 'X' | |
5490 || ptr[col] == 'x') | |
5491 && ptr[col - 1] == '0' | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5492 && vim_isxdigit(ptr[col + 1])) || |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5493 ( dobin |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5494 && col > 0 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5495 && (ptr[col] == 'B' |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5496 || ptr[col] == 'b') |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5497 && ptr[col - 1] == '0' |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5498 && vim_isbdigit(ptr[col + 1]))) |
6868 | 5499 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5500 /* Found hexadecimal or binary number, move to its start. */ |
7 | 5501 --col; |
6868 | 5502 } |
5503 else | |
7 | 5504 { |
6868 | 5505 /* |
5506 * Search forward and then backward to find the start of number. | |
5507 */ | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5508 col = pos->col; |
6868 | 5509 |
5510 while (ptr[col] != NUL | |
5511 && !vim_isdigit(ptr[col]) | |
5512 && !(doalp && ASCII_ISALPHA(ptr[col]))) | |
5513 ++col; | |
5514 | |
5515 while (col > 0 | |
5516 && vim_isdigit(ptr[col - 1]) | |
5517 && !(doalp && ASCII_ISALPHA(ptr[col]))) | |
5518 --col; | |
5519 } | |
5520 } | |
5521 | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5522 if (visual) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5523 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5524 while (ptr[col] != NUL && length > 0 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5525 && !vim_isdigit(ptr[col]) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5526 && !(doalp && ASCII_ISALPHA(ptr[col]))) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5527 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5528 ++col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5529 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5530 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5531 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5532 if (length == 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5533 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5534 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5535 if (col > pos->col && ptr[col - 1] == '-') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5536 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5537 negative = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5538 was_positive = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5539 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5540 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5541 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5542 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5543 * If a number was found, and saving for undo works, replace the number. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5544 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5545 firstdigit = ptr[col]; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5546 if (!VIM_ISDIGIT(firstdigit) && !(doalp && ASCII_ISALPHA(firstdigit))) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5547 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5548 beep_flush(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5549 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5550 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5551 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5552 if (doalp && ASCII_ISALPHA(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5553 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5554 /* decrement or increment alphabetic character */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5555 if (op_type == OP_NR_SUB) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5556 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5557 if (CharOrd(firstdigit) < Prenum1) |
6927 | 5558 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5559 if (isupper(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5560 firstdigit = 'A'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5561 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5562 firstdigit = 'a'; |
6927 | 5563 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5564 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5565 #ifdef EBCDIC |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5566 firstdigit = EBCDIC_CHAR_ADD(firstdigit, -Prenum1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5567 #else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5568 firstdigit -= Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5569 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5570 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5571 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5572 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5573 if (26 - CharOrd(firstdigit) - 1 < Prenum1) |
6927 | 5574 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5575 if (isupper(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5576 firstdigit = 'Z'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5577 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5578 firstdigit = 'z'; |
6927 | 5579 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5580 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5581 #ifdef EBCDIC |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5582 firstdigit = EBCDIC_CHAR_ADD(firstdigit, Prenum1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5583 #else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5584 firstdigit += Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5585 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5586 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5587 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5588 if (!did_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5589 startpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5590 did_change = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5591 (void)del_char(FALSE); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5592 ins_char(firstdigit); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5593 endpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5594 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5595 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5596 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5597 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5598 if (col > 0 && ptr[col - 1] == '-' && !visual) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5599 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5600 /* negative number */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5601 --col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5602 negative = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5603 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5604 /* get the number value (unsigned) */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5605 if (visual && VIsual_mode != 'V') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5606 maxlen = (curbuf->b_visual.vi_curswant == MAXCOL |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5607 ? (int)STRLEN(ptr) - col |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5608 : length); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5609 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5610 vim_str2nr(ptr + col, &pre, &length, |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5611 0 + (dobin ? STR2NR_BIN : 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5612 + (dooct ? STR2NR_OCT : 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5613 + (dohex ? STR2NR_HEX : 0), |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5614 NULL, &n, maxlen); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5615 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5616 /* ignore leading '-' for hex and octal and bin numbers */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5617 if (pre && negative) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5618 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5619 ++col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5620 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5621 negative = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5622 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5623 /* add or subtract */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5624 subtract = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5625 if (op_type == OP_NR_SUB) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5626 subtract ^= TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5627 if (negative) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5628 subtract ^= TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5629 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5630 oldn = n; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5631 if (subtract) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5632 n -= (unsigned long)Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5633 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5634 n += (unsigned long)Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5635 /* handle wraparound for decimal numbers */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5636 if (!pre) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5637 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5638 if (subtract) |
6927 | 5639 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5640 if (n > oldn) |
6868 | 5641 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5642 n = 1 + (n ^ (unsigned long)-1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5643 negative ^= TRUE; |
6868 | 5644 } |
7 | 5645 } |
5646 else | |
6868 | 5647 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5648 /* add */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5649 if (n < oldn) |
6868 | 5650 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5651 n = (n ^ (unsigned long)-1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5652 negative ^= TRUE; |
6868 | 5653 } |
6927 | 5654 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5655 if (n == 0) |
6868 | 5656 negative = FALSE; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5657 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5658 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5659 if (visual && !was_positive && !negative && col > 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5660 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5661 /* need to remove the '-' */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5662 col--; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5663 length++; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5664 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5665 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5666 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5667 * Delete the old number. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5668 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5669 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5670 if (!did_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5671 startpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5672 did_change = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5673 todel = length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5674 c = gchar_cursor(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5675 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5676 * Don't include the '-' in the length, only the length of the |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5677 * part after it is kept the same. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5678 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5679 if (c == '-') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5680 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5681 while (todel-- > 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5682 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5683 if (c < 0x100 && isalpha(c)) |
6868 | 5684 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5685 if (isupper(c)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5686 hexupper = TRUE; |
6868 | 5687 else |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5688 hexupper = FALSE; |
6891 | 5689 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5690 /* del_char() will mark line needing displaying */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5691 (void)del_char(FALSE); |
6868 | 5692 c = gchar_cursor(); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5693 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5694 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5695 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5696 * Prepare the leading characters in buf1[]. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5697 * When there are many leading zeros it could be very long. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5698 * Allocate a bit too much. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5699 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5700 buf1 = alloc((unsigned)length + NUMBUFLEN); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5701 if (buf1 == NULL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5702 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5703 ptr = buf1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5704 if (negative && (!visual || (visual && was_positive))) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5705 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5706 *ptr++ = '-'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5707 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5708 if (pre) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5709 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5710 *ptr++ = '0'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5711 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5712 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5713 if (pre == 'b' || pre == 'B' || |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5714 pre == 'x' || pre == 'X') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5715 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5716 *ptr++ = pre; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5717 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5718 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5719 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5720 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5721 * Put the number characters in buf2[]. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5722 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5723 if (pre == 'b' || pre == 'B') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5724 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5725 int i; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5726 int bit = 0; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5727 int bits = sizeof(unsigned long) * 8; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5728 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5729 /* leading zeros */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5730 for (bit = bits; bit > 0; bit--) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5731 if ((n >> (bit - 1)) & 0x1) break; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5732 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5733 for (i = 0; bit > 0; bit--) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5734 buf2[i++] = ((n >> (bit - 1)) & 0x1) ? '1' : '0'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5735 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5736 buf2[i] = '\0'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5737 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5738 else if (pre == 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5739 sprintf((char *)buf2, "%lu", n); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5740 else if (pre == '0') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5741 sprintf((char *)buf2, "%lo", n); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5742 else if (pre && hexupper) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5743 sprintf((char *)buf2, "%lX", n); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5744 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5745 sprintf((char *)buf2, "%lx", n); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5746 length -= (int)STRLEN(buf2); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5747 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5748 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5749 * Adjust number of zeros to the new number of digits, so the |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5750 * total length of the number remains the same. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5751 * Don't do this when |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5752 * the result may look like an octal number. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5753 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5754 if (firstdigit == '0' && !(dooct && pre == 0)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5755 while (length-- > 0) |
6868 | 5756 *ptr++ = '0'; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5757 *ptr = NUL; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5758 STRCAT(buf1, buf2); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5759 ins_str(buf1); /* insert the new number */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5760 vim_free(buf1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5761 endpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5762 if (did_change && curwin->w_cursor.col) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5763 --curwin->w_cursor.col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5764 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5765 |
7570
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5766 if (did_change) |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5767 { |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5768 /* set the '[ and '] marks */ |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5769 curbuf->b_op_start = startpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5770 curbuf->b_op_end = endpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5771 if (curbuf->b_op_end.col > 0) |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5772 --curbuf->b_op_end.col; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5773 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5774 |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5775 theend: |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5776 if (visual) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5777 curwin->w_cursor = save_cursor; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5778 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5779 return did_change; |
7 | 5780 } |
5781 | |
5782 #ifdef FEAT_VIMINFO | |
5783 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5784 read_viminfo_register(vir_T *virp, int force) |
7 | 5785 { |
5786 int eof; | |
5787 int do_it = TRUE; | |
5788 int size; | |
5789 int limit; | |
5790 int i; | |
5791 int set_prev = FALSE; | |
5792 char_u *str; | |
5793 char_u **array = NULL; | |
6508 | 5794 int new_type = MCHAR; /* init to shut up compiler */ |
5795 colnr_T new_width = 0; /* init to shut up compiler */ | |
7 | 5796 |
5797 /* We only get here (hopefully) if line[0] == '"' */ | |
5798 str = virp->vir_line + 1; | |
1893 | 5799 |
5800 /* If the line starts with "" this is the y_previous register. */ | |
7 | 5801 if (*str == '"') |
5802 { | |
5803 set_prev = TRUE; | |
5804 str++; | |
5805 } | |
1893 | 5806 |
7 | 5807 if (!ASCII_ISALNUM(*str) && *str != '-') |
5808 { | |
5809 if (viminfo_error("E577: ", _("Illegal register name"), virp->vir_line)) | |
5810 return TRUE; /* too many errors, pretend end-of-file */ | |
5811 do_it = FALSE; | |
5812 } | |
5813 get_yank_register(*str++, FALSE); | |
5814 if (!force && y_current->y_array != NULL) | |
5815 do_it = FALSE; | |
1893 | 5816 |
5817 if (*str == '@') | |
5818 { | |
5819 /* "x@: register x used for @@ */ | |
5820 if (force || execreg_lastc == NUL) | |
5821 execreg_lastc = str[-1]; | |
5822 } | |
5823 | |
7 | 5824 size = 0; |
5825 limit = 100; /* Optimized for registers containing <= 100 lines */ | |
5826 if (do_it) | |
5827 { | |
6462 | 5828 /* |
5829 * Build the new register in array[]. | |
5830 * y_array is kept as-is until done. | |
5831 * The "do_it" flag is reset when something is wrong, in which case | |
5832 * array[] needs to be freed. | |
5833 */ | |
7 | 5834 if (set_prev) |
5835 y_previous = y_current; | |
6462 | 5836 array = (char_u **)alloc((unsigned)(limit * sizeof(char_u *))); |
1893 | 5837 str = skipwhite(skiptowhite(str)); |
7 | 5838 if (STRNCMP(str, "CHAR", 4) == 0) |
6462 | 5839 new_type = MCHAR; |
7 | 5840 else if (STRNCMP(str, "BLOCK", 5) == 0) |
6462 | 5841 new_type = MBLOCK; |
7 | 5842 else |
6462 | 5843 new_type = MLINE; |
7 | 5844 /* get the block width; if it's missing we get a zero, which is OK */ |
5845 str = skipwhite(skiptowhite(str)); | |
6462 | 5846 new_width = getdigits(&str); |
7 | 5847 } |
5848 | |
5849 while (!(eof = viminfo_readline(virp)) | |
5850 && (virp->vir_line[0] == TAB || virp->vir_line[0] == '<')) | |
5851 { | |
5852 if (do_it) | |
5853 { | |
6462 | 5854 if (size == limit) |
7 | 5855 { |
6462 | 5856 char_u **new_array = (char_u **) |
7 | 5857 alloc((unsigned)(limit * 2 * sizeof(char_u *))); |
6462 | 5858 |
5859 if (new_array == NULL) | |
5860 { | |
5861 do_it = FALSE; | |
5862 break; | |
5863 } | |
7 | 5864 for (i = 0; i < limit; i++) |
6462 | 5865 new_array[i] = array[i]; |
7 | 5866 vim_free(array); |
6462 | 5867 array = new_array; |
7 | 5868 limit *= 2; |
5869 } | |
5870 str = viminfo_readstring(virp, 1, TRUE); | |
5871 if (str != NULL) | |
5872 array[size++] = str; | |
5873 else | |
6462 | 5874 /* error, don't store the result */ |
7 | 5875 do_it = FALSE; |
5876 } | |
5877 } | |
6508 | 5878 |
7 | 5879 if (do_it) |
5880 { | |
6462 | 5881 /* free y_array[] */ |
5882 for (i = 0; i < y_current->y_size; i++) | |
5883 vim_free(y_current->y_array[i]); | |
5884 vim_free(y_current->y_array); | |
5885 | |
5886 y_current->y_type = new_type; | |
5887 y_current->y_width = new_width; | |
5888 y_current->y_size = size; | |
7 | 5889 if (size == 0) |
5890 { | |
5891 y_current->y_array = NULL; | |
5892 } | |
6462 | 5893 else |
7 | 5894 { |
6462 | 5895 /* Move the lines from array[] to y_array[]. */ |
7 | 5896 y_current->y_array = |
5897 (char_u **)alloc((unsigned)(size * sizeof(char_u *))); | |
5898 for (i = 0; i < size; i++) | |
6462 | 5899 { |
5900 if (y_current->y_array == NULL) | |
5901 vim_free(array[i]); | |
5902 else | |
5903 y_current->y_array[i] = array[i]; | |
5904 } | |
7 | 5905 } |
6462 | 5906 } |
5907 else | |
5908 { | |
5909 /* Free array[] if it was filled. */ | |
5910 for (i = 0; i < size; i++) | |
5911 vim_free(array[i]); | |
5912 } | |
5913 vim_free(array); | |
5914 | |
7 | 5915 return eof; |
5916 } | |
5917 | |
5918 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5919 write_viminfo_registers(FILE *fp) |
7 | 5920 { |
5921 int i, j; | |
5922 char_u *type; | |
5923 char_u c; | |
5924 int num_lines; | |
5925 int max_num_lines; | |
5926 int max_kbyte; | |
5927 long len; | |
5928 | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
5929 fputs(_("\n# Registers:\n"), fp); |
7 | 5930 |
5931 /* Get '<' value, use old '"' value if '<' is not found. */ | |
5932 max_num_lines = get_viminfo_parameter('<'); | |
5933 if (max_num_lines < 0) | |
5934 max_num_lines = get_viminfo_parameter('"'); | |
5935 if (max_num_lines == 0) | |
5936 return; | |
5937 max_kbyte = get_viminfo_parameter('s'); | |
5938 if (max_kbyte == 0) | |
5939 return; | |
1893 | 5940 |
7 | 5941 for (i = 0; i < NUM_REGISTERS; i++) |
5942 { | |
5943 if (y_regs[i].y_array == NULL) | |
5944 continue; | |
5945 #ifdef FEAT_CLIPBOARD | |
5946 /* Skip '*'/'+' register, we don't want them back next time */ | |
5947 if (i == STAR_REGISTER || i == PLUS_REGISTER) | |
5948 continue; | |
5949 #endif | |
5950 #ifdef FEAT_DND | |
5951 /* Neither do we want the '~' register */ | |
5952 if (i == TILDE_REGISTER) | |
5953 continue; | |
5954 #endif | |
55 | 5955 /* Skip empty registers. */ |
7 | 5956 num_lines = y_regs[i].y_size; |
55 | 5957 if (num_lines == 0 |
5958 || (num_lines == 1 && y_regs[i].y_type == MCHAR | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
5959 && *y_regs[i].y_array[0] == NUL)) |
55 | 5960 continue; |
5961 | |
7 | 5962 if (max_kbyte > 0) |
5963 { | |
5964 /* Skip register if there is more text than the maximum size. */ | |
5965 len = 0; | |
5966 for (j = 0; j < num_lines; j++) | |
835 | 5967 len += (long)STRLEN(y_regs[i].y_array[j]) + 1L; |
7 | 5968 if (len > (long)max_kbyte * 1024L) |
5969 continue; | |
5970 } | |
5971 | |
5972 switch (y_regs[i].y_type) | |
5973 { | |
5974 case MLINE: | |
5975 type = (char_u *)"LINE"; | |
5976 break; | |
5977 case MCHAR: | |
5978 type = (char_u *)"CHAR"; | |
5979 break; | |
5980 case MBLOCK: | |
5981 type = (char_u *)"BLOCK"; | |
5982 break; | |
5983 default: | |
5984 sprintf((char *)IObuff, _("E574: Unknown register type %d"), | |
274 | 5985 y_regs[i].y_type); |
7 | 5986 emsg(IObuff); |
5987 type = (char_u *)"LINE"; | |
5988 break; | |
5989 } | |
5990 if (y_previous == &y_regs[i]) | |
5991 fprintf(fp, "\""); | |
5992 c = get_register_name(i); | |
1893 | 5993 fprintf(fp, "\"%c", c); |
5994 if (c == execreg_lastc) | |
5995 fprintf(fp, "@"); | |
5735 | 5996 fprintf(fp, "\t%s\t%d\n", type, (int)y_regs[i].y_width); |
7 | 5997 |
5998 /* If max_num_lines < 0, then we save ALL the lines in the register */ | |
5999 if (max_num_lines > 0 && num_lines > max_num_lines) | |
6000 num_lines = max_num_lines; | |
6001 for (j = 0; j < num_lines; j++) | |
6002 { | |
6003 putc('\t', fp); | |
6004 viminfo_writestring(fp, y_regs[i].y_array[j]); | |
6005 } | |
6006 } | |
6007 } | |
6008 #endif /* FEAT_VIMINFO */ | |
6009 | |
6010 #if defined(FEAT_CLIPBOARD) || defined(PROTO) | |
6011 /* | |
6012 * SELECTION / PRIMARY ('*') | |
6013 * | |
6014 * Text selection stuff that uses the GUI selection register '*'. When using a | |
6015 * GUI this may be text from another window, otherwise it is the last text we | |
6016 * had highlighted with VIsual mode. With mouse support, clicking the middle | |
6017 * button performs the paste, otherwise you will need to do <"*p>. " | |
6018 * If not under X, it is synonymous with the clipboard register '+'. | |
6019 * | |
6020 * X CLIPBOARD ('+') | |
6021 * | |
6022 * Text selection stuff that uses the GUI clipboard register '+'. | |
6023 * Under X, this matches the standard cut/paste buffer CLIPBOARD selection. | |
6024 * It will be used for unnamed cut/pasting is 'clipboard' contains "unnamed", | |
6025 * otherwise you will need to do <"+p>. " | |
6026 * If not under X, it is synonymous with the selection register '*'. | |
6027 */ | |
6028 | |
6029 /* | |
6030 * Routine to export any final X selection we had to the environment | |
6031 * so that the text is still available after vim has exited. X selections | |
6032 * only exist while the owning application exists, so we write to the | |
6033 * permanent (while X runs) store CUT_BUFFER0. | |
6034 * Dump the CLIPBOARD selection if we own it (it's logically the more | |
6035 * 'permanent' of the two), otherwise the PRIMARY one. | |
6036 * For now, use a hard-coded sanity limit of 1Mb of data. | |
6037 */ | |
6038 #if defined(FEAT_X11) && defined(FEAT_CLIPBOARD) | |
6039 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6040 x11_export_final_selection(void) |
7 | 6041 { |
6042 Display *dpy; | |
6043 char_u *str = NULL; | |
6044 long_u len = 0; | |
6045 int motion_type = -1; | |
6046 | |
6047 # ifdef FEAT_GUI | |
6048 if (gui.in_use) | |
6049 dpy = X_DISPLAY; | |
6050 else | |
6051 # endif | |
6052 # ifdef FEAT_XCLIPBOARD | |
6053 dpy = xterm_dpy; | |
6054 # else | |
6055 return; | |
6056 # endif | |
6057 | |
6058 /* Get selection to export */ | |
6059 if (clip_plus.owned) | |
6060 motion_type = clip_convert_selection(&str, &len, &clip_plus); | |
6061 else if (clip_star.owned) | |
6062 motion_type = clip_convert_selection(&str, &len, &clip_star); | |
6063 | |
6064 /* Check it's OK */ | |
6065 if (dpy != NULL && str != NULL && motion_type >= 0 | |
6066 && len < 1024*1024 && len > 0) | |
6067 { | |
1924 | 6068 #ifdef FEAT_MBYTE |
4201 | 6069 int ok = TRUE; |
6070 | |
1924 | 6071 /* The CUT_BUFFER0 is supposed to always contain latin1. Convert from |
6072 * 'enc' when it is a multi-byte encoding. When 'enc' is an 8-bit | |
6073 * encoding conversion usually doesn't work, so keep the text as-is. | |
6074 */ | |
6075 if (has_mbyte) | |
6076 { | |
6077 vimconv_T vc; | |
6078 | |
6079 vc.vc_type = CONV_NONE; | |
6080 if (convert_setup(&vc, p_enc, (char_u *)"latin1") == OK) | |
6081 { | |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2007
diff
changeset
|
6082 int intlen = len; |
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2007
diff
changeset
|
6083 char_u *conv_str; |
2007 | 6084 |
4201 | 6085 vc.vc_fail = TRUE; |
2007 | 6086 conv_str = string_convert(&vc, str, &intlen); |
6087 len = intlen; | |
1924 | 6088 if (conv_str != NULL) |
6089 { | |
6090 vim_free(str); | |
6091 str = conv_str; | |
6092 } | |
4201 | 6093 else |
6094 { | |
6095 ok = FALSE; | |
6096 } | |
1924 | 6097 convert_setup(&vc, NULL, NULL); |
6098 } | |
4201 | 6099 else |
6100 { | |
6101 ok = FALSE; | |
6102 } | |
1924 | 6103 } |
4201 | 6104 |
6105 /* Do not store the string if conversion failed. Better to use any | |
6106 * other selection than garbled text. */ | |
6107 if (ok) | |
6108 #endif | |
6109 { | |
6110 XStoreBuffer(dpy, (char *)str, (int)len, 0); | |
6111 XFlush(dpy); | |
6112 } | |
7 | 6113 } |
6114 | |
6115 vim_free(str); | |
6116 } | |
6117 #endif | |
6118 | |
6119 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6120 clip_free_selection(VimClipboard *cbd) |
7 | 6121 { |
6122 struct yankreg *y_ptr = y_current; | |
6123 | |
6124 if (cbd == &clip_plus) | |
6125 y_current = &y_regs[PLUS_REGISTER]; | |
6126 else | |
6127 y_current = &y_regs[STAR_REGISTER]; | |
6128 free_yank_all(); | |
6129 y_current->y_size = 0; | |
6130 y_current = y_ptr; | |
6131 } | |
6132 | |
6133 /* | |
6134 * Get the selected text and put it in the gui selection register '*' or '+'. | |
6135 */ | |
6136 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6137 clip_get_selection(VimClipboard *cbd) |
7 | 6138 { |
6139 struct yankreg *old_y_previous, *old_y_current; | |
6140 pos_T old_cursor; | |
6141 pos_T old_visual; | |
6142 int old_visual_mode; | |
6143 colnr_T old_curswant; | |
6144 int old_set_curswant; | |
6145 pos_T old_op_start, old_op_end; | |
6146 oparg_T oa; | |
6147 cmdarg_T ca; | |
6148 | |
6149 if (cbd->owned) | |
6150 { | |
6151 if ((cbd == &clip_plus && y_regs[PLUS_REGISTER].y_array != NULL) | |
6152 || (cbd == &clip_star && y_regs[STAR_REGISTER].y_array != NULL)) | |
6153 return; | |
6154 | |
6155 /* Get the text between clip_star.start & clip_star.end */ | |
6156 old_y_previous = y_previous; | |
6157 old_y_current = y_current; | |
6158 old_cursor = curwin->w_cursor; | |
6159 old_curswant = curwin->w_curswant; | |
6160 old_set_curswant = curwin->w_set_curswant; | |
6161 old_op_start = curbuf->b_op_start; | |
6162 old_op_end = curbuf->b_op_end; | |
6163 old_visual = VIsual; | |
6164 old_visual_mode = VIsual_mode; | |
6165 clear_oparg(&oa); | |
6166 oa.regname = (cbd == &clip_plus ? '+' : '*'); | |
6167 oa.op_type = OP_YANK; | |
6168 vim_memset(&ca, 0, sizeof(ca)); | |
6169 ca.oap = &oa; | |
6170 ca.cmdchar = 'y'; | |
6171 ca.count1 = 1; | |
6172 ca.retval = CA_NO_ADJ_OP_END; | |
6173 do_pending_operator(&ca, 0, TRUE); | |
6174 y_previous = old_y_previous; | |
6175 y_current = old_y_current; | |
6176 curwin->w_cursor = old_cursor; | |
688 | 6177 changed_cline_bef_curs(); /* need to update w_virtcol et al */ |
7 | 6178 curwin->w_curswant = old_curswant; |
6179 curwin->w_set_curswant = old_set_curswant; | |
6180 curbuf->b_op_start = old_op_start; | |
6181 curbuf->b_op_end = old_op_end; | |
6182 VIsual = old_visual; | |
6183 VIsual_mode = old_visual_mode; | |
6184 } | |
6185 else | |
6186 { | |
6187 clip_free_selection(cbd); | |
6188 | |
6189 /* Try to get selected text from another window */ | |
6190 clip_gen_request_selection(cbd); | |
6191 } | |
6192 } | |
6193 | |
2896 | 6194 /* |
6195 * Convert from the GUI selection string into the '*'/'+' register. | |
6196 */ | |
7 | 6197 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6198 clip_yank_selection( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6199 int type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6200 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6201 long len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6202 VimClipboard *cbd) |
7 | 6203 { |
6204 struct yankreg *y_ptr; | |
6205 | |
6206 if (cbd == &clip_plus) | |
6207 y_ptr = &y_regs[PLUS_REGISTER]; | |
6208 else | |
6209 y_ptr = &y_regs[STAR_REGISTER]; | |
6210 | |
6211 clip_free_selection(cbd); | |
6212 | |
5798 | 6213 str_to_reg(y_ptr, type, str, len, 0L, FALSE); |
7 | 6214 } |
6215 | |
6216 /* | |
6217 * Convert the '*'/'+' register into a GUI selection string returned in *str | |
6218 * with length *len. | |
6219 * Returns the motion type, or -1 for failure. | |
6220 */ | |
6221 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6222 clip_convert_selection(char_u **str, long_u *len, VimClipboard *cbd) |
7 | 6223 { |
6224 char_u *p; | |
6225 int lnum; | |
6226 int i, j; | |
6227 int_u eolsize; | |
6228 struct yankreg *y_ptr; | |
6229 | |
6230 if (cbd == &clip_plus) | |
6231 y_ptr = &y_regs[PLUS_REGISTER]; | |
6232 else | |
6233 y_ptr = &y_regs[STAR_REGISTER]; | |
6234 | |
6235 #ifdef USE_CRNL | |
6236 eolsize = 2; | |
6237 #else | |
6238 eolsize = 1; | |
6239 #endif | |
6240 | |
6241 *str = NULL; | |
6242 *len = 0; | |
6243 if (y_ptr->y_array == NULL) | |
6244 return -1; | |
6245 | |
6246 for (i = 0; i < y_ptr->y_size; i++) | |
6247 *len += (long_u)STRLEN(y_ptr->y_array[i]) + eolsize; | |
6248 | |
6249 /* | |
6250 * Don't want newline character at end of last line if we're in MCHAR mode. | |
6251 */ | |
6252 if (y_ptr->y_type == MCHAR && *len >= eolsize) | |
6253 *len -= eolsize; | |
6254 | |
6255 p = *str = lalloc(*len + 1, TRUE); /* add one to avoid zero */ | |
6256 if (p == NULL) | |
6257 return -1; | |
6258 lnum = 0; | |
6259 for (i = 0, j = 0; i < (int)*len; i++, j++) | |
6260 { | |
6261 if (y_ptr->y_array[lnum][j] == '\n') | |
6262 p[i] = NUL; | |
6263 else if (y_ptr->y_array[lnum][j] == NUL) | |
6264 { | |
6265 #ifdef USE_CRNL | |
6266 p[i++] = '\r'; | |
6267 #endif | |
6268 #ifdef USE_CR | |
6269 p[i] = '\r'; | |
6270 #else | |
6271 p[i] = '\n'; | |
6272 #endif | |
6273 lnum++; | |
6274 j = -1; | |
6275 } | |
6276 else | |
6277 p[i] = y_ptr->y_array[lnum][j]; | |
6278 } | |
6279 return y_ptr->y_type; | |
6280 } | |
6281 | |
6282 | |
6283 /* | |
6284 * If we have written to a clipboard register, send the text to the clipboard. | |
6285 */ | |
6286 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6287 may_set_selection(void) |
7 | 6288 { |
6289 if (y_current == &(y_regs[STAR_REGISTER]) && clip_star.available) | |
6290 { | |
6291 clip_own_selection(&clip_star); | |
6292 clip_gen_set_selection(&clip_star); | |
6293 } | |
6294 else if (y_current == &(y_regs[PLUS_REGISTER]) && clip_plus.available) | |
6295 { | |
6296 clip_own_selection(&clip_plus); | |
6297 clip_gen_set_selection(&clip_plus); | |
6298 } | |
6299 } | |
6300 | |
6301 #endif /* FEAT_CLIPBOARD || PROTO */ | |
6302 | |
6303 | |
6304 #if defined(FEAT_DND) || defined(PROTO) | |
6305 /* | |
6306 * Replace the contents of the '~' register with str. | |
6307 */ | |
6308 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6309 dnd_yank_drag_data(char_u *str, long len) |
7 | 6310 { |
6311 struct yankreg *curr; | |
6312 | |
6313 curr = y_current; | |
6314 y_current = &y_regs[TILDE_REGISTER]; | |
6315 free_yank_all(); | |
5798 | 6316 str_to_reg(y_current, MCHAR, str, len, 0L, FALSE); |
7 | 6317 y_current = curr; |
6318 } | |
6319 #endif | |
6320 | |
6321 | |
6322 #if defined(FEAT_EVAL) || defined(PROTO) | |
6323 /* | |
6324 * Return the type of a register. | |
6325 * Used for getregtype() | |
6326 * Returns MAUTO for error. | |
6327 */ | |
6328 char_u | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6329 get_reg_type(int regname, long *reglen) |
7 | 6330 { |
6331 switch (regname) | |
6332 { | |
6333 case '%': /* file name */ | |
6334 case '#': /* alternate file name */ | |
6335 case '=': /* expression */ | |
6336 case ':': /* last command line */ | |
6337 case '/': /* last search-pattern */ | |
6338 case '.': /* last inserted text */ | |
6339 #ifdef FEAT_SEARCHPATH | |
6340 case Ctrl_F: /* Filename under cursor */ | |
6341 case Ctrl_P: /* Path under cursor, expand via "path" */ | |
6342 #endif | |
6343 case Ctrl_W: /* word under cursor */ | |
6344 case Ctrl_A: /* WORD (mnemonic All) under cursor */ | |
6345 case '_': /* black hole: always empty */ | |
6346 return MCHAR; | |
6347 } | |
6348 | |
6349 #ifdef FEAT_CLIPBOARD | |
6350 regname = may_get_selection(regname); | |
6351 #endif | |
6352 | |
5596 | 6353 if (regname != NUL && !valid_yank_reg(regname, FALSE)) |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
6354 return MAUTO; |
5596 | 6355 |
7 | 6356 get_yank_register(regname, FALSE); |
6357 | |
6358 if (y_current->y_array != NULL) | |
6359 { | |
6360 if (reglen != NULL && y_current->y_type == MBLOCK) | |
6361 *reglen = y_current->y_width; | |
6362 return y_current->y_type; | |
6363 } | |
6364 return MAUTO; | |
6365 } | |
6366 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
6367 static char_u *getreg_wrap_one_line(char_u *s, int flags); |
5796 | 6368 |
6369 /* | |
6370 * When "flags" has GREG_LIST return a list with text "s". | |
6371 * Otherwise just return "s". | |
6372 */ | |
6373 static char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6374 getreg_wrap_one_line(char_u *s, int flags) |
5796 | 6375 { |
6376 if (flags & GREG_LIST) | |
6377 { | |
6378 list_T *list = list_alloc(); | |
6379 | |
6380 if (list != NULL) | |
6381 { | |
6382 if (list_append_string(list, NULL, -1) == FAIL) | |
6383 { | |
6384 list_free(list, TRUE); | |
6385 return NULL; | |
6386 } | |
6387 list->lv_first->li_tv.vval.v_string = s; | |
6388 } | |
6389 return (char_u *)list; | |
6390 } | |
6391 return s; | |
6392 } | |
6393 | |
7 | 6394 /* |
6395 * Return the contents of a register as a single allocated string. | |
6396 * Used for "@r" in expressions and for getreg(). | |
6397 * Returns NULL for error. | |
5796 | 6398 * Flags: |
6399 * GREG_NO_EXPR Do not allow expression register | |
6400 * GREG_EXPR_SRC For the expression register: return expression itself, | |
6401 * not the result of its evaluation. | |
6402 * GREG_LIST Return a list of lines in place of a single string. | |
7 | 6403 */ |
6404 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6405 get_reg_contents(int regname, int flags) |
7 | 6406 { |
6407 long i; | |
6408 char_u *retval; | |
6409 int allocated; | |
6410 long len; | |
6411 | |
6412 /* Don't allow using an expression register inside an expression */ | |
6413 if (regname == '=') | |
6414 { | |
5796 | 6415 if (flags & GREG_NO_EXPR) |
6416 return NULL; | |
6417 if (flags & GREG_EXPR_SRC) | |
6418 return getreg_wrap_one_line(get_expr_line_src(), flags); | |
6419 return getreg_wrap_one_line(get_expr_line(), flags); | |
7 | 6420 } |
6421 | |
6422 if (regname == '@') /* "@@" is used for unnamed register */ | |
6423 regname = '"'; | |
6424 | |
6425 /* check for valid regname */ | |
6426 if (regname != NUL && !valid_yank_reg(regname, FALSE)) | |
6427 return NULL; | |
6428 | |
6429 #ifdef FEAT_CLIPBOARD | |
6430 regname = may_get_selection(regname); | |
6431 #endif | |
6432 | |
6433 if (get_spec_reg(regname, &retval, &allocated, FALSE)) | |
6434 { | |
6435 if (retval == NULL) | |
6436 return NULL; | |
5796 | 6437 if (allocated) |
6438 return getreg_wrap_one_line(retval, flags); | |
6439 return getreg_wrap_one_line(vim_strsave(retval), flags); | |
7 | 6440 } |
6441 | |
6442 get_yank_register(regname, FALSE); | |
6443 if (y_current->y_array == NULL) | |
6444 return NULL; | |
6445 | |
5796 | 6446 if (flags & GREG_LIST) |
6447 { | |
6448 list_T *list = list_alloc(); | |
6449 int error = FALSE; | |
6450 | |
6451 if (list == NULL) | |
6452 return NULL; | |
6453 for (i = 0; i < y_current->y_size; ++i) | |
6454 if (list_append_string(list, y_current->y_array[i], -1) == FAIL) | |
6455 error = TRUE; | |
6456 if (error) | |
6457 { | |
6458 list_free(list, TRUE); | |
6459 return NULL; | |
6460 } | |
6461 return (char_u *)list; | |
6462 } | |
6463 | |
7 | 6464 /* |
6465 * Compute length of resulting string. | |
6466 */ | |
6467 len = 0; | |
6468 for (i = 0; i < y_current->y_size; ++i) | |
6469 { | |
6470 len += (long)STRLEN(y_current->y_array[i]); | |
6471 /* | |
6472 * Insert a newline between lines and after last line if | |
6473 * y_type is MLINE. | |
6474 */ | |
6475 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | |
6476 ++len; | |
6477 } | |
6478 | |
6479 retval = lalloc(len + 1, TRUE); | |
6480 | |
6481 /* | |
6482 * Copy the lines of the yank register into the string. | |
6483 */ | |
6484 if (retval != NULL) | |
6485 { | |
6486 len = 0; | |
6487 for (i = 0; i < y_current->y_size; ++i) | |
6488 { | |
6489 STRCPY(retval + len, y_current->y_array[i]); | |
6490 len += (long)STRLEN(retval + len); | |
6491 | |
6492 /* | |
6493 * Insert a NL between lines and after the last line if y_type is | |
6494 * MLINE. | |
6495 */ | |
6496 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | |
6497 retval[len++] = '\n'; | |
6498 } | |
6499 retval[len] = NUL; | |
6500 } | |
6501 | |
6502 return retval; | |
6503 } | |
6504 | |
5798 | 6505 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6506 init_write_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6507 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6508 struct yankreg **old_y_previous, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6509 struct yankreg **old_y_current, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6510 int must_append, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6511 int *yank_type UNUSED) |
5798 | 6512 { |
6513 if (!valid_yank_reg(name, TRUE)) /* check for valid reg name */ | |
6514 { | |
6515 emsg_invreg(name); | |
6516 return FAIL; | |
6517 } | |
6518 | |
6519 /* Don't want to change the current (unnamed) register */ | |
6520 *old_y_previous = y_previous; | |
6521 *old_y_current = y_current; | |
6522 | |
6523 get_yank_register(name, TRUE); | |
6524 if (!y_append && !must_append) | |
6525 free_yank_all(); | |
6526 return OK; | |
6527 } | |
6528 | |
6529 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6530 finish_write_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6531 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6532 struct yankreg *old_y_previous, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6533 struct yankreg *old_y_current) |
5798 | 6534 { |
6535 # ifdef FEAT_CLIPBOARD | |
6536 /* Send text of clipboard register to the clipboard. */ | |
6537 may_set_selection(); | |
6538 # endif | |
6539 | |
6540 /* ':let @" = "val"' should change the meaning of the "" register */ | |
6541 if (name != '"') | |
6542 y_previous = old_y_previous; | |
6543 y_current = old_y_current; | |
6544 } | |
6545 | |
7 | 6546 /* |
6547 * Store string "str" in register "name". | |
6548 * "maxlen" is the maximum number of bytes to use, -1 for all bytes. | |
6549 * If "must_append" is TRUE, always append to the register. Otherwise append | |
6550 * if "name" is an uppercase letter. | |
6551 * Note: "maxlen" and "must_append" don't work for the "/" register. | |
6552 * Careful: 'str' is modified, you may have to use a copy! | |
6553 * If "str" ends in '\n' or '\r', use linewise, otherwise use characterwise. | |
6554 */ | |
6555 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6556 write_reg_contents( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6557 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6558 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6559 int maxlen, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6560 int must_append) |
7 | 6561 { |
6562 write_reg_contents_ex(name, str, maxlen, must_append, MAUTO, 0L); | |
6563 } | |
6564 | |
6565 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6566 write_reg_contents_lst( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6567 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6568 char_u **strings, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6569 int maxlen UNUSED, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6570 int must_append, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6571 int yank_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6572 long block_len) |
5798 | 6573 { |
6574 struct yankreg *old_y_previous, *old_y_current; | |
6575 | |
6576 if (name == '/' | |
6577 #ifdef FEAT_EVAL | |
6578 || name == '=' | |
6579 #endif | |
6580 ) | |
6581 { | |
6582 char_u *s; | |
6583 | |
6584 if (strings[0] == NULL) | |
6585 s = (char_u *)""; | |
6586 else if (strings[1] != NULL) | |
6587 { | |
6588 EMSG(_("E883: search pattern and expression register may not " | |
6589 "contain two or more lines")); | |
6590 return; | |
6591 } | |
6592 else | |
6593 s = strings[0]; | |
6594 write_reg_contents_ex(name, s, -1, must_append, yank_type, block_len); | |
6595 return; | |
6596 } | |
6597 | |
6598 if (name == '_') /* black hole: nothing to do */ | |
6599 return; | |
6600 | |
6601 if (init_write_reg(name, &old_y_previous, &old_y_current, must_append, | |
6602 &yank_type) == FAIL) | |
6603 return; | |
6604 | |
6605 str_to_reg(y_current, yank_type, (char_u *) strings, -1, block_len, TRUE); | |
6606 | |
6607 finish_write_reg(name, old_y_previous, old_y_current); | |
6608 } | |
6609 | |
6610 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6611 write_reg_contents_ex( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6612 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6613 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6614 int maxlen, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6615 int must_append, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6616 int yank_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6617 long block_len) |
7 | 6618 { |
6619 struct yankreg *old_y_previous, *old_y_current; | |
6620 long len; | |
6621 | |
336 | 6622 if (maxlen >= 0) |
6623 len = maxlen; | |
6624 else | |
6625 len = (long)STRLEN(str); | |
6626 | |
7 | 6627 /* Special case: '/' search pattern */ |
6628 if (name == '/') | |
6629 { | |
6630 set_last_search_pat(str, RE_SEARCH, TRUE, TRUE); | |
6631 return; | |
6632 } | |
6633 | |
6557 | 6634 if (name == '#') |
6635 { | |
6636 buf_T *buf; | |
6637 | |
6638 if (VIM_ISDIGIT(*str)) | |
6639 { | |
6640 int num = atoi((char *)str); | |
6641 | |
6642 buf = buflist_findnr(num); | |
6643 if (buf == NULL) | |
6644 EMSGN(_(e_nobufnr), (long)num); | |
6645 } | |
6646 else | |
6647 buf = buflist_findnr(buflist_findpat(str, str + STRLEN(str), | |
6648 TRUE, FALSE, FALSE)); | |
6649 if (buf == NULL) | |
6650 return; | |
6651 curwin->w_alt_fnum = buf->b_fnum; | |
6652 return; | |
6653 } | |
6654 | |
336 | 6655 #ifdef FEAT_EVAL |
6656 if (name == '=') | |
6657 { | |
6658 char_u *p, *s; | |
6659 | |
6660 p = vim_strnsave(str, (int)len); | |
6661 if (p == NULL) | |
6662 return; | |
6663 if (must_append) | |
6664 { | |
6665 s = concat_str(get_expr_line_src(), p); | |
6666 vim_free(p); | |
6667 p = s; | |
6668 } | |
6669 set_expr_line(p); | |
6670 return; | |
6671 } | |
6672 #endif | |
6673 | |
7 | 6674 if (name == '_') /* black hole: nothing to do */ |
6675 return; | |
6676 | |
5798 | 6677 if (init_write_reg(name, &old_y_previous, &old_y_current, must_append, |
6678 &yank_type) == FAIL) | |
6679 return; | |
6680 | |
6681 str_to_reg(y_current, yank_type, str, len, block_len, FALSE); | |
6682 | |
6683 finish_write_reg(name, old_y_previous, old_y_current); | |
7 | 6684 } |
6685 #endif /* FEAT_EVAL */ | |
6686 | |
6687 #if defined(FEAT_CLIPBOARD) || defined(FEAT_EVAL) | |
6688 /* | |
6689 * Put a string into a register. When the register is not empty, the string | |
6690 * is appended. | |
6691 */ | |
6692 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6693 str_to_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6694 struct yankreg *y_ptr, /* pointer to yank register */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6695 int yank_type, /* MCHAR, MLINE, MBLOCK, MAUTO */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6696 char_u *str, /* string to put in register */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6697 long len, /* length of string */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6698 long blocklen, /* width of Visual block */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6699 int str_list) /* TRUE if str is char_u ** */ |
7 | 6700 { |
2896 | 6701 int type; /* MCHAR, MLINE or MBLOCK */ |
7 | 6702 int lnum; |
6703 long start; | |
6704 long i; | |
6705 int extra; | |
6706 int newlines; /* number of lines added */ | |
6707 int extraline = 0; /* extra line at the end */ | |
6708 int append = FALSE; /* append to last line in register */ | |
6709 char_u *s; | |
5798 | 6710 char_u **ss; |
7 | 6711 char_u **pp; |
6712 long maxlen; | |
6713 | |
2000 | 6714 if (y_ptr->y_array == NULL) /* NULL means empty register */ |
7 | 6715 y_ptr->y_size = 0; |
6716 | |
2896 | 6717 if (yank_type == MAUTO) |
5798 | 6718 type = ((str_list || (len > 0 && (str[len - 1] == NL |
6719 || str[len - 1] == CAR))) | |
2896 | 6720 ? MLINE : MCHAR); |
6721 else | |
6722 type = yank_type; | |
6723 | |
7 | 6724 /* |
6725 * Count the number of lines within the string | |
6726 */ | |
6727 newlines = 0; | |
5798 | 6728 if (str_list) |
6729 { | |
6730 for (ss = (char_u **) str; *ss != NULL; ++ss) | |
7 | 6731 ++newlines; |
5798 | 6732 } |
6733 else | |
6734 { | |
6735 for (i = 0; i < len; i++) | |
6736 if (str[i] == '\n') | |
6737 ++newlines; | |
6738 if (type == MCHAR || len == 0 || str[len - 1] != '\n') | |
6739 { | |
6740 extraline = 1; | |
6741 ++newlines; /* count extra newline at the end */ | |
6742 } | |
6743 if (y_ptr->y_size > 0 && y_ptr->y_type == MCHAR) | |
6744 { | |
6745 append = TRUE; | |
6746 --newlines; /* uncount newline when appending first line */ | |
6747 } | |
7 | 6748 } |
6749 | |
6807 | 6750 /* Without any lines make the register empty. */ |
6751 if (y_ptr->y_size + newlines == 0) | |
6752 { | |
6753 vim_free(y_ptr->y_array); | |
6754 y_ptr->y_array = NULL; | |
6755 return; | |
6756 } | |
6757 | |
7 | 6758 /* |
6759 * Allocate an array to hold the pointers to the new register lines. | |
6760 * If the register was not empty, move the existing lines to the new array. | |
6761 */ | |
6762 pp = (char_u **)lalloc_clear((y_ptr->y_size + newlines) | |
6763 * sizeof(char_u *), TRUE); | |
6764 if (pp == NULL) /* out of memory */ | |
6765 return; | |
6766 for (lnum = 0; lnum < y_ptr->y_size; ++lnum) | |
6767 pp[lnum] = y_ptr->y_array[lnum]; | |
6768 vim_free(y_ptr->y_array); | |
6769 y_ptr->y_array = pp; | |
6770 maxlen = 0; | |
6771 | |
6772 /* | |
6773 * Find the end of each line and save it into the array. | |
6774 */ | |
5798 | 6775 if (str_list) |
6776 { | |
6777 for (ss = (char_u **) str; *ss != NULL; ++ss, ++lnum) | |
7 | 6778 { |
5856 | 6779 i = (long)STRLEN(*ss); |
5798 | 6780 pp[lnum] = vim_strnsave(*ss, i); |
6781 if (i > maxlen) | |
6782 maxlen = i; | |
7 | 6783 } |
5798 | 6784 } |
6785 else | |
6786 { | |
6787 for (start = 0; start < len + extraline; start += i + 1) | |
7 | 6788 { |
5798 | 6789 for (i = start; i < len; ++i) /* find the end of the line */ |
6790 if (str[i] == '\n') | |
6791 break; | |
6792 i -= start; /* i is now length of line */ | |
6793 if (i > maxlen) | |
6794 maxlen = i; | |
6795 if (append) | |
6796 { | |
6797 --lnum; | |
6798 extra = (int)STRLEN(y_ptr->y_array[lnum]); | |
6799 } | |
6800 else | |
6801 extra = 0; | |
6802 s = alloc((unsigned)(i + extra + 1)); | |
6803 if (s == NULL) | |
6804 break; | |
6805 if (extra) | |
6806 mch_memmove(s, y_ptr->y_array[lnum], (size_t)extra); | |
6807 if (append) | |
6808 vim_free(y_ptr->y_array[lnum]); | |
6809 if (i) | |
6810 mch_memmove(s + extra, str + start, (size_t)i); | |
6811 extra += i; | |
6812 s[extra] = NUL; | |
6813 y_ptr->y_array[lnum++] = s; | |
6814 while (--extra >= 0) | |
6815 { | |
6816 if (*s == NUL) | |
6817 *s = '\n'; /* replace NUL with newline */ | |
6818 ++s; | |
6819 } | |
6820 append = FALSE; /* only first line is appended */ | |
7 | 6821 } |
6822 } | |
6823 y_ptr->y_type = type; | |
6824 y_ptr->y_size = lnum; | |
6825 if (type == MBLOCK) | |
6826 y_ptr->y_width = (blocklen < 0 ? maxlen - 1 : blocklen); | |
6827 else | |
6828 y_ptr->y_width = 0; | |
6829 } | |
6830 #endif /* FEAT_CLIPBOARD || FEAT_EVAL || PROTO */ | |
6831 | |
6832 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6833 clear_oparg(oparg_T *oap) |
7 | 6834 { |
6835 vim_memset(oap, 0, sizeof(oparg_T)); | |
6836 } | |
6837 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
6838 static long line_count_info(char_u *line, long *wc, long *cc, long limit, int eol_size); |
7 | 6839 |
6840 /* | |
161 | 6841 * Count the number of bytes, characters and "words" in a line. |
7 | 6842 * |
6843 * "Words" are counted by looking for boundaries between non-space and | |
6844 * space characters. (it seems to produce results that match 'wc'.) | |
6845 * | |
161 | 6846 * Return value is byte count; word count for the line is added to "*wc". |
6847 * Char count is added to "*cc". | |
7 | 6848 * |
6849 * The function will only examine the first "limit" characters in the | |
6850 * line, stopping if it encounters an end-of-line (NUL byte). In that | |
6851 * case, eol_size will be added to the character count to account for | |
6852 * the size of the EOL character. | |
6853 */ | |
6854 static long | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6855 line_count_info( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6856 char_u *line, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6857 long *wc, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6858 long *cc, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6859 long limit, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6860 int eol_size) |
7 | 6861 { |
161 | 6862 long i; |
6863 long words = 0; | |
6864 long chars = 0; | |
7 | 6865 int is_word = 0; |
6866 | |
3626 | 6867 for (i = 0; i < limit && line[i] != NUL; ) |
7 | 6868 { |
6869 if (is_word) | |
6870 { | |
6871 if (vim_isspace(line[i])) | |
6872 { | |
6873 words++; | |
6874 is_word = 0; | |
6875 } | |
6876 } | |
6877 else if (!vim_isspace(line[i])) | |
6878 is_word = 1; | |
161 | 6879 ++chars; |
6880 #ifdef FEAT_MBYTE | |
474 | 6881 i += (*mb_ptr2len)(line + i); |
161 | 6882 #else |
6883 ++i; | |
6884 #endif | |
7 | 6885 } |
6886 | |
6887 if (is_word) | |
6888 words++; | |
6889 *wc += words; | |
6890 | |
6891 /* Add eol_size if the end of line was reached before hitting limit. */ | |
2996 | 6892 if (i < limit && line[i] == NUL) |
161 | 6893 { |
7 | 6894 i += eol_size; |
161 | 6895 chars += eol_size; |
6896 } | |
6897 *cc += chars; | |
7 | 6898 return i; |
6899 } | |
6900 | |
6901 /* | |
6902 * Give some info about the position of the cursor (for "g CTRL-G"). | |
6903 * In Visual mode, give some info about the selected region. (In this case, | |
6904 * the *_count_cursor variables store running totals for the selection.) | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
6905 * When "dict" is not NULL store the info there instead of showing it. |
7 | 6906 */ |
6907 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6908 cursor_pos_info(dict_T *dict) |
7 | 6909 { |
6910 char_u *p; | |
274 | 6911 char_u buf1[50]; |
6912 char_u buf2[40]; | |
7 | 6913 linenr_T lnum; |
161 | 6914 long byte_count = 0; |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
6915 #ifdef FEAT_MBYTE |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
6916 long bom_count = 0; |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
6917 #endif |
161 | 6918 long byte_count_cursor = 0; |
7 | 6919 long char_count = 0; |
6920 long char_count_cursor = 0; | |
161 | 6921 long word_count = 0; |
6922 long word_count_cursor = 0; | |
7 | 6923 int eol_size; |
6924 long last_check = 100000L; | |
6925 long line_count_selected = 0; | |
6926 pos_T min_pos, max_pos; | |
6927 oparg_T oparg; | |
6928 struct block_def bd; | |
6929 | |
6930 /* | |
6931 * Compute the length of the file in characters. | |
6932 */ | |
6933 if (curbuf->b_ml.ml_flags & ML_EMPTY) | |
6934 { | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
6935 if (dict == NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
6936 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
6937 MSG(_(no_lines_msg)); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
6938 return; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
6939 } |
7 | 6940 } |
6941 else | |
6942 { | |
6943 if (get_fileformat(curbuf) == EOL_DOS) | |
6944 eol_size = 2; | |
6945 else | |
6946 eol_size = 1; | |
6947 | |
6948 if (VIsual_active) | |
6949 { | |
6950 if (lt(VIsual, curwin->w_cursor)) | |
6951 { | |
6952 min_pos = VIsual; | |
6953 max_pos = curwin->w_cursor; | |
6954 } | |
6955 else | |
6956 { | |
6957 min_pos = curwin->w_cursor; | |
6958 max_pos = VIsual; | |
6959 } | |
6960 if (*p_sel == 'e' && max_pos.col > 0) | |
6961 --max_pos.col; | |
6962 | |
6963 if (VIsual_mode == Ctrl_V) | |
6964 { | |
1866 | 6965 #ifdef FEAT_LINEBREAK |
6966 char_u * saved_sbr = p_sbr; | |
6967 | |
6968 /* Make 'sbr' empty for a moment to get the correct size. */ | |
6969 p_sbr = empty_option; | |
6970 #endif | |
7 | 6971 oparg.is_VIsual = 1; |
6972 oparg.block_mode = TRUE; | |
6973 oparg.op_type = OP_NOP; | |
6974 getvcols(curwin, &min_pos, &max_pos, | |
688 | 6975 &oparg.start_vcol, &oparg.end_vcol); |
1866 | 6976 #ifdef FEAT_LINEBREAK |
6977 p_sbr = saved_sbr; | |
6978 #endif | |
688 | 6979 if (curwin->w_curswant == MAXCOL) |
6980 oparg.end_vcol = MAXCOL; | |
7 | 6981 /* Swap the start, end vcol if needed */ |
6982 if (oparg.end_vcol < oparg.start_vcol) | |
6983 { | |
6984 oparg.end_vcol += oparg.start_vcol; | |
6985 oparg.start_vcol = oparg.end_vcol - oparg.start_vcol; | |
6986 oparg.end_vcol -= oparg.start_vcol; | |
6987 } | |
6988 } | |
6989 line_count_selected = max_pos.lnum - min_pos.lnum + 1; | |
6990 } | |
6991 | |
6992 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) | |
6993 { | |
6994 /* Check for a CTRL-C every 100000 characters. */ | |
161 | 6995 if (byte_count > last_check) |
7 | 6996 { |
6997 ui_breakcheck(); | |
6998 if (got_int) | |
6999 return; | |
161 | 7000 last_check = byte_count + 100000L; |
7 | 7001 } |
7002 | |
7003 /* Do extra processing for VIsual mode. */ | |
7004 if (VIsual_active | |
7005 && lnum >= min_pos.lnum && lnum <= max_pos.lnum) | |
7006 { | |
45 | 7007 char_u *s = NULL; |
7008 long len = 0L; | |
7009 | |
7 | 7010 switch (VIsual_mode) |
7011 { | |
7012 case Ctrl_V: | |
5735 | 7013 #ifdef FEAT_VIRTUALEDIT |
7 | 7014 virtual_op = virtual_active(); |
5735 | 7015 #endif |
7 | 7016 block_prep(&oparg, &bd, lnum, 0); |
5735 | 7017 #ifdef FEAT_VIRTUALEDIT |
7 | 7018 virtual_op = MAYBE; |
5735 | 7019 #endif |
45 | 7020 s = bd.textstart; |
7021 len = (long)bd.textlen; | |
7 | 7022 break; |
7023 case 'V': | |
45 | 7024 s = ml_get(lnum); |
7025 len = MAXCOL; | |
7 | 7026 break; |
7027 case 'v': | |
7028 { | |
7029 colnr_T start_col = (lnum == min_pos.lnum) | |
7030 ? min_pos.col : 0; | |
7031 colnr_T end_col = (lnum == max_pos.lnum) | |
7032 ? max_pos.col - start_col + 1 : MAXCOL; | |
7033 | |
45 | 7034 s = ml_get(lnum) + start_col; |
7035 len = end_col; | |
7 | 7036 } |
7037 break; | |
7038 } | |
45 | 7039 if (s != NULL) |
7040 { | |
161 | 7041 byte_count_cursor += line_count_info(s, &word_count_cursor, |
7042 &char_count_cursor, len, eol_size); | |
45 | 7043 if (lnum == curbuf->b_ml.ml_line_count |
7044 && !curbuf->b_p_eol | |
6933 | 7045 && (curbuf->b_p_bin || !curbuf->b_p_fixeol) |
50 | 7046 && (long)STRLEN(s) < len) |
161 | 7047 byte_count_cursor -= eol_size; |
45 | 7048 } |
7 | 7049 } |
7050 else | |
7051 { | |
7052 /* In non-visual mode, check for the line the cursor is on */ | |
7053 if (lnum == curwin->w_cursor.lnum) | |
7054 { | |
7055 word_count_cursor += word_count; | |
161 | 7056 char_count_cursor += char_count; |
7057 byte_count_cursor = byte_count + | |
7058 line_count_info(ml_get(lnum), | |
7059 &word_count_cursor, &char_count_cursor, | |
7 | 7060 (long)(curwin->w_cursor.col + 1), eol_size); |
7061 } | |
7062 } | |
7063 /* Add to the running totals */ | |
161 | 7064 byte_count += line_count_info(ml_get(lnum), &word_count, |
7065 &char_count, (long)MAXCOL, eol_size); | |
7 | 7066 } |
7067 | |
7068 /* Correction for when last line doesn't have an EOL. */ | |
6933 | 7069 if (!curbuf->b_p_eol && (curbuf->b_p_bin || !curbuf->b_p_fixeol)) |
161 | 7070 byte_count -= eol_size; |
7 | 7071 |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7072 if (dict == NULL) |
7 | 7073 { |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7074 if (VIsual_active) |
7 | 7075 { |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7076 if (VIsual_mode == Ctrl_V && curwin->w_curswant < MAXCOL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7077 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7078 getvcols(curwin, &min_pos, &max_pos, &min_pos.col, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7079 &max_pos.col); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7080 vim_snprintf((char *)buf1, sizeof(buf1), _("%ld Cols; "), |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7081 (long)(oparg.end_vcol - oparg.start_vcol + 1)); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7082 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7083 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7084 buf1[0] = NUL; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7085 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7086 if (char_count_cursor == byte_count_cursor |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7087 && char_count == byte_count) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7088 vim_snprintf((char *)IObuff, IOSIZE, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7089 _("Selected %s%ld of %ld Lines; %ld of %ld Words; %ld of %ld Bytes"), |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7090 buf1, line_count_selected, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7091 (long)curbuf->b_ml.ml_line_count, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7092 word_count_cursor, word_count, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7093 byte_count_cursor, byte_count); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7094 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7095 vim_snprintf((char *)IObuff, IOSIZE, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7096 _("Selected %s%ld of %ld Lines; %ld of %ld Words; %ld of %ld Chars; %ld of %ld Bytes"), |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7097 buf1, line_count_selected, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7098 (long)curbuf->b_ml.ml_line_count, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7099 word_count_cursor, word_count, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7100 char_count_cursor, char_count, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7101 byte_count_cursor, byte_count); |
7 | 7102 } |
7103 else | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7104 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7105 p = ml_get_curline(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7106 validate_virtcol(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7107 col_print(buf1, sizeof(buf1), (int)curwin->w_cursor.col + 1, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7108 (int)curwin->w_virtcol + 1); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7109 col_print(buf2, sizeof(buf2), (int)STRLEN(p), |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7110 linetabsize(p)); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7111 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7112 if (char_count_cursor == byte_count_cursor |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7113 && char_count == byte_count) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7114 vim_snprintf((char *)IObuff, IOSIZE, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7115 _("Col %s of %s; Line %ld of %ld; Word %ld of %ld; Byte %ld of %ld"), |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7116 (char *)buf1, (char *)buf2, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7117 (long)curwin->w_cursor.lnum, |
7 | 7118 (long)curbuf->b_ml.ml_line_count, |
7119 word_count_cursor, word_count, | |
161 | 7120 byte_count_cursor, byte_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7121 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7122 vim_snprintf((char *)IObuff, IOSIZE, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7123 _("Col %s of %s; Line %ld of %ld; Word %ld of %ld; Char %ld of %ld; Byte %ld of %ld"), |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7124 (char *)buf1, (char *)buf2, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7125 (long)curwin->w_cursor.lnum, |
161 | 7126 (long)curbuf->b_ml.ml_line_count, |
7127 word_count_cursor, word_count, | |
7128 char_count_cursor, char_count, | |
7129 byte_count_cursor, byte_count); | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7130 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7131 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7132 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7133 #ifdef FEAT_MBYTE |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7134 bom_count = bomb_size(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7135 if (bom_count > 0) |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7136 vim_snprintf((char *)IObuff + STRLEN(IObuff), IOSIZE, |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7137 _("(+%ld for BOM)"), bom_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7138 #endif |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7139 if (dict == NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7140 { |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7141 /* Don't shorten this message, the user asked for it. */ |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7142 p = p_shm; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7143 p_shm = (char_u *)""; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7144 msg(IObuff); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7145 p_shm = p; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7146 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7147 } |
7484
1fe988587423
commit https://github.com/vim/vim/commit/718272a7e13c71095ce07eb3b3d5e1f9790a6991
Christian Brabandt <cb@256bit.org>
parents:
7480
diff
changeset
|
7148 #if defined(FEAT_EVAL) |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7149 if (dict != NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7150 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7151 dict_add_nr_str(dict, "words", (long)word_count, NULL); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7152 dict_add_nr_str(dict, "chars", (long)char_count, NULL); |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7153 dict_add_nr_str(dict, "bytes", (long)byte_count |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7154 # ifdef FEAT_MBYTE |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7155 + bom_count |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7156 # endif |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7157 , NULL); |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7158 dict_add_nr_str(dict, VIsual_active ? "visual_bytes" : "cursor_bytes", |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7159 (long)byte_count_cursor, NULL); |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7160 dict_add_nr_str(dict, VIsual_active ? "visual_chars" : "cursor_chars", |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7161 (long)char_count_cursor, NULL); |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7162 dict_add_nr_str(dict, VIsual_active ? "visual_words" : "cursor_words", |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7163 (long)word_count_cursor, NULL); |
7 | 7164 } |
7484
1fe988587423
commit https://github.com/vim/vim/commit/718272a7e13c71095ce07eb3b3d5e1f9790a6991
Christian Brabandt <cb@256bit.org>
parents:
7480
diff
changeset
|
7165 #endif |
7 | 7166 } |