Mercurial > vim
annotate src/ops.c @ 9833:e764104bc7c1
Added tag v7.4.2191 for changeset 568ea507b0cd0995840aa42c762f125812760223
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Wed, 10 Aug 2016 21:00:08 +0200 |
parents | 32e34e574716 |
children | 80ace3687eec |
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 /* | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
53 * Each yank register has an array of pointers to lines. |
7 | 54 */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
55 typedef struct |
7 | 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 */ | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
61 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
62 time_t y_time_set; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
63 #endif |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
64 } yankreg_T; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
65 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
66 static yankreg_T y_regs[NUM_REGISTERS]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
67 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
68 static yankreg_T *y_current; /* ptr to current yankreg */ |
7 | 69 static int y_append; /* TRUE when appending */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
70 static yankreg_T *y_previous = NULL; /* ptr to last written yankreg */ |
7 | 71 |
72 /* | |
73 * structure used by block_prep, op_delete and op_yank for blockwise operators | |
74 * also op_change, op_shift, op_insert, op_replace - AKelly | |
75 */ | |
76 struct block_def | |
77 { | |
1839 | 78 int startspaces; /* 'extra' cols before first char */ |
79 int endspaces; /* 'extra' cols after last char */ | |
7 | 80 int textlen; /* chars in block */ |
1839 | 81 char_u *textstart; /* pointer to 1st char (partially) in block */ |
82 colnr_T textcol; /* index of chars (partially) in block */ | |
7 | 83 colnr_T start_vcol; /* start col of 1st char wholly inside block */ |
84 colnr_T end_vcol; /* start col of 1st char wholly after block */ | |
85 #ifdef FEAT_VISUALEXTRA | |
86 int is_short; /* TRUE if line is too short to fit in block */ | |
87 int is_MAX; /* TRUE if curswant==MAXCOL when starting */ | |
88 int is_oneChar; /* TRUE if block within one character */ | |
89 int pre_whitesp; /* screen cols of ws before block */ | |
90 int pre_whitesp_c; /* chars of ws before block */ | |
91 colnr_T end_char_vcols; /* number of vcols of post-block char */ | |
92 #endif | |
93 colnr_T start_char_vcols; /* number of vcols of pre-block char */ | |
94 }; | |
95 | |
96 #ifdef FEAT_VISUALEXTRA | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
97 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
|
98 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
|
99 #endif |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
100 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
|
101 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
|
102 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
|
103 int silent); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
104 static void stuffescaped(char_u *arg, int literally); |
7 | 105 #ifdef FEAT_MBYTE |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
106 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
|
107 #endif |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
108 static void free_yank(long); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
109 static void free_yank_all(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
110 static int yank_copy_line(struct block_def *bd, long y_idx); |
7 | 111 #ifdef FEAT_CLIPBOARD |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
112 static void copy_yank_reg(yankreg_T *reg); |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
113 static void may_set_selection(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
114 #endif |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
115 static void dis_msg(char_u *p, int skip_esc); |
3562 | 116 #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
|
117 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
|
118 #endif |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
119 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
|
120 static int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1); |
7 | 121 #if defined(FEAT_CLIPBOARD) || defined(FEAT_EVAL) |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
122 static void str_to_reg(yankreg_T *y_ptr, int yank_type, char_u *str, long len, long blocklen, int str_list); |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
123 #endif |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
124 static int ends_in_white(linenr_T lnum); |
7 | 125 #ifdef FEAT_COMMENTS |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
126 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
|
127 static int fmt_check_par(linenr_T, int *, char_u **, int do_comments); |
7 | 128 #else |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
129 static int fmt_check_par(linenr_T); |
7 | 130 #endif |
131 | |
132 /* | |
133 * The names of operators. | |
134 * IMPORTANT: Index must correspond with defines in vim.h!!! | |
135 * The third field indicates whether the operator always works on lines. | |
136 */ | |
137 static char opchars[][3] = | |
138 { | |
139 {NUL, NUL, FALSE}, /* OP_NOP */ | |
140 {'d', NUL, FALSE}, /* OP_DELETE */ | |
141 {'y', NUL, FALSE}, /* OP_YANK */ | |
142 {'c', NUL, FALSE}, /* OP_CHANGE */ | |
143 {'<', NUL, TRUE}, /* OP_LSHIFT */ | |
144 {'>', NUL, TRUE}, /* OP_RSHIFT */ | |
145 {'!', NUL, TRUE}, /* OP_FILTER */ | |
146 {'g', '~', FALSE}, /* OP_TILDE */ | |
147 {'=', NUL, TRUE}, /* OP_INDENT */ | |
148 {'g', 'q', TRUE}, /* OP_FORMAT */ | |
149 {':', NUL, TRUE}, /* OP_COLON */ | |
150 {'g', 'U', FALSE}, /* OP_UPPER */ | |
151 {'g', 'u', FALSE}, /* OP_LOWER */ | |
152 {'J', NUL, TRUE}, /* DO_JOIN */ | |
153 {'g', 'J', TRUE}, /* DO_JOIN_NS */ | |
154 {'g', '?', FALSE}, /* OP_ROT13 */ | |
155 {'r', NUL, FALSE}, /* OP_REPLACE */ | |
156 {'I', NUL, FALSE}, /* OP_INSERT */ | |
157 {'A', NUL, FALSE}, /* OP_APPEND */ | |
158 {'z', 'f', TRUE}, /* OP_FOLD */ | |
159 {'z', 'o', TRUE}, /* OP_FOLDOPEN */ | |
160 {'z', 'O', TRUE}, /* OP_FOLDOPENREC */ | |
161 {'z', 'c', TRUE}, /* OP_FOLDCLOSE */ | |
162 {'z', 'C', TRUE}, /* OP_FOLDCLOSEREC */ | |
163 {'z', 'd', TRUE}, /* OP_FOLDDEL */ | |
164 {'z', 'D', TRUE}, /* OP_FOLDDELREC */ | |
165 {'g', 'w', TRUE}, /* OP_FORMAT2 */ | |
603 | 166 {'g', '@', FALSE}, /* OP_FUNCTION */ |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
167 {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
|
168 {Ctrl_X, NUL, FALSE}, /* OP_NR_SUB */ |
7 | 169 }; |
170 | |
171 /* | |
172 * Translate a command name into an operator type. | |
173 * Must only be called with a valid operator name! | |
174 */ | |
175 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
176 get_op_type(int char1, int char2) |
7 | 177 { |
178 int i; | |
179 | |
180 if (char1 == 'r') /* ignore second character */ | |
181 return OP_REPLACE; | |
182 if (char1 == '~') /* when tilde is an operator */ | |
183 return OP_TILDE; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
184 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
|
185 return OP_NR_ADD; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
186 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
|
187 return OP_NR_SUB; |
7 | 188 for (i = 0; ; ++i) |
189 if (opchars[i][0] == char1 && opchars[i][1] == char2) | |
190 break; | |
191 return i; | |
192 } | |
193 | |
194 /* | |
195 * Return TRUE if operator "op" always works on whole lines. | |
196 */ | |
197 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
198 op_on_lines(int op) |
7 | 199 { |
200 return opchars[op][2]; | |
201 } | |
202 | |
203 /* | |
204 * Get first operator command character. | |
205 * Returns 'g' or 'z' if there is another command character. | |
206 */ | |
207 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
208 get_op_char(int optype) |
7 | 209 { |
210 return opchars[optype][0]; | |
211 } | |
212 | |
213 /* | |
214 * Get second operator command character. | |
215 */ | |
216 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
217 get_extra_op_char(int optype) |
7 | 218 { |
219 return opchars[optype][1]; | |
220 } | |
221 | |
222 /* | |
223 * op_shift - handle a shift operation | |
224 */ | |
225 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
226 op_shift(oparg_T *oap, int curs_top, int amount) |
7 | 227 { |
228 long i; | |
229 int first_char; | |
230 char_u *s; | |
231 int block_col = 0; | |
232 | |
233 if (u_save((linenr_T)(oap->start.lnum - 1), | |
234 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
235 return; | |
236 | |
237 if (oap->block_mode) | |
238 block_col = curwin->w_cursor.col; | |
239 | |
240 for (i = oap->line_count; --i >= 0; ) | |
241 { | |
242 first_char = *ml_get_curline(); | |
243 if (first_char == NUL) /* empty line */ | |
244 curwin->w_cursor.col = 0; | |
245 #ifdef FEAT_VISUALEXTRA | |
246 else if (oap->block_mode) | |
247 shift_block(oap, amount); | |
248 #endif | |
249 else | |
250 /* Move the line right if it doesn't start with '#', 'smartindent' | |
251 * isn't set or 'cindent' isn't set or '#' isn't in 'cino'. */ | |
252 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) | |
253 if (first_char != '#' || !preprocs_left()) | |
254 #endif | |
255 { | |
1516 | 256 shift_line(oap->op_type == OP_LSHIFT, p_sr, amount, FALSE); |
7 | 257 } |
258 ++curwin->w_cursor.lnum; | |
259 } | |
260 | |
261 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
|
262 #ifdef FEAT_FOLDING |
4cbff53717d4
updated for version 7.4a.017
Bram Moolenaar <bram@vim.org>
parents:
5100
diff
changeset
|
263 /* 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
|
264 foldOpenCursor(); |
4cbff53717d4
updated for version 7.4a.017
Bram Moolenaar <bram@vim.org>
parents:
5100
diff
changeset
|
265 #endif |
7 | 266 |
267 if (oap->block_mode) | |
268 { | |
269 curwin->w_cursor.lnum = oap->start.lnum; | |
270 curwin->w_cursor.col = block_col; | |
271 } | |
5735 | 272 else if (curs_top) /* put cursor on first line, for ">>" */ |
7 | 273 { |
274 curwin->w_cursor.lnum = oap->start.lnum; | |
275 beginline(BL_SOL | BL_FIX); /* shift_line() may have set cursor.col */ | |
276 } | |
277 else | |
278 --curwin->w_cursor.lnum; /* put cursor on last line, for ":>" */ | |
279 | |
280 if (oap->line_count > p_report) | |
281 { | |
282 if (oap->op_type == OP_RSHIFT) | |
283 s = (char_u *)">"; | |
284 else | |
285 s = (char_u *)"<"; | |
286 if (oap->line_count == 1) | |
287 { | |
288 if (amount == 1) | |
289 sprintf((char *)IObuff, _("1 line %sed 1 time"), s); | |
290 else | |
291 sprintf((char *)IObuff, _("1 line %sed %d times"), s, amount); | |
292 } | |
293 else | |
294 { | |
295 if (amount == 1) | |
296 sprintf((char *)IObuff, _("%ld lines %sed 1 time"), | |
297 oap->line_count, s); | |
298 else | |
299 sprintf((char *)IObuff, _("%ld lines %sed %d times"), | |
300 oap->line_count, s, amount); | |
301 } | |
302 msg(IObuff); | |
303 } | |
304 | |
305 /* | |
306 * Set "'[" and "']" marks. | |
307 */ | |
308 curbuf->b_op_start = oap->start; | |
309 curbuf->b_op_end.lnum = oap->end.lnum; | |
310 curbuf->b_op_end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
311 if (curbuf->b_op_end.col > 0) | |
312 --curbuf->b_op_end.col; | |
313 } | |
314 | |
315 /* | |
316 * shift the current line one shiftwidth left (if left != 0) or right | |
317 * leaves cursor on first blank in the line | |
318 */ | |
319 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
320 shift_line( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
321 int left, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
322 int round, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
323 int amount, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
324 int call_changed_bytes) /* call changed_bytes() */ |
7 | 325 { |
326 int count; | |
327 int i, j; | |
5438 | 328 int p_sw = (int)get_sw_value(curbuf); |
7 | 329 |
330 count = get_indent(); /* get current indent */ | |
331 | |
332 if (round) /* round off indent */ | |
333 { | |
334 i = count / p_sw; /* number of p_sw rounded down */ | |
335 j = count % p_sw; /* extra spaces */ | |
336 if (j && left) /* first remove extra spaces */ | |
337 --amount; | |
338 if (left) | |
339 { | |
340 i -= amount; | |
341 if (i < 0) | |
342 i = 0; | |
343 } | |
344 else | |
345 i += amount; | |
346 count = i * p_sw; | |
347 } | |
348 else /* original vi indent */ | |
349 { | |
350 if (left) | |
351 { | |
352 count -= p_sw * amount; | |
353 if (count < 0) | |
354 count = 0; | |
355 } | |
356 else | |
357 count += p_sw * amount; | |
358 } | |
359 | |
360 /* Set new indent */ | |
361 #ifdef FEAT_VREPLACE | |
362 if (State & VREPLACE_FLAG) | |
1516 | 363 change_indent(INDENT_SET, count, FALSE, NUL, call_changed_bytes); |
7 | 364 else |
365 #endif | |
1516 | 366 (void)set_indent(count, call_changed_bytes ? SIN_CHANGED : 0); |
7 | 367 } |
368 | |
369 #if defined(FEAT_VISUALEXTRA) || defined(PROTO) | |
370 /* | |
371 * Shift one line of the current block one shiftwidth right or left. | |
372 * Leaves cursor on first character in block. | |
373 */ | |
374 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
375 shift_block(oparg_T *oap, int amount) |
7 | 376 { |
377 int left = (oap->op_type == OP_LSHIFT); | |
378 int oldstate = State; | |
1839 | 379 int total; |
380 char_u *newp, *oldp; | |
7 | 381 int oldcol = curwin->w_cursor.col; |
5438 | 382 int p_sw = (int)get_sw_value(curbuf); |
7 | 383 int p_ts = (int)curbuf->b_p_ts; |
384 struct block_def bd; | |
385 int incr; | |
1839 | 386 colnr_T ws_vcol; |
7 | 387 int i = 0, j = 0; |
388 int len; | |
389 #ifdef FEAT_RIGHTLEFT | |
390 int old_p_ri = p_ri; | |
391 | |
4352 | 392 p_ri = 0; /* don't want revins in indent */ |
7 | 393 #endif |
394 | |
395 State = INSERT; /* don't want REPLACE for State */ | |
396 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); | |
397 if (bd.is_short) | |
398 return; | |
399 | |
400 /* total is number of screen columns to be inserted/removed */ | |
401 total = amount * p_sw; | |
402 oldp = ml_get_curline(); | |
403 | |
404 if (!left) | |
405 { | |
406 /* | |
407 * 1. Get start vcol | |
408 * 2. Total ws vcols | |
409 * 3. Divvy into TABs & spp | |
410 * 4. Construct new string | |
411 */ | |
412 total += bd.pre_whitesp; /* all virtual WS upto & incl a split TAB */ | |
413 ws_vcol = bd.start_vcol - bd.pre_whitesp; | |
414 if (bd.startspaces) | |
415 { | |
416 #ifdef FEAT_MBYTE | |
417 if (has_mbyte) | |
8399
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
418 { |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
419 if ((*mb_ptr2len)(bd.textstart) == 1) |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
420 ++bd.textstart; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
421 else |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
422 { |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
423 ws_vcol = 0; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
424 bd.startspaces = 0; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
425 } |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
426 } |
1995 | 427 else |
428 #endif | |
429 ++bd.textstart; | |
7 | 430 } |
431 for ( ; vim_iswhite(*bd.textstart); ) | |
432 { | |
5995 | 433 /* TODO: is passing bd.textstart for start of the line OK? */ |
434 incr = lbr_chartabsize_adv(bd.textstart, &bd.textstart, | |
435 (colnr_T)(bd.start_vcol)); | |
7 | 436 total += incr; |
437 bd.start_vcol += incr; | |
438 } | |
439 /* OK, now total=all the VWS reqd, and textstart points at the 1st | |
440 * non-ws char in the block. */ | |
441 if (!curbuf->b_p_et) | |
442 i = ((ws_vcol % p_ts) + total) / p_ts; /* number of tabs */ | |
443 if (i) | |
444 j = ((ws_vcol % p_ts) + total) % p_ts; /* number of spp */ | |
445 else | |
446 j = total; | |
447 /* if we're splitting a TAB, allow for it */ | |
448 bd.textcol -= bd.pre_whitesp_c - (bd.startspaces != 0); | |
449 len = (int)STRLEN(bd.textstart) + 1; | |
450 newp = alloc_check((unsigned)(bd.textcol + i + j + len)); | |
451 if (newp == NULL) | |
452 return; | |
453 vim_memset(newp, NUL, (size_t)(bd.textcol + i + j + len)); | |
454 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
6929 | 455 vim_memset(newp + bd.textcol, TAB, (size_t)i); |
456 vim_memset(newp + bd.textcol + i, ' ', (size_t)j); | |
7 | 457 /* the end */ |
458 mch_memmove(newp + bd.textcol + i + j, bd.textstart, (size_t)len); | |
459 } | |
460 else /* left */ | |
461 { | |
1839 | 462 colnr_T destination_col; /* column to which text in block will |
463 be shifted */ | |
464 char_u *verbatim_copy_end; /* end of the part of the line which is | |
465 copied verbatim */ | |
466 colnr_T verbatim_copy_width;/* the (displayed) width of this part | |
467 of line */ | |
468 unsigned fill; /* nr of spaces that replace a TAB */ | |
469 unsigned new_line_len; /* the length of the line after the | |
470 block shift */ | |
471 size_t block_space_width; | |
472 size_t shift_amount; | |
473 char_u *non_white = bd.textstart; | |
474 colnr_T non_white_col; | |
475 | |
476 /* | |
477 * Firstly, let's find the first non-whitespace character that is | |
478 * displayed after the block's start column and the character's column | |
479 * number. Also, let's calculate the width of all the whitespace | |
480 * characters that are displayed in the block and precede the searched | |
481 * non-whitespace character. | |
482 */ | |
483 | |
484 /* If "bd.startspaces" is set, "bd.textstart" points to the character, | |
485 * the part of which is displayed at the block's beginning. Let's start | |
486 * searching from the next character. */ | |
487 if (bd.startspaces) | |
488 mb_ptr_adv(non_white); | |
489 | |
490 /* The character's column is in "bd.start_vcol". */ | |
491 non_white_col = bd.start_vcol; | |
492 | |
493 while (vim_iswhite(*non_white)) | |
7 | 494 { |
5995 | 495 incr = lbr_chartabsize_adv(bd.textstart, &non_white, non_white_col); |
1839 | 496 non_white_col += incr; |
7 | 497 } |
1839 | 498 |
499 block_space_width = non_white_col - oap->start_vcol; | |
500 /* We will shift by "total" or "block_space_width", whichever is less. | |
501 */ | |
1860 | 502 shift_amount = (block_space_width < (size_t)total |
503 ? block_space_width : (size_t)total); | |
1839 | 504 |
505 /* The column to which we will shift the text. */ | |
1860 | 506 destination_col = (colnr_T)(non_white_col - shift_amount); |
1839 | 507 |
508 /* Now let's find out how much of the beginning of the line we can | |
509 * reuse without modification. */ | |
510 verbatim_copy_end = bd.textstart; | |
511 verbatim_copy_width = bd.start_vcol; | |
512 | |
513 /* If "bd.startspaces" is set, "bd.textstart" points to the character | |
514 * preceding the block. We have to subtract its width to obtain its | |
515 * column number. */ | |
516 if (bd.startspaces) | |
517 verbatim_copy_width -= bd.start_char_vcols; | |
518 while (verbatim_copy_width < destination_col) | |
7 | 519 { |
5995 | 520 char_u *line = verbatim_copy_end; |
521 | |
522 /* TODO: is passing verbatim_copy_end for start of the line OK? */ | |
523 incr = lbr_chartabsize(line, verbatim_copy_end, | |
524 verbatim_copy_width); | |
1839 | 525 if (verbatim_copy_width + incr > destination_col) |
526 break; | |
527 verbatim_copy_width += incr; | |
528 mb_ptr_adv(verbatim_copy_end); | |
7 | 529 } |
530 | |
1839 | 531 /* If "destination_col" is different from the width of the initial |
532 * part of the line that will be copied, it means we encountered a tab | |
533 * character, which we will have to partly replace with spaces. */ | |
534 fill = destination_col - verbatim_copy_width; | |
535 | |
536 /* The replacement line will consist of: | |
537 * - the beginning of the original line up to "verbatim_copy_end", | |
538 * - "fill" number of spaces, | |
539 * - the rest of the line, pointed to by non_white. */ | |
540 new_line_len = (unsigned)(verbatim_copy_end - oldp) | |
541 + fill | |
542 + (unsigned)STRLEN(non_white) + 1; | |
543 | |
544 newp = alloc_check(new_line_len); | |
7 | 545 if (newp == NULL) |
546 return; | |
1839 | 547 mch_memmove(newp, oldp, (size_t)(verbatim_copy_end - oldp)); |
6929 | 548 vim_memset(newp + (verbatim_copy_end - oldp), ' ', (size_t)fill); |
1839 | 549 STRMOVE(newp + (verbatim_copy_end - oldp) + fill, non_white); |
7 | 550 } |
551 /* replace the line */ | |
552 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
553 changed_bytes(curwin->w_cursor.lnum, (colnr_T)bd.textcol); | |
554 State = oldstate; | |
555 curwin->w_cursor.col = oldcol; | |
556 #ifdef FEAT_RIGHTLEFT | |
557 p_ri = old_p_ri; | |
558 #endif | |
559 } | |
560 #endif | |
561 | |
562 #ifdef FEAT_VISUALEXTRA | |
563 /* | |
564 * Insert string "s" (b_insert ? before : after) block :AKelly | |
565 * Caller must prepare for undo. | |
566 */ | |
567 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
568 block_insert( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
569 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
570 char_u *s, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
571 int b_insert, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
572 struct block_def *bdp) |
7 | 573 { |
574 int p_ts; | |
575 int count = 0; /* extra spaces to replace a cut TAB */ | |
576 int spaces = 0; /* non-zero if cutting a TAB */ | |
577 colnr_T offset; /* pointer along new line */ | |
578 unsigned s_len; /* STRLEN(s) */ | |
579 char_u *newp, *oldp; /* new, old lines */ | |
580 linenr_T lnum; /* loop var */ | |
581 int oldstate = State; | |
582 | |
583 State = INSERT; /* don't want REPLACE for State */ | |
584 s_len = (unsigned)STRLEN(s); | |
585 | |
586 for (lnum = oap->start.lnum + 1; lnum <= oap->end.lnum; lnum++) | |
587 { | |
588 block_prep(oap, bdp, lnum, TRUE); | |
589 if (bdp->is_short && b_insert) | |
590 continue; /* OP_INSERT, line ends before block start */ | |
591 | |
592 oldp = ml_get(lnum); | |
593 | |
594 if (b_insert) | |
595 { | |
596 p_ts = bdp->start_char_vcols; | |
597 spaces = bdp->startspaces; | |
598 if (spaces != 0) | |
599 count = p_ts - 1; /* we're cutting a TAB */ | |
600 offset = bdp->textcol; | |
601 } | |
602 else /* append */ | |
603 { | |
604 p_ts = bdp->end_char_vcols; | |
605 if (!bdp->is_short) /* spaces = padding after block */ | |
606 { | |
607 spaces = (bdp->endspaces ? p_ts - bdp->endspaces : 0); | |
608 if (spaces != 0) | |
609 count = p_ts - 1; /* we're cutting a TAB */ | |
610 offset = bdp->textcol + bdp->textlen - (spaces != 0); | |
611 } | |
612 else /* spaces = padding to block edge */ | |
613 { | |
614 /* if $ used, just append to EOL (ie spaces==0) */ | |
615 if (!bdp->is_MAX) | |
616 spaces = (oap->end_vcol - bdp->end_vcol) + 1; | |
617 count = spaces; | |
618 offset = bdp->textcol + bdp->textlen; | |
619 } | |
620 } | |
621 | |
6140 | 622 #ifdef FEAT_MBYTE |
623 if (has_mbyte && spaces > 0) | |
624 { | |
6460 | 625 int off; |
626 | |
6140 | 627 /* Avoid starting halfway a multi-byte character. */ |
628 if (b_insert) | |
629 { | |
6460 | 630 off = (*mb_head_off)(oldp, oldp + offset + spaces); |
6140 | 631 } |
632 else | |
633 { | |
6460 | 634 off = (*mb_off_next)(oldp, oldp + offset); |
6140 | 635 offset += off; |
636 } | |
6460 | 637 spaces -= off; |
638 count -= off; | |
6140 | 639 } |
640 #endif | |
641 | |
7 | 642 newp = alloc_check((unsigned)(STRLEN(oldp)) + s_len + count + 1); |
643 if (newp == NULL) | |
644 continue; | |
645 | |
646 /* copy up to shifted part */ | |
647 mch_memmove(newp, oldp, (size_t)(offset)); | |
648 oldp += offset; | |
649 | |
650 /* insert pre-padding */ | |
6929 | 651 vim_memset(newp + offset, ' ', (size_t)spaces); |
7 | 652 |
653 /* copy the new text */ | |
654 mch_memmove(newp + offset + spaces, s, (size_t)s_len); | |
655 offset += s_len; | |
656 | |
657 if (spaces && !bdp->is_short) | |
658 { | |
659 /* insert post-padding */ | |
6929 | 660 vim_memset(newp + offset + spaces, ' ', (size_t)(p_ts - spaces)); |
7 | 661 /* We're splitting a TAB, don't copy it. */ |
662 oldp++; | |
663 /* We allowed for that TAB, remember this now */ | |
664 count++; | |
665 } | |
666 | |
667 if (spaces > 0) | |
668 offset += count; | |
1622 | 669 STRMOVE(newp + offset, oldp); |
7 | 670 |
671 ml_replace(lnum, newp, FALSE); | |
672 | |
673 if (lnum == oap->end.lnum) | |
674 { | |
675 /* Set "']" mark to the end of the block instead of the end of | |
676 * the insert in the first line. */ | |
677 curbuf->b_op_end.lnum = oap->end.lnum; | |
678 curbuf->b_op_end.col = offset; | |
679 } | |
680 } /* for all lnum */ | |
681 | |
682 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); | |
683 | |
684 State = oldstate; | |
685 } | |
686 #endif | |
687 | |
688 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) || defined(PROTO) | |
689 /* | |
690 * op_reindent - handle reindenting a block of lines. | |
691 */ | |
692 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
693 op_reindent(oparg_T *oap, int (*how)(void)) |
7 | 694 { |
695 long i; | |
696 char_u *l; | |
6971 | 697 int amount; |
7 | 698 linenr_T first_changed = 0; |
699 linenr_T last_changed = 0; | |
700 linenr_T start_lnum = curwin->w_cursor.lnum; | |
701 | |
216 | 702 /* Don't even try when 'modifiable' is off. */ |
703 if (!curbuf->b_p_ma) | |
704 { | |
705 EMSG(_(e_modifiable)); | |
706 return; | |
707 } | |
708 | |
7 | 709 for (i = oap->line_count; --i >= 0 && !got_int; ) |
710 { | |
711 /* it's a slow thing to do, so give feedback so there's no worry that | |
712 * the computer's just hung. */ | |
713 | |
714 if (i > 1 | |
715 && (i % 50 == 0 || i == oap->line_count - 1) | |
716 && oap->line_count > p_report) | |
717 smsg((char_u *)_("%ld lines to indent... "), i); | |
718 | |
719 /* | |
720 * Be vi-compatible: For lisp indenting the first line is not | |
721 * indented, unless there is only one line. | |
722 */ | |
723 #ifdef FEAT_LISP | |
724 if (i != oap->line_count - 1 || oap->line_count == 1 | |
725 || how != get_lisp_indent) | |
726 #endif | |
727 { | |
728 l = skipwhite(ml_get_curline()); | |
729 if (*l == NUL) /* empty or blank line */ | |
6971 | 730 amount = 0; |
7 | 731 else |
6971 | 732 amount = how(); /* get the indent for this line */ |
733 | |
734 if (amount >= 0 && set_indent(amount, SIN_UNDO)) | |
7 | 735 { |
736 /* did change the indent, call changed_lines() later */ | |
737 if (first_changed == 0) | |
738 first_changed = curwin->w_cursor.lnum; | |
739 last_changed = curwin->w_cursor.lnum; | |
740 } | |
741 } | |
742 ++curwin->w_cursor.lnum; | |
1550 | 743 curwin->w_cursor.col = 0; /* make sure it's valid */ |
7 | 744 } |
745 | |
746 /* put cursor on first non-blank of indented line */ | |
747 curwin->w_cursor.lnum = start_lnum; | |
748 beginline(BL_SOL | BL_FIX); | |
749 | |
750 /* Mark changed lines so that they will be redrawn. When Visual | |
751 * highlighting was present, need to continue until the last line. When | |
752 * there is no change still need to remove the Visual highlighting. */ | |
753 if (last_changed != 0) | |
754 changed_lines(first_changed, 0, | |
755 oap->is_VIsual ? start_lnum + oap->line_count : | |
756 last_changed + 1, 0L); | |
757 else if (oap->is_VIsual) | |
758 redraw_curbuf_later(INVERTED); | |
759 | |
760 if (oap->line_count > p_report) | |
761 { | |
762 i = oap->line_count - (i + 1); | |
763 if (i == 1) | |
764 MSG(_("1 line indented ")); | |
765 else | |
766 smsg((char_u *)_("%ld lines indented "), i); | |
767 } | |
768 /* set '[ and '] marks */ | |
769 curbuf->b_op_start = oap->start; | |
770 curbuf->b_op_end = oap->end; | |
771 } | |
772 #endif /* defined(FEAT_LISP) || defined(FEAT_CINDENT) */ | |
773 | |
774 #if defined(FEAT_EVAL) || defined(PROTO) | |
775 /* | |
776 * Keep the last expression line here, for repeating. | |
777 */ | |
778 static char_u *expr_line = NULL; | |
779 | |
780 /* | |
781 * Get an expression for the "\"=expr1" or "CTRL-R =expr1" | |
782 * Returns '=' when OK, NUL otherwise. | |
783 */ | |
784 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
785 get_expr_register(void) |
7 | 786 { |
787 char_u *new_line; | |
788 | |
789 new_line = getcmdline('=', 0L, 0); | |
790 if (new_line == NULL) | |
791 return NUL; | |
792 if (*new_line == NUL) /* use previous line */ | |
793 vim_free(new_line); | |
794 else | |
795 set_expr_line(new_line); | |
796 return '='; | |
797 } | |
798 | |
799 /* | |
800 * Set the expression for the '=' register. | |
801 * Argument must be an allocated string. | |
802 */ | |
803 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
804 set_expr_line(char_u *new_line) |
7 | 805 { |
806 vim_free(expr_line); | |
807 expr_line = new_line; | |
808 } | |
809 | |
810 /* | |
811 * Get the result of the '=' register expression. | |
812 * Returns a pointer to allocated memory, or NULL for failure. | |
813 */ | |
814 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
815 get_expr_line(void) |
7 | 816 { |
817 char_u *expr_copy; | |
818 char_u *rv; | |
994 | 819 static int nested = 0; |
7 | 820 |
821 if (expr_line == NULL) | |
822 return NULL; | |
823 | |
824 /* Make a copy of the expression, because evaluating it may cause it to be | |
825 * changed. */ | |
826 expr_copy = vim_strsave(expr_line); | |
827 if (expr_copy == NULL) | |
828 return NULL; | |
829 | |
994 | 830 /* When we are invoked recursively limit the evaluation to 10 levels. |
831 * Then return the string as-is. */ | |
832 if (nested >= 10) | |
833 return expr_copy; | |
834 | |
835 ++nested; | |
714 | 836 rv = eval_to_string(expr_copy, NULL, TRUE); |
994 | 837 --nested; |
7 | 838 vim_free(expr_copy); |
839 return rv; | |
840 } | |
283 | 841 |
842 /* | |
843 * Get the '=' register expression itself, without evaluating it. | |
844 */ | |
845 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
846 get_expr_line_src(void) |
283 | 847 { |
848 if (expr_line == NULL) | |
849 return NULL; | |
850 return vim_strsave(expr_line); | |
851 } | |
7 | 852 #endif /* FEAT_EVAL */ |
853 | |
854 /* | |
855 * Check if 'regname' is a valid name of a yank register. | |
856 * Note: There is no check for 0 (default register), caller should do this | |
857 */ | |
858 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
859 valid_yank_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
860 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
861 int writing) /* if TRUE check for writable registers */ |
7 | 862 { |
863 if ( (regname > 0 && ASCII_ISALNUM(regname)) | |
864 || (!writing && vim_strchr((char_u *) | |
865 #ifdef FEAT_EVAL | |
6557 | 866 "/.%:=" |
7 | 867 #else |
6557 | 868 "/.%:" |
7 | 869 #endif |
870 , regname) != NULL) | |
6557 | 871 || regname == '#' |
7 | 872 || regname == '"' |
873 || regname == '-' | |
874 || regname == '_' | |
875 #ifdef FEAT_CLIPBOARD | |
876 || regname == '*' | |
877 || regname == '+' | |
878 #endif | |
879 #ifdef FEAT_DND | |
880 || (!writing && regname == '~') | |
881 #endif | |
882 ) | |
883 return TRUE; | |
884 return FALSE; | |
885 } | |
886 | |
887 /* | |
888 * Set y_current and y_append, according to the value of "regname". | |
889 * Cannot handle the '_' register. | |
140 | 890 * Must only be called with a valid register name! |
7 | 891 * |
892 * If regname is 0 and writing, use register 0 | |
893 * If regname is 0 and reading, use previous register | |
894 */ | |
15 | 895 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
896 get_yank_register(int regname, int writing) |
7 | 897 { |
898 int i; | |
899 | |
900 y_append = FALSE; | |
901 if ((regname == 0 || regname == '"') && !writing && y_previous != NULL) | |
902 { | |
903 y_current = y_previous; | |
904 return; | |
905 } | |
906 i = regname; | |
907 if (VIM_ISDIGIT(i)) | |
908 i -= '0'; | |
909 else if (ASCII_ISLOWER(i)) | |
910 i = CharOrdLow(i) + 10; | |
911 else if (ASCII_ISUPPER(i)) | |
912 { | |
913 i = CharOrdUp(i) + 10; | |
914 y_append = TRUE; | |
915 } | |
916 else if (regname == '-') | |
917 i = DELETION_REGISTER; | |
918 #ifdef FEAT_CLIPBOARD | |
919 /* When selection is not available, use register 0 instead of '*' */ | |
920 else if (clip_star.available && regname == '*') | |
921 i = STAR_REGISTER; | |
922 /* When clipboard is not available, use register 0 instead of '+' */ | |
923 else if (clip_plus.available && regname == '+') | |
924 i = PLUS_REGISTER; | |
925 #endif | |
926 #ifdef FEAT_DND | |
927 else if (!writing && regname == '~') | |
928 i = TILDE_REGISTER; | |
929 #endif | |
930 else /* not 0-9, a-z, A-Z or '-': use register 0 */ | |
931 i = 0; | |
932 y_current = &(y_regs[i]); | |
933 if (writing) /* remember the register we write into for do_put() */ | |
934 y_previous = y_current; | |
935 } | |
936 | |
15 | 937 #if defined(FEAT_CLIPBOARD) || defined(PROTO) |
7 | 938 /* |
939 * When "regname" is a clipboard register, obtain the selection. If it's not | |
940 * available return zero, otherwise return "regname". | |
941 */ | |
15 | 942 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
943 may_get_selection(int regname) |
7 | 944 { |
945 if (regname == '*') | |
946 { | |
947 if (!clip_star.available) | |
948 regname = 0; | |
949 else | |
950 clip_get_selection(&clip_star); | |
951 } | |
952 else if (regname == '+') | |
953 { | |
954 if (!clip_plus.available) | |
955 regname = 0; | |
956 else | |
957 clip_get_selection(&clip_plus); | |
958 } | |
959 return regname; | |
960 } | |
961 #endif | |
962 | |
963 /* | |
964 * Obtain the contents of a "normal" register. The register is made empty. | |
965 * The returned pointer has allocated memory, use put_register() later. | |
966 */ | |
967 void * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
968 get_register( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
969 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
970 int copy) /* make a copy, if FALSE make register empty. */ |
7 | 971 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
972 yankreg_T *reg; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
973 int i; |
7 | 974 |
975 #ifdef FEAT_CLIPBOARD | |
976 /* When Visual area changed, may have to update selection. Obtain the | |
977 * selection too. */ | |
1435 | 978 if (name == '*' && clip_star.available) |
7 | 979 { |
3674 | 980 if (clip_isautosel_star()) |
981 clip_update_selection(&clip_star); | |
982 may_get_selection(name); | |
983 } | |
984 if (name == '+' && clip_plus.available) | |
985 { | |
986 if (clip_isautosel_plus()) | |
987 clip_update_selection(&clip_plus); | |
7 | 988 may_get_selection(name); |
989 } | |
990 #endif | |
991 | |
992 get_yank_register(name, 0); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
993 reg = (yankreg_T *)alloc((unsigned)sizeof(yankreg_T)); |
7 | 994 if (reg != NULL) |
995 { | |
996 *reg = *y_current; | |
997 if (copy) | |
998 { | |
999 /* If we run out of memory some or all of the lines are empty. */ | |
1000 if (reg->y_size == 0) | |
1001 reg->y_array = NULL; | |
1002 else | |
1003 reg->y_array = (char_u **)alloc((unsigned)(sizeof(char_u *) | |
1004 * reg->y_size)); | |
1005 if (reg->y_array != NULL) | |
1006 { | |
1007 for (i = 0; i < reg->y_size; ++i) | |
1008 reg->y_array[i] = vim_strsave(y_current->y_array[i]); | |
1009 } | |
1010 } | |
1011 else | |
1012 y_current->y_array = NULL; | |
1013 } | |
1014 return (void *)reg; | |
1015 } | |
1016 | |
1017 /* | |
1451 | 1018 * Put "reg" into register "name". Free any previous contents and "reg". |
7 | 1019 */ |
1020 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1021 put_register(int name, void *reg) |
7 | 1022 { |
1023 get_yank_register(name, 0); | |
1024 free_yank_all(); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1025 *y_current = *(yankreg_T *)reg; |
1451 | 1026 vim_free(reg); |
7 | 1027 |
5735 | 1028 #ifdef FEAT_CLIPBOARD |
7 | 1029 /* Send text written to clipboard register to the clipboard. */ |
1030 may_set_selection(); | |
5735 | 1031 #endif |
7 | 1032 } |
4209 | 1033 |
1034 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1035 free_register(void *reg) |
4209 | 1036 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1037 yankreg_T tmp; |
4209 | 1038 |
1039 tmp = *y_current; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1040 *y_current = *(yankreg_T *)reg; |
4209 | 1041 free_yank_all(); |
1042 vim_free(reg); | |
1043 *y_current = tmp; | |
1044 } | |
7 | 1045 |
1046 #if defined(FEAT_MOUSE) || defined(PROTO) | |
1047 /* | |
1048 * return TRUE if the current yank register has type MLINE | |
1049 */ | |
1050 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1051 yank_register_mline(int regname) |
7 | 1052 { |
1053 if (regname != 0 && !valid_yank_reg(regname, FALSE)) | |
1054 return FALSE; | |
1055 if (regname == '_') /* black hole is always empty */ | |
1056 return FALSE; | |
1057 get_yank_register(regname, FALSE); | |
1058 return (y_current->y_type == MLINE); | |
1059 } | |
1060 #endif | |
1061 | |
1062 /* | |
1157 | 1063 * Start or stop recording into a yank register. |
7 | 1064 * |
1157 | 1065 * Return FAIL for failure, OK otherwise. |
7 | 1066 */ |
1067 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1068 do_record(int c) |
7 | 1069 { |
1157 | 1070 char_u *p; |
1071 static int regname; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1072 yankreg_T *old_y_previous, *old_y_current; |
1157 | 1073 int retval; |
7 | 1074 |
1075 if (Recording == FALSE) /* start recording */ | |
1076 { | |
1077 /* registers 0-9, a-z and " are allowed */ | |
1078 if (c < 0 || (!ASCII_ISALNUM(c) && c != '"')) | |
1079 retval = FAIL; | |
1080 else | |
1081 { | |
7233
9487ea110214
commit https://github.com/vim/vim/commit/a0ed84a26897c994512873a895b9fc54e90c6845
Christian Brabandt <cb@256bit.org>
parents:
7011
diff
changeset
|
1082 Recording = c; |
7 | 1083 showmode(); |
1084 regname = c; | |
1085 retval = OK; | |
1086 } | |
1087 } | |
1088 else /* stop recording */ | |
1089 { | |
1090 /* | |
1157 | 1091 * Get the recorded key hits. K_SPECIAL and CSI will be escaped, this |
1092 * needs to be removed again to put it in a register. exec_reg then | |
1093 * adds the escaping back later. | |
7 | 1094 */ |
1095 Recording = FALSE; | |
1096 MSG(""); | |
1097 p = get_recorded(); | |
1098 if (p == NULL) | |
1099 retval = FAIL; | |
1100 else | |
1101 { | |
1081 | 1102 /* Remove escaping for CSI and K_SPECIAL in multi-byte chars. */ |
1103 vim_unescape_csi(p); | |
1104 | |
7 | 1105 /* |
1106 * We don't want to change the default register here, so save and | |
1107 * restore the current register name. | |
1108 */ | |
1109 old_y_previous = y_previous; | |
1110 old_y_current = y_current; | |
1111 | |
1112 retval = stuff_yank(regname, p); | |
1113 | |
1114 y_previous = old_y_previous; | |
1115 y_current = old_y_current; | |
1116 } | |
1117 } | |
1118 return retval; | |
1119 } | |
1120 | |
1121 /* | |
1122 * Stuff string "p" into yank register "regname" as a single line (append if | |
1123 * uppercase). "p" must have been alloced. | |
1124 * | |
1125 * return FAIL for failure, OK otherwise | |
1126 */ | |
1127 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1128 stuff_yank(int regname, char_u *p) |
7 | 1129 { |
1130 char_u *lp; | |
1131 char_u **pp; | |
1132 | |
1133 /* check for read-only register */ | |
1134 if (regname != 0 && !valid_yank_reg(regname, TRUE)) | |
1135 { | |
1136 vim_free(p); | |
1137 return FAIL; | |
1138 } | |
1139 if (regname == '_') /* black hole: don't do anything */ | |
1140 { | |
1141 vim_free(p); | |
1142 return OK; | |
1143 } | |
1144 get_yank_register(regname, TRUE); | |
1145 if (y_append && y_current->y_array != NULL) | |
1146 { | |
1147 pp = &(y_current->y_array[y_current->y_size - 1]); | |
1148 lp = lalloc((long_u)(STRLEN(*pp) + STRLEN(p) + 1), TRUE); | |
1149 if (lp == NULL) | |
1150 { | |
1151 vim_free(p); | |
1152 return FAIL; | |
1153 } | |
1154 STRCPY(lp, *pp); | |
1155 STRCAT(lp, p); | |
1156 vim_free(p); | |
1157 vim_free(*pp); | |
1158 *pp = lp; | |
1159 } | |
1160 else | |
1161 { | |
1162 free_yank_all(); | |
1163 if ((y_current->y_array = | |
1164 (char_u **)alloc((unsigned)sizeof(char_u *))) == NULL) | |
1165 { | |
1166 vim_free(p); | |
1167 return FAIL; | |
1168 } | |
1169 y_current->y_array[0] = p; | |
1170 y_current->y_size = 1; | |
1171 y_current->y_type = MCHAR; /* used to be MLINE, why? */ | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1172 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1173 y_current->y_time_set = vim_time(); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1174 #endif |
7 | 1175 } |
1176 return OK; | |
1177 } | |
1178 | |
1893 | 1179 static int execreg_lastc = NUL; |
1180 | |
7 | 1181 /* |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
1182 * Execute a yank register: copy it into the stuff buffer. |
7 | 1183 * |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
1184 * Return FAIL for failure, OK otherwise. |
7 | 1185 */ |
1186 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1187 do_execreg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1188 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1189 int colon, /* insert ':' before each line */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1190 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
|
1191 int silent) /* set "silent" flag in typeahead buffer */ |
7 | 1192 { |
1193 long i; | |
1194 char_u *p; | |
1195 int retval = OK; | |
1196 int remap; | |
1197 | |
1198 if (regname == '@') /* repeat previous one */ | |
168 | 1199 { |
1893 | 1200 if (execreg_lastc == NUL) |
168 | 1201 { |
1202 EMSG(_("E748: No previously used register")); | |
1203 return FAIL; | |
1204 } | |
1893 | 1205 regname = execreg_lastc; |
168 | 1206 } |
7 | 1207 /* check for valid regname */ |
1208 if (regname == '%' || regname == '#' || !valid_yank_reg(regname, FALSE)) | |
168 | 1209 { |
1210 emsg_invreg(regname); | |
7 | 1211 return FAIL; |
168 | 1212 } |
1893 | 1213 execreg_lastc = regname; |
7 | 1214 |
1215 #ifdef FEAT_CLIPBOARD | |
1216 regname = may_get_selection(regname); | |
1217 #endif | |
1218 | |
1219 if (regname == '_') /* black hole: don't stuff anything */ | |
1220 return OK; | |
1221 | |
1222 #ifdef FEAT_CMDHIST | |
1223 if (regname == ':') /* use last command line */ | |
1224 { | |
1225 if (last_cmdline == NULL) | |
1226 { | |
1227 EMSG(_(e_nolastcmd)); | |
1228 return FAIL; | |
1229 } | |
1230 vim_free(new_last_cmdline); /* don't keep the cmdline containing @: */ | |
1231 new_last_cmdline = NULL; | |
16 | 1232 /* Escape all control characters with a CTRL-V */ |
1233 p = vim_strsave_escaped_ext(last_cmdline, | |
20 | 1234 (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 | 1235 if (p != NULL) |
480 | 1236 { |
1237 /* When in Visual mode "'<,'>" will be prepended to the command. | |
1238 * Remove it when it's already there. */ | |
1239 if (VIsual_active && STRNCMP(p, "'<,'>", 5) == 0) | |
1077 | 1240 retval = put_in_typebuf(p + 5, TRUE, TRUE, silent); |
480 | 1241 else |
1077 | 1242 retval = put_in_typebuf(p, TRUE, TRUE, silent); |
480 | 1243 } |
16 | 1244 vim_free(p); |
7 | 1245 } |
1246 #endif | |
1247 #ifdef FEAT_EVAL | |
1248 else if (regname == '=') | |
1249 { | |
1250 p = get_expr_line(); | |
1251 if (p == NULL) | |
1252 return FAIL; | |
1077 | 1253 retval = put_in_typebuf(p, TRUE, colon, silent); |
7 | 1254 vim_free(p); |
1255 } | |
1256 #endif | |
1257 else if (regname == '.') /* use last inserted text */ | |
1258 { | |
1259 p = get_last_insert_save(); | |
1260 if (p == NULL) | |
1261 { | |
1262 EMSG(_(e_noinstext)); | |
1263 return FAIL; | |
1264 } | |
1077 | 1265 retval = put_in_typebuf(p, FALSE, colon, silent); |
7 | 1266 vim_free(p); |
1267 } | |
1268 else | |
1269 { | |
1270 get_yank_register(regname, FALSE); | |
1271 if (y_current->y_array == NULL) | |
1272 return FAIL; | |
1273 | |
1274 /* Disallow remaping for ":@r". */ | |
1275 remap = colon ? REMAP_NONE : REMAP_YES; | |
1276 | |
1277 /* | |
1278 * Insert lines into typeahead buffer, from last one to first one. | |
1279 */ | |
1034 | 1280 put_reedit_in_typebuf(silent); |
7 | 1281 for (i = y_current->y_size; --i >= 0; ) |
1282 { | |
1077 | 1283 char_u *escaped; |
1284 | |
7 | 1285 /* insert NL between lines and after last line if type is MLINE */ |
1286 if (y_current->y_type == MLINE || i < y_current->y_size - 1 | |
1287 || addcr) | |
1288 { | |
1034 | 1289 if (ins_typebuf((char_u *)"\n", remap, 0, TRUE, silent) == FAIL) |
7 | 1290 return FAIL; |
1291 } | |
1077 | 1292 escaped = vim_strsave_escape_csi(y_current->y_array[i]); |
1293 if (escaped == NULL) | |
1294 return FAIL; | |
1295 retval = ins_typebuf(escaped, remap, 0, TRUE, silent); | |
1296 vim_free(escaped); | |
1297 if (retval == FAIL) | |
7 | 1298 return FAIL; |
1034 | 1299 if (colon && ins_typebuf((char_u *)":", remap, 0, TRUE, silent) |
7 | 1300 == FAIL) |
1301 return FAIL; | |
1302 } | |
1303 Exec_reg = TRUE; /* disable the 'q' command */ | |
1304 } | |
1305 return retval; | |
1306 } | |
1307 | |
1308 /* | |
1309 * If "restart_edit" is not zero, put it in the typeahead buffer, so that it's | |
1310 * used only after other typeahead has been processed. | |
1311 */ | |
1312 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1313 put_reedit_in_typebuf(int silent) |
7 | 1314 { |
1315 char_u buf[3]; | |
1316 | |
1317 if (restart_edit != NUL) | |
1318 { | |
1319 if (restart_edit == 'V') | |
1320 { | |
1321 buf[0] = 'g'; | |
1322 buf[1] = 'R'; | |
1323 buf[2] = NUL; | |
1324 } | |
1325 else | |
1326 { | |
1327 buf[0] = restart_edit == 'I' ? 'i' : restart_edit; | |
1328 buf[1] = NUL; | |
1329 } | |
1034 | 1330 if (ins_typebuf(buf, REMAP_NONE, 0, TRUE, silent) == OK) |
7 | 1331 restart_edit = NUL; |
1332 } | |
1333 } | |
1334 | |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1335 /* |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1336 * 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
|
1337 * executed again. |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1338 * 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
|
1339 * no remapping. |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1340 */ |
7 | 1341 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1342 put_in_typebuf( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1343 char_u *s, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1344 int esc, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1345 int colon, /* add ':' before the line */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1346 int silent) |
7 | 1347 { |
1348 int retval = OK; | |
1349 | |
1034 | 1350 put_reedit_in_typebuf(silent); |
7 | 1351 if (colon) |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1352 retval = ins_typebuf((char_u *)"\n", REMAP_NONE, 0, TRUE, silent); |
7 | 1353 if (retval == OK) |
1077 | 1354 { |
1355 char_u *p; | |
1356 | |
1357 if (esc) | |
1358 p = vim_strsave_escape_csi(s); | |
1359 else | |
1360 p = s; | |
1361 if (p == NULL) | |
1362 retval = FAIL; | |
1363 else | |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1364 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
|
1365 0, TRUE, silent); |
1077 | 1366 if (esc) |
1367 vim_free(p); | |
1368 } | |
7 | 1369 if (colon && retval == OK) |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1370 retval = ins_typebuf((char_u *)":", REMAP_NONE, 0, TRUE, silent); |
7 | 1371 return retval; |
1372 } | |
1373 | |
1374 /* | |
1375 * Insert a yank register: copy it into the Read buffer. | |
1376 * Used by CTRL-R command and middle mouse button in insert mode. | |
1377 * | |
1378 * return FAIL for failure, OK otherwise | |
1379 */ | |
1380 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1381 insert_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1382 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1383 int literally) /* insert literally, not as if typed */ |
7 | 1384 { |
1385 long i; | |
1386 int retval = OK; | |
1387 char_u *arg; | |
1388 int allocated; | |
1389 | |
1390 /* | |
1391 * It is possible to get into an endless loop by having CTRL-R a in | |
1392 * register a and then, in insert mode, doing CTRL-R a. | |
1393 * If you hit CTRL-C, the loop will be broken here. | |
1394 */ | |
1395 ui_breakcheck(); | |
1396 if (got_int) | |
1397 return FAIL; | |
1398 | |
1399 /* check for valid regname */ | |
1400 if (regname != NUL && !valid_yank_reg(regname, FALSE)) | |
1401 return FAIL; | |
1402 | |
1403 #ifdef FEAT_CLIPBOARD | |
1404 regname = may_get_selection(regname); | |
1405 #endif | |
1406 | |
1407 if (regname == '.') /* insert last inserted text */ | |
1408 retval = stuff_inserted(NUL, 1L, TRUE); | |
1409 else if (get_spec_reg(regname, &arg, &allocated, TRUE)) | |
1410 { | |
1411 if (arg == NULL) | |
1412 return FAIL; | |
1413 stuffescaped(arg, literally); | |
1414 if (allocated) | |
1415 vim_free(arg); | |
1416 } | |
1417 else /* name or number register */ | |
1418 { | |
1419 get_yank_register(regname, FALSE); | |
1420 if (y_current->y_array == NULL) | |
1421 retval = FAIL; | |
1422 else | |
1423 { | |
1424 for (i = 0; i < y_current->y_size; ++i) | |
1425 { | |
1426 stuffescaped(y_current->y_array[i], literally); | |
1427 /* | |
1428 * Insert a newline between lines and after last line if | |
1429 * y_type is MLINE. | |
1430 */ | |
1431 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | |
1432 stuffcharReadbuff('\n'); | |
1433 } | |
1434 } | |
1435 } | |
1436 | |
1437 return retval; | |
1438 } | |
1439 | |
1440 /* | |
1441 * Stuff a string into the typeahead buffer, such that edit() will insert it | |
1442 * literally ("literally" TRUE) or interpret is as typed characters. | |
1443 */ | |
1444 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1445 stuffescaped(char_u *arg, int literally) |
7 | 1446 { |
1447 int c; | |
1448 char_u *start; | |
1449 | |
1450 while (*arg != NUL) | |
1451 { | |
1452 /* Stuff a sequence of normal ASCII characters, that's fast. Also | |
1453 * stuff K_SPECIAL to get the effect of a special key when "literally" | |
1454 * is TRUE. */ | |
1455 start = arg; | |
1456 while ((*arg >= ' ' | |
1457 #ifndef EBCDIC | |
1458 && *arg < DEL /* EBCDIC: chars above space are normal */ | |
1459 #endif | |
1460 ) | |
1461 || (*arg == K_SPECIAL && !literally)) | |
1462 ++arg; | |
1463 if (arg > start) | |
1464 stuffReadbuffLen(start, (long)(arg - start)); | |
1465 | |
1466 /* stuff a single special character */ | |
1467 if (*arg != NUL) | |
1468 { | |
1469 #ifdef FEAT_MBYTE | |
1470 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
|
1471 c = mb_cptr2char_adv(&arg); |
7 | 1472 else |
1473 #endif | |
1474 c = *arg++; | |
1475 if (literally && ((c < ' ' && c != TAB) || c == DEL)) | |
1476 stuffcharReadbuff(Ctrl_V); | |
1477 stuffcharReadbuff(c); | |
1478 } | |
1479 } | |
1480 } | |
1481 | |
1482 /* | |
1157 | 1483 * If "regname" is a special register, return TRUE and store a pointer to its |
1484 * value in "argp". | |
7 | 1485 */ |
15 | 1486 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1487 get_spec_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1488 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1489 char_u **argp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1490 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
|
1491 int errmsg) /* give error message when failing */ |
7 | 1492 { |
1493 int cnt; | |
1494 | |
1495 *argp = NULL; | |
1496 *allocated = FALSE; | |
1497 switch (regname) | |
1498 { | |
1499 case '%': /* file name */ | |
1500 if (errmsg) | |
1501 check_fname(); /* will give emsg if not set */ | |
1502 *argp = curbuf->b_fname; | |
1503 return TRUE; | |
1504 | |
1505 case '#': /* alternate file name */ | |
1506 *argp = getaltfname(errmsg); /* may give emsg if not set */ | |
1507 return TRUE; | |
1508 | |
1509 #ifdef FEAT_EVAL | |
1510 case '=': /* result of expression */ | |
1511 *argp = get_expr_line(); | |
1512 *allocated = TRUE; | |
1513 return TRUE; | |
1514 #endif | |
1515 | |
1516 case ':': /* last command line */ | |
1517 if (last_cmdline == NULL && errmsg) | |
1518 EMSG(_(e_nolastcmd)); | |
1519 *argp = last_cmdline; | |
1520 return TRUE; | |
1521 | |
1522 case '/': /* last search-pattern */ | |
1523 if (last_search_pat() == NULL && errmsg) | |
1524 EMSG(_(e_noprevre)); | |
1525 *argp = last_search_pat(); | |
1526 return TRUE; | |
1527 | |
1528 case '.': /* last inserted text */ | |
1529 *argp = get_last_insert_save(); | |
1530 *allocated = TRUE; | |
1531 if (*argp == NULL && errmsg) | |
1532 EMSG(_(e_noinstext)); | |
1533 return TRUE; | |
1534 | |
1535 #ifdef FEAT_SEARCHPATH | |
1536 case Ctrl_F: /* Filename under cursor */ | |
1537 case Ctrl_P: /* Path under cursor, expand via "path" */ | |
1538 if (!errmsg) | |
1539 return FALSE; | |
1540 *argp = file_name_at_cursor(FNAME_MESS | FNAME_HYP | |
681 | 1541 | (regname == Ctrl_P ? FNAME_EXP : 0), 1L, NULL); |
7 | 1542 *allocated = TRUE; |
1543 return TRUE; | |
1544 #endif | |
1545 | |
1546 case Ctrl_W: /* word under cursor */ | |
1547 case Ctrl_A: /* WORD (mnemonic All) under cursor */ | |
1548 if (!errmsg) | |
1549 return FALSE; | |
1550 cnt = find_ident_under_cursor(argp, regname == Ctrl_W | |
1551 ? (FIND_IDENT|FIND_STRING) : FIND_STRING); | |
1552 *argp = cnt ? vim_strnsave(*argp, cnt) : NULL; | |
1553 *allocated = TRUE; | |
1554 return TRUE; | |
1555 | |
1556 case '_': /* black hole: always empty */ | |
1557 *argp = (char_u *)""; | |
1558 return TRUE; | |
1559 } | |
1560 | |
1561 return FALSE; | |
1562 } | |
1563 | |
1564 /* | |
15 | 1565 * Paste a yank register into the command line. |
1566 * Only for non-special registers. | |
1567 * Used by CTRL-R command in command-line mode | |
7 | 1568 * insert_reg() can't be used here, because special characters from the |
1569 * register contents will be interpreted as commands. | |
1570 * | |
1571 * return FAIL for failure, OK otherwise | |
1572 */ | |
1573 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1574 cmdline_paste_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1575 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1576 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
|
1577 int remcr) /* don't add CR characters */ |
7 | 1578 { |
1579 long i; | |
1580 | |
1581 get_yank_register(regname, FALSE); | |
1582 if (y_current->y_array == NULL) | |
1583 return FAIL; | |
1584 | |
1585 for (i = 0; i < y_current->y_size; ++i) | |
1586 { | |
1587 cmdline_paste_str(y_current->y_array[i], literally); | |
1588 | |
1015 | 1589 /* 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
|
1590 * 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
|
1591 if ((y_current->y_type == MLINE || i < y_current->y_size - 1) && !remcr) |
7 | 1592 cmdline_paste_str((char_u *)"\r", literally); |
1593 | |
1594 /* Check for CTRL-C, in case someone tries to paste a few thousand | |
1595 * lines and gets bored. */ | |
1596 ui_breakcheck(); | |
1597 if (got_int) | |
1598 return FAIL; | |
1599 } | |
1600 return OK; | |
1601 } | |
1602 | |
1603 #if defined(FEAT_CLIPBOARD) || defined(PROTO) | |
1604 /* | |
1605 * Adjust the register name pointed to with "rp" for the clipboard being | |
1606 * used always and the clipboard being available. | |
1607 */ | |
1608 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1609 adjust_clip_reg(int *rp) |
7 | 1610 { |
2654 | 1611 /* If no reg. specified, and "unnamed" or "unnamedplus" is in 'clipboard', |
1612 * use '*' or '+' reg, respectively. "unnamedplus" prevails. */ | |
6116 | 1613 if (*rp == 0 && (clip_unnamed != 0 || clip_unnamed_saved != 0)) |
1614 { | |
1615 if (clip_unnamed != 0) | |
1616 *rp = ((clip_unnamed & CLIP_UNNAMED_PLUS) && clip_plus.available) | |
2654 | 1617 ? '+' : '*'; |
6116 | 1618 else |
1619 *rp = ((clip_unnamed_saved & CLIP_UNNAMED_PLUS) && clip_plus.available) | |
1620 ? '+' : '*'; | |
1621 } | |
7 | 1622 if (!clip_star.available && *rp == '*') |
1623 *rp = 0; | |
1624 if (!clip_plus.available && *rp == '+') | |
1625 *rp = 0; | |
1626 } | |
1627 #endif | |
1628 | |
1629 /* | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1630 * Handle a delete operation. |
7 | 1631 * |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1632 * Return FAIL if undo failed, OK otherwise. |
7 | 1633 */ |
1634 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1635 op_delete(oparg_T *oap) |
7 | 1636 { |
1637 int n; | |
1638 linenr_T lnum; | |
1639 char_u *ptr; | |
1640 char_u *newp, *oldp; | |
1641 struct block_def bd; | |
1642 linenr_T old_lcount = curbuf->b_ml.ml_line_count; | |
1643 int did_yank = FALSE; | |
3782 | 1644 int orig_regname = oap->regname; |
7 | 1645 |
1646 if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to do */ | |
1647 return OK; | |
1648 | |
1649 /* Nothing to delete, return here. Do prepare undo, for op_change(). */ | |
1650 if (oap->empty) | |
1651 return u_save_cursor(); | |
1652 | |
1653 if (!curbuf->b_p_ma) | |
1654 { | |
1655 EMSG(_(e_modifiable)); | |
1656 return FAIL; | |
1657 } | |
1658 | |
1659 #ifdef FEAT_CLIPBOARD | |
1660 adjust_clip_reg(&oap->regname); | |
1661 #endif | |
1662 | |
1663 #ifdef FEAT_MBYTE | |
1664 if (has_mbyte) | |
1665 mb_adjust_opend(oap); | |
1666 #endif | |
1667 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1668 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1669 * 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
|
1670 * 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
|
1671 * 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
|
1672 */ |
7 | 1673 if ( oap->motion_type == MCHAR |
1674 && !oap->is_VIsual | |
50 | 1675 && !oap->block_mode |
7 | 1676 && oap->line_count > 1 |
3254 | 1677 && oap->motion_force == NUL |
7 | 1678 && oap->op_type == OP_DELETE) |
1679 { | |
2957 | 1680 ptr = ml_get(oap->end.lnum) + oap->end.col; |
1681 if (*ptr != NUL) | |
1682 ptr += oap->inclusive; | |
7 | 1683 ptr = skipwhite(ptr); |
1684 if (*ptr == NUL && inindent(0)) | |
1685 oap->motion_type = MLINE; | |
1686 } | |
1687 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1688 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1689 * 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
|
1690 * 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
|
1691 */ |
7 | 1692 if ( oap->motion_type == MCHAR |
1693 && oap->line_count == 1 | |
1694 && oap->op_type == OP_DELETE | |
1695 && *ml_get(oap->start.lnum) == NUL) | |
1696 { | |
1697 /* | |
446 | 1698 * It's an error to operate on an empty region, when 'E' included in |
7 | 1699 * 'cpoptions' (Vi compatible). |
1700 */ | |
446 | 1701 #ifdef FEAT_VIRTUALEDIT |
1702 if (virtual_op) | |
1703 /* Virtual editing: Nothing gets deleted, but we set the '[ and '] | |
1704 * marks as if it happened. */ | |
1705 goto setmarks; | |
1706 #endif | |
7 | 1707 if (vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL) |
1708 beep_flush(); | |
1709 return OK; | |
1710 } | |
1711 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1712 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1713 * 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
|
1714 * 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
|
1715 * 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
|
1716 */ |
7 | 1717 if (oap->regname != '_') |
1718 { | |
1719 if (oap->regname != 0) | |
1720 { | |
1721 /* check for read-only register */ | |
1722 if (!valid_yank_reg(oap->regname, TRUE)) | |
1723 { | |
1724 beep_flush(); | |
1725 return OK; | |
1726 } | |
1727 get_yank_register(oap->regname, TRUE); /* yank into specif'd reg. */ | |
1728 if (op_yank(oap, TRUE, FALSE) == OK) /* yank without message */ | |
1729 did_yank = TRUE; | |
1730 } | |
1731 | |
1732 /* | |
1733 * Put deleted text into register 1 and shift number registers if the | |
1734 * delete contains a line break, or when a regname has been specified. | |
3782 | 1735 * Use the register name from before adjust_clip_reg() may have |
1736 * changed it. | |
7 | 1737 */ |
3782 | 1738 if (orig_regname != 0 || oap->motion_type == MLINE |
7 | 1739 || oap->line_count > 1 || oap->use_reg_one) |
1740 { | |
1741 y_current = &y_regs[9]; | |
1742 free_yank_all(); /* free register nine */ | |
1743 for (n = 9; n > 1; --n) | |
1744 y_regs[n] = y_regs[n - 1]; | |
1745 y_previous = y_current = &y_regs[1]; | |
1746 y_regs[1].y_array = NULL; /* set register one to empty */ | |
1747 if (op_yank(oap, TRUE, FALSE) == OK) | |
1748 did_yank = TRUE; | |
1749 } | |
1750 | |
3468 | 1751 /* Yank into small delete register when no named register specified |
1752 * and the delete is within one line. */ | |
1753 if (( | |
1754 #ifdef FEAT_CLIPBOARD | |
3584 | 1755 ((clip_unnamed & CLIP_UNNAMED) && oap->regname == '*') || |
1756 ((clip_unnamed & CLIP_UNNAMED_PLUS) && oap->regname == '+') || | |
3468 | 1757 #endif |
1758 oap->regname == 0) && oap->motion_type != MLINE | |
7 | 1759 && oap->line_count == 1) |
1760 { | |
1761 oap->regname = '-'; | |
1762 get_yank_register(oap->regname, TRUE); | |
1763 if (op_yank(oap, TRUE, FALSE) == OK) | |
1764 did_yank = TRUE; | |
1765 oap->regname = 0; | |
1766 } | |
1767 | |
1768 /* | |
1769 * If there's too much stuff to fit in the yank register, then get a | |
1770 * confirmation before doing the delete. This is crude, but simple. | |
1771 * And it avoids doing a delete of something we can't put back if we | |
1772 * want. | |
1773 */ | |
1774 if (!did_yank) | |
1775 { | |
1776 int msg_silent_save = msg_silent; | |
1777 | |
1778 msg_silent = 0; /* must display the prompt */ | |
1779 n = ask_yesno((char_u *)_("cannot yank; delete anyway"), TRUE); | |
1780 msg_silent = msg_silent_save; | |
1781 if (n != 'y') | |
1782 { | |
1783 EMSG(_(e_abort)); | |
1784 return FAIL; | |
1785 } | |
1786 } | |
1787 } | |
1788 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1789 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1790 * 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
|
1791 */ |
7 | 1792 if (oap->block_mode) |
1793 { | |
1794 if (u_save((linenr_T)(oap->start.lnum - 1), | |
1795 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
1796 return FAIL; | |
1797 | |
1798 for (lnum = curwin->w_cursor.lnum; lnum <= oap->end.lnum; ++lnum) | |
1799 { | |
1800 block_prep(oap, &bd, lnum, TRUE); | |
1801 if (bd.textlen == 0) /* nothing to delete */ | |
1802 continue; | |
1803 | |
1804 /* Adjust cursor position for tab replaced by spaces and 'lbr'. */ | |
1805 if (lnum == curwin->w_cursor.lnum) | |
1806 { | |
1807 curwin->w_cursor.col = bd.textcol + bd.startspaces; | |
1808 # ifdef FEAT_VIRTUALEDIT | |
1809 curwin->w_cursor.coladd = 0; | |
1810 # endif | |
1811 } | |
1812 | |
1813 /* n == number of chars deleted | |
1814 * If we delete a TAB, it may be replaced by several characters. | |
1815 * Thus the number of characters may increase! | |
1816 */ | |
1817 n = bd.textlen - bd.startspaces - bd.endspaces; | |
1818 oldp = ml_get(lnum); | |
1819 newp = alloc_check((unsigned)STRLEN(oldp) + 1 - n); | |
1820 if (newp == NULL) | |
1821 continue; | |
1822 /* copy up to deleted part */ | |
1823 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
1824 /* insert spaces */ | |
6929 | 1825 vim_memset(newp + bd.textcol, ' ', |
7 | 1826 (size_t)(bd.startspaces + bd.endspaces)); |
1827 /* copy the part after the deleted part */ | |
1828 oldp += bd.textcol + bd.textlen; | |
1622 | 1829 STRMOVE(newp + bd.textcol + bd.startspaces + bd.endspaces, oldp); |
7 | 1830 /* replace the line */ |
1831 ml_replace(lnum, newp, FALSE); | |
1832 } | |
1833 | |
1834 check_cursor_col(); | |
1835 changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col, | |
1836 oap->end.lnum + 1, 0L); | |
1837 oap->line_count = 0; /* no lines deleted */ | |
1838 } | |
5735 | 1839 else if (oap->motion_type == MLINE) |
7 | 1840 { |
1841 if (oap->op_type == OP_CHANGE) | |
1842 { | |
1843 /* Delete the lines except the first one. Temporarily move the | |
1844 * cursor to the next line. Save the current line number, if the | |
1845 * last line is deleted it may be changed. | |
1846 */ | |
1847 if (oap->line_count > 1) | |
1848 { | |
1849 lnum = curwin->w_cursor.lnum; | |
1850 ++curwin->w_cursor.lnum; | |
1851 del_lines((long)(oap->line_count - 1), TRUE); | |
1852 curwin->w_cursor.lnum = lnum; | |
1853 } | |
1854 if (u_save_cursor() == FAIL) | |
1855 return FAIL; | |
1856 if (curbuf->b_p_ai) /* don't delete indent */ | |
1857 { | |
1858 beginline(BL_WHITE); /* cursor on first non-white */ | |
1859 did_ai = TRUE; /* delete the indent when ESC hit */ | |
1860 ai_col = curwin->w_cursor.col; | |
1861 } | |
1862 else | |
1863 beginline(0); /* cursor in column 0 */ | |
1864 truncate_line(FALSE); /* delete the rest of the line */ | |
1865 /* leave cursor past last char in line */ | |
1866 if (oap->line_count > 1) | |
1867 u_clearline(); /* "U" command not possible after "2cc" */ | |
1868 } | |
1869 else | |
1870 { | |
1871 del_lines(oap->line_count, TRUE); | |
1872 beginline(BL_WHITE | BL_FIX); | |
1873 u_clearline(); /* "U" command not possible after "dd" */ | |
1874 } | |
1875 } | |
1876 else | |
1877 { | |
1878 #ifdef FEAT_VIRTUALEDIT | |
1879 if (virtual_op) | |
1880 { | |
1881 int endcol = 0; | |
1882 | |
1883 /* For virtualedit: break the tabs that are partly included. */ | |
1884 if (gchar_pos(&oap->start) == '\t') | |
1885 { | |
1886 if (u_save_cursor() == FAIL) /* save first line for undo */ | |
1887 return FAIL; | |
1888 if (oap->line_count == 1) | |
1889 endcol = getviscol2(oap->end.col, oap->end.coladd); | |
1890 coladvance_force(getviscol2(oap->start.col, oap->start.coladd)); | |
1891 oap->start = curwin->w_cursor; | |
1892 if (oap->line_count == 1) | |
1893 { | |
1894 coladvance(endcol); | |
1895 oap->end.col = curwin->w_cursor.col; | |
1896 oap->end.coladd = curwin->w_cursor.coladd; | |
1897 curwin->w_cursor = oap->start; | |
1898 } | |
1899 } | |
1900 | |
1901 /* Break a tab only when it's included in the area. */ | |
1902 if (gchar_pos(&oap->end) == '\t' | |
1903 && (int)oap->end.coladd < oap->inclusive) | |
1904 { | |
1905 /* save last line for undo */ | |
1906 if (u_save((linenr_T)(oap->end.lnum - 1), | |
1907 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
1908 return FAIL; | |
1909 curwin->w_cursor = oap->end; | |
1910 coladvance_force(getviscol2(oap->end.col, oap->end.coladd)); | |
1911 oap->end = curwin->w_cursor; | |
1912 curwin->w_cursor = oap->start; | |
1913 } | |
1914 } | |
1915 #endif | |
1916 | |
1917 if (oap->line_count == 1) /* delete characters within one line */ | |
1918 { | |
1919 if (u_save_cursor() == FAIL) /* save line for undo */ | |
1920 return FAIL; | |
1921 | |
1922 /* if 'cpoptions' contains '$', display '$' at end of change */ | |
5735 | 1923 if ( vim_strchr(p_cpo, CPO_DOLLAR) != NULL |
7 | 1924 && oap->op_type == OP_CHANGE |
1925 && oap->end.lnum == curwin->w_cursor.lnum | |
5735 | 1926 && !oap->is_VIsual) |
7 | 1927 display_dollar(oap->end.col - !oap->inclusive); |
1928 | |
1929 n = oap->end.col - oap->start.col + 1 - !oap->inclusive; | |
1930 | |
1931 #ifdef FEAT_VIRTUALEDIT | |
1932 if (virtual_op) | |
1933 { | |
1934 /* fix up things for virtualedit-delete: | |
1935 * break the tabs which are going to get in our way | |
1936 */ | |
1937 char_u *curline = ml_get_curline(); | |
1938 int len = (int)STRLEN(curline); | |
1939 | |
1940 if (oap->end.coladd != 0 | |
1941 && (int)oap->end.col >= len - 1 | |
1942 && !(oap->start.coladd && (int)oap->end.col >= len - 1)) | |
1943 n++; | |
1944 /* Delete at least one char (e.g, when on a control char). */ | |
1945 if (n == 0 && oap->start.coladd != oap->end.coladd) | |
1946 n = 1; | |
1947 | |
1948 /* When deleted a char in the line, reset coladd. */ | |
1949 if (gchar_cursor() != NUL) | |
1950 curwin->w_cursor.coladd = 0; | |
1951 } | |
1952 #endif | |
6826 | 1953 (void)del_bytes((long)n, !virtual_op, |
1954 oap->op_type == OP_DELETE && !oap->is_VIsual); | |
7 | 1955 } |
1956 else /* delete characters between lines */ | |
1957 { | |
1958 pos_T curpos; | |
1959 | |
1960 /* save deleted and changed lines for undo */ | |
1961 if (u_save((linenr_T)(curwin->w_cursor.lnum - 1), | |
1962 (linenr_T)(curwin->w_cursor.lnum + oap->line_count)) == FAIL) | |
1963 return FAIL; | |
1964 | |
1965 truncate_line(TRUE); /* delete from cursor to end of line */ | |
1966 | |
1967 curpos = curwin->w_cursor; /* remember curwin->w_cursor */ | |
1968 ++curwin->w_cursor.lnum; | |
1969 del_lines((long)(oap->line_count - 2), FALSE); | |
1970 | |
6826 | 1971 /* delete from start of line until op_end */ |
2957 | 1972 n = (oap->end.col + 1 - !oap->inclusive); |
6826 | 1973 curwin->w_cursor.col = 0; |
1974 (void)del_bytes((long)n, !virtual_op, | |
1975 oap->op_type == OP_DELETE && !oap->is_VIsual); | |
1976 curwin->w_cursor = curpos; /* restore curwin->w_cursor */ | |
1977 (void)do_join(2, FALSE, FALSE, FALSE, FALSE); | |
7 | 1978 } |
1979 } | |
1980 | |
1981 msgmore(curbuf->b_ml.ml_line_count - old_lcount); | |
1982 | |
446 | 1983 #ifdef FEAT_VIRTUALEDIT |
1984 setmarks: | |
1985 #endif | |
7 | 1986 if (oap->block_mode) |
1987 { | |
1988 curbuf->b_op_end.lnum = oap->end.lnum; | |
1989 curbuf->b_op_end.col = oap->start.col; | |
1990 } | |
1991 else | |
1992 curbuf->b_op_end = oap->start; | |
1993 curbuf->b_op_start = oap->start; | |
1994 | |
1995 return OK; | |
1996 } | |
1997 | |
1998 #ifdef FEAT_MBYTE | |
1999 /* | |
2000 * Adjust end of operating area for ending on a multi-byte character. | |
2001 * Used for deletion. | |
2002 */ | |
2003 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2004 mb_adjust_opend(oparg_T *oap) |
7 | 2005 { |
2006 char_u *p; | |
2007 | |
2008 if (oap->inclusive) | |
2009 { | |
2010 p = ml_get(oap->end.lnum); | |
2011 oap->end.col += mb_tail_off(p, p + oap->end.col); | |
2012 } | |
2013 } | |
2014 #endif | |
2015 | |
2016 #if defined(FEAT_VISUALEXTRA) || defined(PROTO) | |
2017 /* | |
2018 * Replace a whole area with one character. | |
2019 */ | |
2020 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2021 op_replace(oparg_T *oap, int c) |
7 | 2022 { |
2023 int n, numc; | |
2024 #ifdef FEAT_MBYTE | |
2025 int num_chars; | |
2026 #endif | |
2027 char_u *newp, *oldp; | |
2028 size_t oldlen; | |
2029 struct block_def bd; | |
5428 | 2030 char_u *after_p = NULL; |
2031 int had_ctrl_v_cr = (c == -1 || c == -2); | |
7 | 2032 |
2033 if ((curbuf->b_ml.ml_flags & ML_EMPTY ) || oap->empty) | |
2034 return OK; /* nothing to do */ | |
2035 | |
5428 | 2036 if (had_ctrl_v_cr) |
2037 c = (c == -1 ? '\r' : '\n'); | |
2038 | |
7 | 2039 #ifdef FEAT_MBYTE |
2040 if (has_mbyte) | |
2041 mb_adjust_opend(oap); | |
2042 #endif | |
2043 | |
2044 if (u_save((linenr_T)(oap->start.lnum - 1), | |
2045 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
2046 return FAIL; | |
2047 | |
2048 /* | |
2049 * block mode replace | |
2050 */ | |
2051 if (oap->block_mode) | |
2052 { | |
2053 bd.is_MAX = (curwin->w_curswant == MAXCOL); | |
2054 for ( ; curwin->w_cursor.lnum <= oap->end.lnum; ++curwin->w_cursor.lnum) | |
2055 { | |
1982 | 2056 curwin->w_cursor.col = 0; /* make sure cursor position is valid */ |
7 | 2057 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); |
2058 if (bd.textlen == 0 && (!virtual_op || bd.is_MAX)) | |
2059 continue; /* nothing to replace */ | |
2060 | |
2061 /* n == number of extra chars required | |
2062 * If we split a TAB, it may be replaced by several characters. | |
2063 * Thus the number of characters may increase! | |
2064 */ | |
2065 #ifdef FEAT_VIRTUALEDIT | |
2066 /* If the range starts in virtual space, count the initial | |
2067 * coladd offset as part of "startspaces" */ | |
2068 if (virtual_op && bd.is_short && *bd.textstart == NUL) | |
2069 { | |
2070 pos_T vpos; | |
2071 | |
1982 | 2072 vpos.lnum = curwin->w_cursor.lnum; |
7 | 2073 getvpos(&vpos, oap->start_vcol); |
2074 bd.startspaces += vpos.coladd; | |
2075 n = bd.startspaces; | |
2076 } | |
2077 else | |
2078 #endif | |
2079 /* allow for pre spaces */ | |
2080 n = (bd.startspaces ? bd.start_char_vcols - 1 : 0); | |
2081 | |
2082 /* allow for post spp */ | |
2083 n += (bd.endspaces | |
2084 #ifdef FEAT_VIRTUALEDIT | |
2085 && !bd.is_oneChar | |
2086 #endif | |
2087 && bd.end_char_vcols > 0) ? bd.end_char_vcols - 1 : 0; | |
2088 /* Figure out how many characters to replace. */ | |
2089 numc = oap->end_vcol - oap->start_vcol + 1; | |
2090 if (bd.is_short && (!virtual_op || bd.is_MAX)) | |
2091 numc -= (oap->end_vcol - bd.end_vcol) + 1; | |
2092 | |
2093 #ifdef FEAT_MBYTE | |
2094 /* A double-wide character can be replaced only up to half the | |
2095 * times. */ | |
2096 if ((*mb_char2cells)(c) > 1) | |
2097 { | |
2098 if ((numc & 1) && !bd.is_short) | |
2099 { | |
2100 ++bd.endspaces; | |
2101 ++n; | |
2102 } | |
2103 numc = numc / 2; | |
2104 } | |
2105 | |
2106 /* Compute bytes needed, move character count to num_chars. */ | |
2107 num_chars = numc; | |
2108 numc *= (*mb_char2len)(c); | |
2109 #endif | |
2110 /* oldlen includes textlen, so don't double count */ | |
2111 n += numc - bd.textlen; | |
2112 | |
2113 oldp = ml_get_curline(); | |
2114 oldlen = STRLEN(oldp); | |
2115 newp = alloc_check((unsigned)oldlen + 1 + n); | |
2116 if (newp == NULL) | |
2117 continue; | |
2118 vim_memset(newp, NUL, (size_t)(oldlen + 1 + n)); | |
2119 /* copy up to deleted part */ | |
2120 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
2121 oldp += bd.textcol + bd.textlen; | |
2122 /* insert pre-spaces */ | |
6929 | 2123 vim_memset(newp + bd.textcol, ' ', (size_t)bd.startspaces); |
7 | 2124 /* insert replacement chars CHECK FOR ALLOCATED SPACE */ |
5428 | 2125 /* -1/-2 is used for entering CR literally. */ |
2126 if (had_ctrl_v_cr || (c != '\r' && c != '\n')) | |
7 | 2127 { |
5428 | 2128 #ifdef FEAT_MBYTE |
2129 if (has_mbyte) | |
2130 { | |
2131 n = (int)STRLEN(newp); | |
2132 while (--num_chars >= 0) | |
2133 n += (*mb_char2bytes)(c, newp + n); | |
2134 } | |
2135 else | |
2136 #endif | |
6929 | 2137 vim_memset(newp + STRLEN(newp), c, (size_t)numc); |
5428 | 2138 if (!bd.is_short) |
2139 { | |
2140 /* insert post-spaces */ | |
6929 | 2141 vim_memset(newp + STRLEN(newp), ' ', (size_t)bd.endspaces); |
5428 | 2142 /* copy the part after the changed part */ |
2143 STRMOVE(newp + STRLEN(newp), oldp); | |
2144 } | |
7 | 2145 } |
2146 else | |
2147 { | |
5428 | 2148 /* Replacing with \r or \n means splitting the line. */ |
5475 | 2149 after_p = alloc_check( |
2150 (unsigned)(oldlen + 1 + n - STRLEN(newp))); | |
5428 | 2151 if (after_p != NULL) |
2152 STRMOVE(after_p, oldp); | |
7 | 2153 } |
2154 /* replace the line */ | |
2155 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
5428 | 2156 if (after_p != NULL) |
2157 { | |
2158 ml_append(curwin->w_cursor.lnum++, after_p, 0, FALSE); | |
2159 appended_lines_mark(curwin->w_cursor.lnum, 1L); | |
2160 oap->end.lnum++; | |
2161 vim_free(after_p); | |
2162 } | |
7 | 2163 } |
2164 } | |
2165 else | |
2166 { | |
2167 /* | |
2168 * MCHAR and MLINE motion replace. | |
2169 */ | |
2170 if (oap->motion_type == MLINE) | |
2171 { | |
2172 oap->start.col = 0; | |
2173 curwin->w_cursor.col = 0; | |
2174 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
2175 if (oap->end.col) | |
2176 --oap->end.col; | |
2177 } | |
2178 else if (!oap->inclusive) | |
2179 dec(&(oap->end)); | |
2180 | |
2181 while (ltoreq(curwin->w_cursor, oap->end)) | |
2182 { | |
2183 n = gchar_cursor(); | |
2184 if (n != NUL) | |
2185 { | |
2186 #ifdef FEAT_MBYTE | |
2187 if ((*mb_char2len)(c) > 1 || (*mb_char2len)(n) > 1) | |
2188 { | |
2189 /* This is slow, but it handles replacing a single-byte | |
2190 * with a multi-byte and the other way around. */ | |
4203 | 2191 if (curwin->w_cursor.lnum == oap->end.lnum) |
2192 oap->end.col += (*mb_char2len)(c) - (*mb_char2len)(n); | |
7 | 2193 n = State; |
2194 State = REPLACE; | |
2195 ins_char(c); | |
2196 State = n; | |
2197 /* Backup to the replaced character. */ | |
2198 dec_cursor(); | |
2199 } | |
2200 else | |
2201 #endif | |
2202 { | |
2203 #ifdef FEAT_VIRTUALEDIT | |
2204 if (n == TAB) | |
2205 { | |
2206 int end_vcol = 0; | |
2207 | |
2208 if (curwin->w_cursor.lnum == oap->end.lnum) | |
2209 { | |
2210 /* oap->end has to be recalculated when | |
2211 * the tab breaks */ | |
2212 end_vcol = getviscol2(oap->end.col, | |
2213 oap->end.coladd); | |
2214 } | |
2215 coladvance_force(getviscol()); | |
2216 if (curwin->w_cursor.lnum == oap->end.lnum) | |
2217 getvpos(&oap->end, end_vcol); | |
2218 } | |
2219 #endif | |
2220 pchar(curwin->w_cursor, c); | |
2221 } | |
2222 } | |
2223 #ifdef FEAT_VIRTUALEDIT | |
2224 else if (virtual_op && curwin->w_cursor.lnum == oap->end.lnum) | |
2225 { | |
2226 int virtcols = oap->end.coladd; | |
2227 | |
2228 if (curwin->w_cursor.lnum == oap->start.lnum | |
2229 && oap->start.col == oap->end.col && oap->start.coladd) | |
2230 virtcols -= oap->start.coladd; | |
2231 | |
2232 /* oap->end has been trimmed so it's effectively inclusive; | |
2233 * as a result an extra +1 must be counted so we don't | |
2234 * trample the NUL byte. */ | |
2235 coladvance_force(getviscol2(oap->end.col, oap->end.coladd) + 1); | |
2236 curwin->w_cursor.col -= (virtcols + 1); | |
2237 for (; virtcols >= 0; virtcols--) | |
2238 { | |
2239 pchar(curwin->w_cursor, c); | |
2240 if (inc(&curwin->w_cursor) == -1) | |
2241 break; | |
2242 } | |
2243 } | |
2244 #endif | |
2245 | |
2246 /* Advance to next character, stop at the end of the file. */ | |
2247 if (inc_cursor() == -1) | |
2248 break; | |
2249 } | |
2250 } | |
2251 | |
2252 curwin->w_cursor = oap->start; | |
2253 check_cursor(); | |
2254 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, 0L); | |
2255 | |
2256 /* Set "'[" and "']" marks. */ | |
2257 curbuf->b_op_start = oap->start; | |
2258 curbuf->b_op_end = oap->end; | |
2259 | |
2260 return OK; | |
2261 } | |
2262 #endif | |
2263 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
2264 static int swapchars(int op_type, pos_T *pos, int length); |
1525 | 2265 |
7 | 2266 /* |
2267 * Handle the (non-standard vi) tilde operator. Also for "gu", "gU" and "g?". | |
2268 */ | |
2269 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2270 op_tilde(oparg_T *oap) |
7 | 2271 { |
2272 pos_T pos; | |
2273 struct block_def bd; | |
1528 | 2274 int did_change = FALSE; |
7 | 2275 |
2276 if (u_save((linenr_T)(oap->start.lnum - 1), | |
2277 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
2278 return; | |
2279 | |
2280 pos = oap->start; | |
2281 if (oap->block_mode) /* Visual block mode */ | |
2282 { | |
2283 for (; pos.lnum <= oap->end.lnum; ++pos.lnum) | |
2284 { | |
1766 | 2285 int one_change; |
2286 | |
7 | 2287 block_prep(oap, &bd, pos.lnum, FALSE); |
2288 pos.col = bd.textcol; | |
1766 | 2289 one_change = swapchars(oap->op_type, &pos, bd.textlen); |
2290 did_change |= one_change; | |
1525 | 2291 |
5735 | 2292 #ifdef FEAT_NETBEANS_INTG |
2210 | 2293 if (netbeans_active() && one_change) |
7 | 2294 { |
2295 char_u *ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
2296 | |
33 | 2297 netbeans_removed(curbuf, pos.lnum, bd.textcol, |
2298 (long)bd.textlen); | |
7 | 2299 netbeans_inserted(curbuf, pos.lnum, bd.textcol, |
2210 | 2300 &ptr[bd.textcol], bd.textlen); |
7 | 2301 } |
5735 | 2302 #endif |
7 | 2303 } |
2304 if (did_change) | |
2305 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); | |
2306 } | |
2307 else /* not block mode */ | |
2308 { | |
2309 if (oap->motion_type == MLINE) | |
2310 { | |
2311 oap->start.col = 0; | |
2312 pos.col = 0; | |
2313 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
2314 if (oap->end.col) | |
2315 --oap->end.col; | |
2316 } | |
2317 else if (!oap->inclusive) | |
2318 dec(&(oap->end)); | |
2319 | |
1528 | 2320 if (pos.lnum == oap->end.lnum) |
2321 did_change = swapchars(oap->op_type, &pos, | |
2322 oap->end.col - pos.col + 1); | |
2323 else | |
2324 for (;;) | |
2325 { | |
2326 did_change |= swapchars(oap->op_type, &pos, | |
2327 pos.lnum == oap->end.lnum ? oap->end.col + 1: | |
2328 (int)STRLEN(ml_get_pos(&pos))); | |
2329 if (ltoreq(oap->end, pos) || inc(&pos) == -1) | |
2330 break; | |
2331 } | |
7 | 2332 if (did_change) |
2333 { | |
2334 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, | |
2335 0L); | |
2336 #ifdef FEAT_NETBEANS_INTG | |
2210 | 2337 if (netbeans_active() && did_change) |
7 | 2338 { |
2339 char_u *ptr; | |
2340 int count; | |
2341 | |
2342 pos = oap->start; | |
2343 while (pos.lnum < oap->end.lnum) | |
2344 { | |
2345 ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
835 | 2346 count = (int)STRLEN(ptr) - pos.col; |
33 | 2347 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7 | 2348 netbeans_inserted(curbuf, pos.lnum, pos.col, |
2210 | 2349 &ptr[pos.col], count); |
7 | 2350 pos.col = 0; |
2351 pos.lnum++; | |
2352 } | |
2353 ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
2354 count = oap->end.col - pos.col + 1; | |
33 | 2355 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7 | 2356 netbeans_inserted(curbuf, pos.lnum, pos.col, |
2210 | 2357 &ptr[pos.col], count); |
7 | 2358 } |
2359 #endif | |
2360 } | |
2361 } | |
2362 | |
2363 if (!did_change && oap->is_VIsual) | |
2364 /* No change: need to remove the Visual selection */ | |
2365 redraw_curbuf_later(INVERTED); | |
2366 | |
2367 /* | |
2368 * Set '[ and '] marks. | |
2369 */ | |
2370 curbuf->b_op_start = oap->start; | |
2371 curbuf->b_op_end = oap->end; | |
2372 | |
2373 if (oap->line_count > p_report) | |
2374 { | |
2375 if (oap->line_count == 1) | |
2376 MSG(_("1 line changed")); | |
2377 else | |
2378 smsg((char_u *)_("%ld lines changed"), oap->line_count); | |
2379 } | |
2380 } | |
2381 | |
2382 /* | |
1525 | 2383 * Invoke swapchar() on "length" bytes at position "pos". |
2384 * "pos" is advanced to just after the changed characters. | |
2385 * "length" is rounded up to include the whole last multi-byte character. | |
2386 * Also works correctly when the number of bytes changes. | |
2387 * Returns TRUE if some character was changed. | |
2388 */ | |
2389 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2390 swapchars(int op_type, pos_T *pos, int length) |
1525 | 2391 { |
2392 int todo; | |
2393 int did_change = 0; | |
2394 | |
2395 for (todo = length; todo > 0; --todo) | |
2396 { | |
2397 # ifdef FEAT_MBYTE | |
2398 if (has_mbyte) | |
5288
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2399 { |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2400 int len = (*mb_ptr2len)(ml_get_pos(pos)); |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2401 |
1525 | 2402 /* we're counting bytes, not characters */ |
5288
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2403 if (len > 0) |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2404 todo -= len - 1; |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2405 } |
1525 | 2406 # endif |
2407 did_change |= swapchar(op_type, pos); | |
2408 if (inc(pos) == -1) /* at end of file */ | |
2409 break; | |
2410 } | |
2411 return did_change; | |
2412 } | |
2413 | |
2414 /* | |
7 | 2415 * If op_type == OP_UPPER: make uppercase, |
2416 * if op_type == OP_LOWER: make lowercase, | |
2417 * if op_type == OP_ROT13: do rot13 encoding, | |
2418 * else swap case of character at 'pos' | |
2419 * returns TRUE when something actually changed. | |
2420 */ | |
2421 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2422 swapchar(int op_type, pos_T *pos) |
7 | 2423 { |
2424 int c; | |
2425 int nc; | |
2426 | |
2427 c = gchar_pos(pos); | |
2428 | |
2429 /* Only do rot13 encoding for ASCII characters. */ | |
2430 if (c >= 0x80 && op_type == OP_ROT13) | |
2431 return FALSE; | |
2432 | |
2433 #ifdef FEAT_MBYTE | |
1525 | 2434 if (op_type == OP_UPPER && c == 0xdf |
2435 && (enc_latin1like || STRCMP(p_enc, "iso-8859-2") == 0)) | |
493 | 2436 { |
2437 pos_T sp = curwin->w_cursor; | |
2438 | |
2439 /* Special handling of German sharp s: change to "SS". */ | |
2440 curwin->w_cursor = *pos; | |
2441 del_char(FALSE); | |
2442 ins_char('S'); | |
2443 ins_char('S'); | |
2444 curwin->w_cursor = sp; | |
2445 inc(pos); | |
2446 } | |
2447 | |
7 | 2448 if (enc_dbcs != 0 && c >= 0x100) /* No lower/uppercase letter */ |
2449 return FALSE; | |
2450 #endif | |
2451 nc = c; | |
2452 if (MB_ISLOWER(c)) | |
2453 { | |
2454 if (op_type == OP_ROT13) | |
2455 nc = ROT13(c, 'a'); | |
2456 else if (op_type != OP_LOWER) | |
2457 nc = MB_TOUPPER(c); | |
2458 } | |
2459 else if (MB_ISUPPER(c)) | |
2460 { | |
2461 if (op_type == OP_ROT13) | |
2462 nc = ROT13(c, 'A'); | |
2463 else if (op_type != OP_UPPER) | |
2464 nc = MB_TOLOWER(c); | |
2465 } | |
2466 if (nc != c) | |
2467 { | |
2468 #ifdef FEAT_MBYTE | |
2469 if (enc_utf8 && (c >= 0x80 || nc >= 0x80)) | |
2470 { | |
2471 pos_T sp = curwin->w_cursor; | |
2472 | |
2473 curwin->w_cursor = *pos; | |
2451
0b8612c2814d
Fix: changing case of a character removed combining characters.
Bram Moolenaar <bram@vim.org>
parents:
2446
diff
changeset
|
2474 /* 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
|
2475 del_bytes(utf_ptr2len(ml_get_cursor()), FALSE, FALSE); |
7 | 2476 ins_char(nc); |
2477 curwin->w_cursor = sp; | |
2478 } | |
2479 else | |
2480 #endif | |
2481 pchar(*pos, nc); | |
2482 return TRUE; | |
2483 } | |
2484 return FALSE; | |
2485 } | |
2486 | |
2487 #if defined(FEAT_VISUALEXTRA) || defined(PROTO) | |
2488 /* | |
2489 * op_insert - Insert and append operators for Visual mode. | |
2490 */ | |
2491 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2492 op_insert(oparg_T *oap, long count1) |
7 | 2493 { |
2494 long ins_len, pre_textlen = 0; | |
2495 char_u *firstline, *ins_text; | |
2496 struct block_def bd; | |
2497 int i; | |
6579 | 2498 pos_T t1; |
7 | 2499 |
2500 /* edit() changes this - record it for OP_APPEND */ | |
2501 bd.is_MAX = (curwin->w_curswant == MAXCOL); | |
2502 | |
2503 /* vis block is still marked. Get rid of it now. */ | |
2504 curwin->w_cursor.lnum = oap->start.lnum; | |
2505 update_screen(INVERTED); | |
2506 | |
2507 if (oap->block_mode) | |
2508 { | |
2509 #ifdef FEAT_VIRTUALEDIT | |
2510 /* When 'virtualedit' is used, need to insert the extra spaces before | |
2511 * doing block_prep(). When only "block" is used, virtual edit is | |
2512 * already disabled, but still need it when calling | |
2513 * coladvance_force(). */ | |
2514 if (curwin->w_cursor.coladd > 0) | |
2515 { | |
2516 int old_ve_flags = ve_flags; | |
2517 | |
2518 ve_flags = VE_ALL; | |
2519 if (u_save_cursor() == FAIL) | |
2520 return; | |
2521 coladvance_force(oap->op_type == OP_APPEND | |
2522 ? oap->end_vcol + 1 : getviscol()); | |
2523 if (oap->op_type == OP_APPEND) | |
2524 --curwin->w_cursor.col; | |
2525 ve_flags = old_ve_flags; | |
2526 } | |
2527 #endif | |
2528 /* Get the info about the block before entering the text */ | |
2529 block_prep(oap, &bd, oap->start.lnum, TRUE); | |
2530 firstline = ml_get(oap->start.lnum) + bd.textcol; | |
2531 if (oap->op_type == OP_APPEND) | |
2532 firstline += bd.textlen; | |
2533 pre_textlen = (long)STRLEN(firstline); | |
2534 } | |
2535 | |
2536 if (oap->op_type == OP_APPEND) | |
2537 { | |
2538 if (oap->block_mode | |
2539 #ifdef FEAT_VIRTUALEDIT | |
2540 && curwin->w_cursor.coladd == 0 | |
2541 #endif | |
2542 ) | |
2543 { | |
2544 /* Move the cursor to the character right of the block. */ | |
2545 curwin->w_set_curswant = TRUE; | |
2546 while (*ml_get_cursor() != NUL | |
2547 && (curwin->w_cursor.col < bd.textcol + bd.textlen)) | |
2548 ++curwin->w_cursor.col; | |
2549 if (bd.is_short && !bd.is_MAX) | |
2550 { | |
2551 /* First line was too short, make it longer and adjust the | |
2552 * values in "bd". */ | |
2553 if (u_save_cursor() == FAIL) | |
2554 return; | |
2555 for (i = 0; i < bd.endspaces; ++i) | |
2556 ins_char(' '); | |
2557 bd.textlen += bd.endspaces; | |
2558 } | |
2559 } | |
2560 else | |
2561 { | |
2562 curwin->w_cursor = oap->end; | |
893 | 2563 check_cursor_col(); |
7 | 2564 |
2565 /* Works just like an 'i'nsert on the next character. */ | |
2566 if (!lineempty(curwin->w_cursor.lnum) | |
2567 && oap->start_vcol != oap->end_vcol) | |
2568 inc_cursor(); | |
2569 } | |
2570 } | |
2571 | |
6579 | 2572 t1 = oap->start; |
7 | 2573 edit(NUL, FALSE, (linenr_T)count1); |
2574 | |
6579 | 2575 /* When a tab was inserted, and the characters in front of the tab |
2576 * have been converted to a tab as well, the column of the cursor | |
2577 * might have actually been reduced, so need to adjust here. */ | |
2578 if (t1.lnum == curbuf->b_op_start_orig.lnum | |
2579 && lt(curbuf->b_op_start_orig, t1)) | |
2580 oap->start = curbuf->b_op_start_orig; | |
2581 | |
1477 | 2582 /* If user has moved off this line, we don't know what to do, so do |
2583 * nothing. | |
2584 * Also don't repeat the insert when Insert mode ended with CTRL-C. */ | |
2585 if (curwin->w_cursor.lnum != oap->start.lnum || got_int) | |
7 | 2586 return; |
2587 | |
2588 if (oap->block_mode) | |
2589 { | |
2590 struct block_def bd2; | |
2591 | |
5471 | 2592 /* The user may have moved the cursor before inserting something, try |
2593 * to adjust the block for that. */ | |
5680 | 2594 if (oap->start.lnum == curbuf->b_op_start_orig.lnum && !bd.is_MAX) |
5471 | 2595 { |
2596 if (oap->op_type == OP_INSERT | |
5730 | 2597 && oap->start.col |
2598 #ifdef FEAT_VIRTUALEDIT | |
2599 + oap->start.coladd | |
2600 #endif | |
2601 != curbuf->b_op_start_orig.col | |
2602 #ifdef FEAT_VIRTUALEDIT | |
2603 + curbuf->b_op_start_orig.coladd | |
2604 #endif | |
2605 ) | |
5471 | 2606 { |
6579 | 2607 int t = getviscol2(curbuf->b_op_start_orig.col, |
2608 curbuf->b_op_start_orig.coladd); | |
5680 | 2609 oap->start.col = curbuf->b_op_start_orig.col; |
6579 | 2610 pre_textlen -= t - oap->start_vcol; |
2611 oap->start_vcol = t; | |
5471 | 2612 } |
2613 else if (oap->op_type == OP_APPEND | |
5730 | 2614 && oap->end.col |
2615 #ifdef FEAT_VIRTUALEDIT | |
2616 + oap->end.coladd | |
2617 #endif | |
2618 >= curbuf->b_op_start_orig.col | |
2619 #ifdef FEAT_VIRTUALEDIT | |
2620 + curbuf->b_op_start_orig.coladd | |
2621 #endif | |
2622 ) | |
5471 | 2623 { |
6579 | 2624 int t = getviscol2(curbuf->b_op_start_orig.col, |
2625 curbuf->b_op_start_orig.coladd); | |
5680 | 2626 oap->start.col = curbuf->b_op_start_orig.col; |
5471 | 2627 /* reset pre_textlen to the value of OP_INSERT */ |
2628 pre_textlen += bd.textlen; | |
6579 | 2629 pre_textlen -= t - oap->start_vcol; |
2630 oap->start_vcol = t; | |
5471 | 2631 oap->op_type = OP_INSERT; |
2632 } | |
2633 } | |
2634 | |
7 | 2635 /* |
2636 * Spaces and tabs in the indent may have changed to other spaces and | |
1392 | 2637 * tabs. Get the starting column again and correct the length. |
7 | 2638 * Don't do this when "$" used, end-of-line will have changed. |
2639 */ | |
2640 block_prep(oap, &bd2, oap->start.lnum, TRUE); | |
2641 if (!bd.is_MAX || bd2.textlen < bd.textlen) | |
2642 { | |
2643 if (oap->op_type == OP_APPEND) | |
2644 { | |
2645 pre_textlen += bd2.textlen - bd.textlen; | |
2646 if (bd2.endspaces) | |
2647 --bd2.textlen; | |
2648 } | |
2649 bd.textcol = bd2.textcol; | |
2650 bd.textlen = bd2.textlen; | |
2651 } | |
2652 | |
2653 /* | |
2654 * Subsequent calls to ml_get() flush the firstline data - take a | |
2655 * copy of the required string. | |
2656 */ | |
2657 firstline = ml_get(oap->start.lnum) + bd.textcol; | |
2658 if (oap->op_type == OP_APPEND) | |
2659 firstline += bd.textlen; | |
3421 | 2660 if (pre_textlen >= 0 |
2661 && (ins_len = (long)STRLEN(firstline) - pre_textlen) > 0) | |
7 | 2662 { |
2663 ins_text = vim_strnsave(firstline, (int)ins_len); | |
2664 if (ins_text != NULL) | |
2665 { | |
2666 /* block handled here */ | |
2667 if (u_save(oap->start.lnum, | |
2668 (linenr_T)(oap->end.lnum + 1)) == OK) | |
2669 block_insert(oap, ins_text, (oap->op_type == OP_INSERT), | |
2670 &bd); | |
2671 | |
2672 curwin->w_cursor.col = oap->start.col; | |
2673 check_cursor(); | |
2674 vim_free(ins_text); | |
2675 } | |
2676 } | |
2677 } | |
2678 } | |
2679 #endif | |
2680 | |
2681 /* | |
2682 * op_change - handle a change operation | |
2683 * | |
2684 * return TRUE if edit() returns because of a CTRL-O command | |
2685 */ | |
2686 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2687 op_change(oparg_T *oap) |
7 | 2688 { |
2689 colnr_T l; | |
2690 int retval; | |
2691 #ifdef FEAT_VISUALEXTRA | |
2692 long offset; | |
2693 linenr_T linenr; | |
1392 | 2694 long ins_len; |
2695 long pre_textlen = 0; | |
2696 long pre_indent = 0; | |
7 | 2697 char_u *firstline; |
2698 char_u *ins_text, *newp, *oldp; | |
2699 struct block_def bd; | |
2700 #endif | |
2701 | |
2702 l = oap->start.col; | |
2703 if (oap->motion_type == MLINE) | |
2704 { | |
2705 l = 0; | |
2706 #ifdef FEAT_SMARTINDENT | |
2707 if (!p_paste && curbuf->b_p_si | |
2708 # ifdef FEAT_CINDENT | |
2709 && !curbuf->b_p_cin | |
2710 # endif | |
2711 ) | |
2712 can_si = TRUE; /* It's like opening a new line, do si */ | |
2713 #endif | |
2714 } | |
2715 | |
2716 /* First delete the text in the region. In an empty buffer only need to | |
2717 * save for undo */ | |
2718 if (curbuf->b_ml.ml_flags & ML_EMPTY) | |
2719 { | |
2720 if (u_save_cursor() == FAIL) | |
2721 return FALSE; | |
2722 } | |
2723 else if (op_delete(oap) == FAIL) | |
2724 return FALSE; | |
2725 | |
2726 if ((l > curwin->w_cursor.col) && !lineempty(curwin->w_cursor.lnum) | |
2727 && !virtual_op) | |
2728 inc_cursor(); | |
2729 | |
2730 #ifdef FEAT_VISUALEXTRA | |
2731 /* check for still on same line (<CR> in inserted text meaningless) */ | |
2732 /* skip blank lines too */ | |
2733 if (oap->block_mode) | |
2734 { | |
2735 # ifdef FEAT_VIRTUALEDIT | |
2736 /* Add spaces before getting the current line length. */ | |
2737 if (virtual_op && (curwin->w_cursor.coladd > 0 | |
2738 || gchar_cursor() == NUL)) | |
2739 coladvance_force(getviscol()); | |
2740 # endif | |
1392 | 2741 firstline = ml_get(oap->start.lnum); |
2742 pre_textlen = (long)STRLEN(firstline); | |
2743 pre_indent = (long)(skipwhite(firstline) - firstline); | |
7 | 2744 bd.textcol = curwin->w_cursor.col; |
2745 } | |
2746 #endif | |
2747 | |
2748 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) | |
2749 if (oap->motion_type == MLINE) | |
2750 fix_indent(); | |
2751 #endif | |
2752 | |
2753 retval = edit(NUL, FALSE, (linenr_T)1); | |
2754 | |
2755 #ifdef FEAT_VISUALEXTRA | |
2756 /* | |
39 | 2757 * In Visual block mode, handle copying the new text to all lines of the |
7 | 2758 * block. |
1477 | 2759 * Don't repeat the insert when Insert mode ended with CTRL-C. |
7 | 2760 */ |
1477 | 2761 if (oap->block_mode && oap->start.lnum != oap->end.lnum && !got_int) |
7 | 2762 { |
1392 | 2763 /* Auto-indenting may have changed the indent. If the cursor was past |
2764 * the indent, exclude that indent change from the inserted text. */ | |
7 | 2765 firstline = ml_get(oap->start.lnum); |
1403 | 2766 if (bd.textcol > (colnr_T)pre_indent) |
7 | 2767 { |
1392 | 2768 long new_indent = (long)(skipwhite(firstline) - firstline); |
2769 | |
2770 pre_textlen += new_indent - pre_indent; | |
2771 bd.textcol += new_indent - pre_indent; | |
2772 } | |
2773 | |
2774 ins_len = (long)STRLEN(firstline) - pre_textlen; | |
2775 if (ins_len > 0) | |
2776 { | |
2777 /* Subsequent calls to ml_get() flush the firstline data - take a | |
2778 * copy of the inserted text. */ | |
7 | 2779 if ((ins_text = alloc_check((unsigned)(ins_len + 1))) != NULL) |
2780 { | |
419 | 2781 vim_strncpy(ins_text, firstline + bd.textcol, (size_t)ins_len); |
7 | 2782 for (linenr = oap->start.lnum + 1; linenr <= oap->end.lnum; |
2783 linenr++) | |
2784 { | |
2785 block_prep(oap, &bd, linenr, TRUE); | |
2786 if (!bd.is_short || virtual_op) | |
2787 { | |
2788 # ifdef FEAT_VIRTUALEDIT | |
2789 pos_T vpos; | |
2790 | |
2791 /* If the block starts in virtual space, count the | |
2792 * initial coladd offset as part of "startspaces" */ | |
2793 if (bd.is_short) | |
2794 { | |
1982 | 2795 vpos.lnum = linenr; |
7 | 2796 (void)getvpos(&vpos, oap->start_vcol); |
2797 } | |
2798 else | |
2799 vpos.coladd = 0; | |
2800 # endif | |
2801 oldp = ml_get(linenr); | |
2802 newp = alloc_check((unsigned)(STRLEN(oldp) | |
2803 # ifdef FEAT_VIRTUALEDIT | |
2804 + vpos.coladd | |
2805 # endif | |
2806 + ins_len + 1)); | |
2807 if (newp == NULL) | |
2808 continue; | |
2809 /* copy up to block start */ | |
2810 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
2811 offset = bd.textcol; | |
2812 # ifdef FEAT_VIRTUALEDIT | |
6929 | 2813 vim_memset(newp + offset, ' ', (size_t)vpos.coladd); |
7 | 2814 offset += vpos.coladd; |
2815 # endif | |
2816 mch_memmove(newp + offset, ins_text, (size_t)ins_len); | |
2817 offset += ins_len; | |
2818 oldp += bd.textcol; | |
1622 | 2819 STRMOVE(newp + offset, oldp); |
7 | 2820 ml_replace(linenr, newp, FALSE); |
2821 } | |
2822 } | |
2823 check_cursor(); | |
2824 | |
2825 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); | |
2826 } | |
2827 vim_free(ins_text); | |
2828 } | |
2829 } | |
2830 #endif | |
2831 | |
2832 return retval; | |
2833 } | |
2834 | |
2835 /* | |
2836 * set all the yank registers to empty (called from main()) | |
2837 */ | |
2838 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2839 init_yank(void) |
7 | 2840 { |
2841 int i; | |
2842 | |
2843 for (i = 0; i < NUM_REGISTERS; ++i) | |
2844 y_regs[i].y_array = NULL; | |
2845 } | |
2846 | |
356 | 2847 #if defined(EXITFREE) || defined(PROTO) |
2848 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2849 clear_registers(void) |
356 | 2850 { |
2851 int i; | |
2852 | |
2853 for (i = 0; i < NUM_REGISTERS; ++i) | |
2854 { | |
2855 y_current = &y_regs[i]; | |
2856 if (y_current->y_array != NULL) | |
2857 free_yank_all(); | |
2858 } | |
2859 } | |
2860 #endif | |
2861 | |
7 | 2862 /* |
2863 * Free "n" lines from the current yank register. | |
2864 * Called for normal freeing and in case of error. | |
2865 */ | |
2866 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2867 free_yank(long n) |
7 | 2868 { |
2869 if (y_current->y_array != NULL) | |
2870 { | |
2871 long i; | |
2872 | |
2873 for (i = n; --i >= 0; ) | |
2874 { | |
2875 #ifdef AMIGA /* only for very slow machines */ | |
2876 if ((i & 1023) == 1023) /* this may take a while */ | |
2877 { | |
2878 /* | |
2879 * This message should never cause a hit-return message. | |
2880 * Overwrite this message with any next message. | |
2881 */ | |
2882 ++no_wait_return; | |
2883 smsg((char_u *)_("freeing %ld lines"), i + 1); | |
2884 --no_wait_return; | |
2885 msg_didout = FALSE; | |
2886 msg_col = 0; | |
2887 } | |
2888 #endif | |
2889 vim_free(y_current->y_array[i]); | |
2890 } | |
2891 vim_free(y_current->y_array); | |
2892 y_current->y_array = NULL; | |
2893 #ifdef AMIGA | |
2894 if (n >= 1000) | |
2895 MSG(""); | |
2896 #endif | |
2897 } | |
2898 } | |
2899 | |
2900 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2901 free_yank_all(void) |
7 | 2902 { |
2903 free_yank(y_current->y_size); | |
2904 } | |
2905 | |
2906 /* | |
2907 * Yank the text between "oap->start" and "oap->end" into a yank register. | |
2908 * If we are to append (uppercase register), we first yank into a new yank | |
2909 * register and then concatenate the old and the new one (so we keep the old | |
2910 * one in case of out-of-memory). | |
2911 * | |
5245
8c6615a30951
updated for version 7.4a.047
Bram Moolenaar <bram@vim.org>
parents:
5182
diff
changeset
|
2912 * Return FAIL for failure, OK otherwise. |
7 | 2913 */ |
2914 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2915 op_yank(oparg_T *oap, int deleting, int mess) |
7 | 2916 { |
2917 long y_idx; /* index in y_array[] */ | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
2918 yankreg_T *curr; /* copy of y_current */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
2919 yankreg_T newreg; /* new yank register when appending */ |
7 | 2920 char_u **new_ptr; |
2921 linenr_T lnum; /* current line number */ | |
2922 long j; | |
2923 int yanktype = oap->motion_type; | |
2924 long yanklines = oap->line_count; | |
2925 linenr_T yankendlnum = oap->end.lnum; | |
2926 char_u *p; | |
2927 char_u *pnew; | |
2928 struct block_def bd; | |
2658 | 2929 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
2654 | 2930 int did_star = FALSE; |
2658 | 2931 #endif |
7 | 2932 |
2933 /* check for read-only register */ | |
2934 if (oap->regname != 0 && !valid_yank_reg(oap->regname, TRUE)) | |
2935 { | |
2936 beep_flush(); | |
2937 return FAIL; | |
2938 } | |
2939 if (oap->regname == '_') /* black hole: nothing to do */ | |
2940 return OK; | |
2941 | |
2942 #ifdef FEAT_CLIPBOARD | |
2943 if (!clip_star.available && oap->regname == '*') | |
2944 oap->regname = 0; | |
2945 else if (!clip_plus.available && oap->regname == '+') | |
2946 oap->regname = 0; | |
2947 #endif | |
2948 | |
2949 if (!deleting) /* op_delete() already set y_current */ | |
2950 get_yank_register(oap->regname, TRUE); | |
2951 | |
2952 curr = y_current; | |
2953 /* append to existing contents */ | |
2954 if (y_append && y_current->y_array != NULL) | |
2955 y_current = &newreg; | |
2956 else | |
2957 free_yank_all(); /* free previously yanked lines */ | |
2958 | |
593 | 2959 /* |
2960 * If the cursor was in column 1 before and after the movement, and the | |
2961 * operator is not inclusive, the yank is always linewise. | |
2962 */ | |
7 | 2963 if ( oap->motion_type == MCHAR |
2964 && oap->start.col == 0 | |
2965 && !oap->inclusive | |
2966 && (!oap->is_VIsual || *p_sel == 'o') | |
50 | 2967 && !oap->block_mode |
7 | 2968 && oap->end.col == 0 |
2969 && yanklines > 1) | |
2970 { | |
2971 yanktype = MLINE; | |
2972 --yankendlnum; | |
2973 --yanklines; | |
2974 } | |
2975 | |
2976 y_current->y_size = yanklines; | |
2977 y_current->y_type = yanktype; /* set the yank register type */ | |
2978 y_current->y_width = 0; | |
2979 y_current->y_array = (char_u **)lalloc_clear((long_u)(sizeof(char_u *) * | |
2980 yanklines), TRUE); | |
2981 if (y_current->y_array == NULL) | |
2982 { | |
2983 y_current = curr; | |
2984 return FAIL; | |
2985 } | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
2986 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
2987 y_current->y_time_set = vim_time(); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
2988 #endif |
7 | 2989 |
2990 y_idx = 0; | |
2991 lnum = oap->start.lnum; | |
2992 | |
2993 if (oap->block_mode) | |
2994 { | |
2995 /* Visual block mode */ | |
2996 y_current->y_type = MBLOCK; /* set the yank register type */ | |
2997 y_current->y_width = oap->end_vcol - oap->start_vcol; | |
2998 | |
2999 if (curwin->w_curswant == MAXCOL && y_current->y_width > 0) | |
3000 y_current->y_width--; | |
3001 } | |
3002 | |
3003 for ( ; lnum <= yankendlnum; lnum++, y_idx++) | |
3004 { | |
3005 switch (y_current->y_type) | |
3006 { | |
3007 case MBLOCK: | |
3008 block_prep(oap, &bd, lnum, FALSE); | |
3009 if (yank_copy_line(&bd, y_idx) == FAIL) | |
3010 goto fail; | |
3011 break; | |
3012 | |
3013 case MLINE: | |
3014 if ((y_current->y_array[y_idx] = | |
3015 vim_strsave(ml_get(lnum))) == NULL) | |
3016 goto fail; | |
3017 break; | |
3018 | |
3019 case MCHAR: | |
3020 { | |
3021 colnr_T startcol = 0, endcol = MAXCOL; | |
3022 #ifdef FEAT_VIRTUALEDIT | |
3023 int is_oneChar = FALSE; | |
3024 colnr_T cs, ce; | |
3025 #endif | |
3026 p = ml_get(lnum); | |
3027 bd.startspaces = 0; | |
3028 bd.endspaces = 0; | |
3029 | |
3030 if (lnum == oap->start.lnum) | |
3031 { | |
3032 startcol = oap->start.col; | |
3033 #ifdef FEAT_VIRTUALEDIT | |
3034 if (virtual_op) | |
3035 { | |
3036 getvcol(curwin, &oap->start, &cs, NULL, &ce); | |
3037 if (ce != cs && oap->start.coladd > 0) | |
3038 { | |
3039 /* Part of a tab selected -- but don't | |
3040 * double-count it. */ | |
3041 bd.startspaces = (ce - cs + 1) | |
3042 - oap->start.coladd; | |
3043 startcol++; | |
3044 } | |
3045 } | |
3046 #endif | |
3047 } | |
3048 | |
3049 if (lnum == oap->end.lnum) | |
3050 { | |
3051 endcol = oap->end.col; | |
3052 #ifdef FEAT_VIRTUALEDIT | |
3053 if (virtual_op) | |
3054 { | |
3055 getvcol(curwin, &oap->end, &cs, NULL, &ce); | |
3056 if (p[endcol] == NUL || (cs + oap->end.coladd < ce | |
3057 # ifdef FEAT_MBYTE | |
3058 /* Don't add space for double-wide | |
3059 * char; endcol will be on last byte | |
3060 * of multi-byte char. */ | |
3061 && (*mb_head_off)(p, p + endcol) == 0 | |
3062 # endif | |
3063 )) | |
3064 { | |
3065 if (oap->start.lnum == oap->end.lnum | |
3066 && oap->start.col == oap->end.col) | |
3067 { | |
3068 /* Special case: inside a single char */ | |
3069 is_oneChar = TRUE; | |
3070 bd.startspaces = oap->end.coladd | |
3071 - oap->start.coladd + oap->inclusive; | |
3072 endcol = startcol; | |
3073 } | |
3074 else | |
3075 { | |
3076 bd.endspaces = oap->end.coladd | |
3077 + oap->inclusive; | |
3078 endcol -= oap->inclusive; | |
3079 } | |
3080 } | |
3081 } | |
3082 #endif | |
3083 } | |
3510 | 3084 if (endcol == MAXCOL) |
3085 endcol = (colnr_T)STRLEN(p); | |
7 | 3086 if (startcol > endcol |
3087 #ifdef FEAT_VIRTUALEDIT | |
3088 || is_oneChar | |
3089 #endif | |
3090 ) | |
3091 bd.textlen = 0; | |
3092 else | |
3093 { | |
3094 bd.textlen = endcol - startcol + oap->inclusive; | |
3095 } | |
3096 bd.textstart = p + startcol; | |
3097 if (yank_copy_line(&bd, y_idx) == FAIL) | |
3098 goto fail; | |
3099 break; | |
3100 } | |
3101 /* NOTREACHED */ | |
3102 } | |
3103 } | |
3104 | |
3105 if (curr != y_current) /* append the new block to the old block */ | |
3106 { | |
3107 new_ptr = (char_u **)lalloc((long_u)(sizeof(char_u *) * | |
3108 (curr->y_size + y_current->y_size)), TRUE); | |
3109 if (new_ptr == NULL) | |
3110 goto fail; | |
3111 for (j = 0; j < curr->y_size; ++j) | |
3112 new_ptr[j] = curr->y_array[j]; | |
3113 vim_free(curr->y_array); | |
3114 curr->y_array = new_ptr; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3115 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3116 curr->y_time_set = vim_time(); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3117 #endif |
7 | 3118 |
3119 if (yanktype == MLINE) /* MLINE overrides MCHAR and MBLOCK */ | |
3120 curr->y_type = MLINE; | |
3121 | |
164 | 3122 /* Concatenate the last line of the old block with the first line of |
3123 * the new block, unless being Vi compatible. */ | |
3124 if (curr->y_type == MCHAR && vim_strchr(p_cpo, CPO_REGAPPEND) == NULL) | |
7 | 3125 { |
3126 pnew = lalloc((long_u)(STRLEN(curr->y_array[curr->y_size - 1]) | |
3127 + STRLEN(y_current->y_array[0]) + 1), TRUE); | |
3128 if (pnew == NULL) | |
3129 { | |
3130 y_idx = y_current->y_size - 1; | |
3131 goto fail; | |
3132 } | |
3133 STRCPY(pnew, curr->y_array[--j]); | |
3134 STRCAT(pnew, y_current->y_array[0]); | |
3135 vim_free(curr->y_array[j]); | |
3136 vim_free(y_current->y_array[0]); | |
3137 curr->y_array[j++] = pnew; | |
3138 y_idx = 1; | |
3139 } | |
3140 else | |
3141 y_idx = 0; | |
3142 while (y_idx < y_current->y_size) | |
3143 curr->y_array[j++] = y_current->y_array[y_idx++]; | |
3144 curr->y_size = j; | |
3145 vim_free(y_current->y_array); | |
3146 y_current = curr; | |
3147 } | |
5981 | 3148 if (curwin->w_p_rnu) |
3149 redraw_later(SOME_VALID); /* cursor moved to start */ | |
7 | 3150 if (mess) /* Display message about yank? */ |
3151 { | |
3152 if (yanktype == MCHAR | |
3153 && !oap->block_mode | |
3154 && yanklines == 1) | |
3155 yanklines = 0; | |
3156 /* Some versions of Vi use ">=" here, some don't... */ | |
3157 if (yanklines > p_report) | |
3158 { | |
3159 /* redisplay now, so message is not deleted */ | |
3160 update_topline_redraw(); | |
3161 if (yanklines == 1) | |
205 | 3162 { |
3163 if (oap->block_mode) | |
3164 MSG(_("block of 1 line yanked")); | |
3165 else | |
3166 MSG(_("1 line yanked")); | |
3167 } | |
3168 else if (oap->block_mode) | |
3169 smsg((char_u *)_("block of %ld lines yanked"), yanklines); | |
7 | 3170 else |
3171 smsg((char_u *)_("%ld lines yanked"), yanklines); | |
3172 } | |
3173 } | |
3174 | |
3175 /* | |
3176 * Set "'[" and "']" marks. | |
3177 */ | |
3178 curbuf->b_op_start = oap->start; | |
3179 curbuf->b_op_end = oap->end; | |
5735 | 3180 if (yanktype == MLINE && !oap->block_mode) |
36 | 3181 { |
3182 curbuf->b_op_start.col = 0; | |
3183 curbuf->b_op_end.col = MAXCOL; | |
3184 } | |
7 | 3185 |
3186 #ifdef FEAT_CLIPBOARD | |
3187 /* | |
3188 * If we were yanking to the '*' register, send result to clipboard. | |
3189 * If no register was specified, and "unnamed" in 'clipboard', make a copy | |
3190 * to the '*' register. | |
3191 */ | |
3192 if (clip_star.available | |
3193 && (curr == &(y_regs[STAR_REGISTER]) | |
2654 | 3194 || (!deleting && oap->regname == 0 |
6116 | 3195 && ((clip_unnamed | clip_unnamed_saved) & CLIP_UNNAMED)))) |
7 | 3196 { |
3197 if (curr != &(y_regs[STAR_REGISTER])) | |
3198 /* Copy the text from register 0 to the clipboard register. */ | |
3199 copy_yank_reg(&(y_regs[STAR_REGISTER])); | |
3200 | |
3201 clip_own_selection(&clip_star); | |
3202 clip_gen_set_selection(&clip_star); | |
2658 | 3203 # ifdef FEAT_X11 |
2654 | 3204 did_star = TRUE; |
2658 | 3205 # endif |
7 | 3206 } |
3207 | |
3208 # ifdef FEAT_X11 | |
3209 /* | |
3210 * If we were yanking to the '+' register, send result to selection. | |
3211 * Also copy to the '*' register, in case auto-select is off. | |
3212 */ | |
2654 | 3213 if (clip_plus.available |
3214 && (curr == &(y_regs[PLUS_REGISTER]) | |
3215 || (!deleting && oap->regname == 0 | |
6116 | 3216 && ((clip_unnamed | clip_unnamed_saved) & |
3217 CLIP_UNNAMED_PLUS)))) | |
7 | 3218 { |
2654 | 3219 if (curr != &(y_regs[PLUS_REGISTER])) |
3220 /* Copy the text from register 0 to the clipboard register. */ | |
3221 copy_yank_reg(&(y_regs[PLUS_REGISTER])); | |
3222 | |
7 | 3223 clip_own_selection(&clip_plus); |
3224 clip_gen_set_selection(&clip_plus); | |
3674 | 3225 if (!clip_isautosel_star() && !did_star |
3226 && curr == &(y_regs[PLUS_REGISTER])) | |
7 | 3227 { |
3228 copy_yank_reg(&(y_regs[STAR_REGISTER])); | |
3229 clip_own_selection(&clip_star); | |
3230 clip_gen_set_selection(&clip_star); | |
3231 } | |
3232 } | |
3233 # endif | |
3234 #endif | |
3235 | |
3236 return OK; | |
3237 | |
3238 fail: /* free the allocated lines */ | |
3239 free_yank(y_idx + 1); | |
3240 y_current = curr; | |
3241 return FAIL; | |
3242 } | |
3243 | |
3244 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3245 yank_copy_line(struct block_def *bd, long y_idx) |
7 | 3246 { |
3247 char_u *pnew; | |
3248 | |
3249 if ((pnew = alloc(bd->startspaces + bd->endspaces + bd->textlen + 1)) | |
3250 == NULL) | |
3251 return FAIL; | |
3252 y_current->y_array[y_idx] = pnew; | |
6929 | 3253 vim_memset(pnew, ' ', (size_t)bd->startspaces); |
7 | 3254 pnew += bd->startspaces; |
3255 mch_memmove(pnew, bd->textstart, (size_t)bd->textlen); | |
3256 pnew += bd->textlen; | |
6929 | 3257 vim_memset(pnew, ' ', (size_t)bd->endspaces); |
7 | 3258 pnew += bd->endspaces; |
3259 *pnew = NUL; | |
3260 return OK; | |
3261 } | |
3262 | |
3263 #ifdef FEAT_CLIPBOARD | |
3264 /* | |
3265 * Make a copy of the y_current register to register "reg". | |
3266 */ | |
3267 static void | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3268 copy_yank_reg(yankreg_T *reg) |
7 | 3269 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3270 yankreg_T *curr = y_current; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3271 long j; |
7 | 3272 |
3273 y_current = reg; | |
3274 free_yank_all(); | |
3275 *y_current = *curr; | |
3276 y_current->y_array = (char_u **)lalloc_clear( | |
3277 (long_u)(sizeof(char_u *) * y_current->y_size), TRUE); | |
3278 if (y_current->y_array == NULL) | |
3279 y_current->y_size = 0; | |
3280 else | |
3281 for (j = 0; j < y_current->y_size; ++j) | |
3282 if ((y_current->y_array[j] = vim_strsave(curr->y_array[j])) == NULL) | |
3283 { | |
3284 free_yank(j); | |
3285 y_current->y_size = 0; | |
3286 break; | |
3287 } | |
3288 y_current = curr; | |
3289 } | |
3290 #endif | |
3291 | |
3292 /* | |
140 | 3293 * Put contents of register "regname" into the text. |
3294 * Caller must check "regname" to be valid! | |
3295 * "flags": PUT_FIXINDENT make indent look nice | |
3296 * PUT_CURSEND leave cursor after end of new text | |
3297 * PUT_LINE force linewise put (":put") | |
7 | 3298 */ |
3299 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3300 do_put( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3301 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3302 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
|
3303 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3304 int flags) |
7 | 3305 { |
3306 char_u *ptr; | |
3307 char_u *newp, *oldp; | |
3308 int yanklen; | |
3309 int totlen = 0; /* init for gcc */ | |
3310 linenr_T lnum; | |
3311 colnr_T col; | |
3312 long i; /* index in y_array[] */ | |
3313 int y_type; | |
3314 long y_size; | |
3315 int oldlen; | |
3316 long y_width = 0; | |
3317 colnr_T vcol; | |
3318 int delcount; | |
3319 int incr = 0; | |
3320 long j; | |
3321 struct block_def bd; | |
3322 char_u **y_array = NULL; | |
3323 long nr_lines = 0; | |
3324 pos_T new_cursor; | |
3325 int indent; | |
3326 int orig_indent = 0; /* init for gcc */ | |
3327 int indent_diff = 0; /* init for gcc */ | |
3328 int first_indent = TRUE; | |
3329 int lendiff = 0; | |
3330 pos_T old_pos; | |
3331 char_u *insert_string = NULL; | |
3332 int allocated = FALSE; | |
3333 long cnt; | |
3334 | |
3335 #ifdef FEAT_CLIPBOARD | |
3336 /* Adjust register name for "unnamed" in 'clipboard'. */ | |
3337 adjust_clip_reg(®name); | |
3338 (void)may_get_selection(regname); | |
3339 #endif | |
3340 | |
3341 if (flags & PUT_FIXINDENT) | |
3342 orig_indent = get_indent(); | |
3343 | |
3344 curbuf->b_op_start = curwin->w_cursor; /* default for '[ mark */ | |
3345 curbuf->b_op_end = curwin->w_cursor; /* default for '] mark */ | |
3346 | |
3347 /* | |
3348 * Using inserted text works differently, because the register includes | |
3349 * special characters (newlines, etc.). | |
3350 */ | |
3351 if (regname == '.') | |
3352 { | |
3353 (void)stuff_inserted((dir == FORWARD ? (count == -1 ? 'o' : 'a') : | |
3354 (count == -1 ? 'O' : 'i')), count, FALSE); | |
3355 /* Putting the text is done later, so can't really move the cursor to | |
3356 * the next character. Use "l" to simulate it. */ | |
3357 if ((flags & PUT_CURSEND) && gchar_cursor() != NUL) | |
3358 stuffcharReadbuff('l'); | |
3359 return; | |
3360 } | |
3361 | |
3362 /* | |
3363 * For special registers '%' (file name), '#' (alternate file name) and | |
3364 * ':' (last command line), etc. we have to create a fake yank register. | |
3365 */ | |
3366 if (get_spec_reg(regname, &insert_string, &allocated, TRUE)) | |
3367 { | |
3368 if (insert_string == NULL) | |
3369 return; | |
3370 } | |
3371 | |
4005 | 3372 #ifdef FEAT_AUTOCMD |
3373 /* Autocommands may be executed when saving lines for undo, which may make | |
3374 * y_array invalid. Start undo now to avoid that. */ | |
3375 u_save(curwin->w_cursor.lnum, curwin->w_cursor.lnum + 1); | |
3376 #endif | |
3377 | |
7 | 3378 if (insert_string != NULL) |
3379 { | |
3380 y_type = MCHAR; | |
3381 #ifdef FEAT_EVAL | |
3382 if (regname == '=') | |
3383 { | |
3384 /* For the = register we need to split the string at NL | |
3093 | 3385 * characters. |
3386 * Loop twice: count the number of lines and save them. */ | |
7 | 3387 for (;;) |
3388 { | |
3389 y_size = 0; | |
3390 ptr = insert_string; | |
3391 while (ptr != NULL) | |
3392 { | |
3393 if (y_array != NULL) | |
3394 y_array[y_size] = ptr; | |
3395 ++y_size; | |
3396 ptr = vim_strchr(ptr, '\n'); | |
3397 if (ptr != NULL) | |
3398 { | |
3399 if (y_array != NULL) | |
3400 *ptr = NUL; | |
3401 ++ptr; | |
3093 | 3402 /* A trailing '\n' makes the register linewise. */ |
7 | 3403 if (*ptr == NUL) |
3404 { | |
3405 y_type = MLINE; | |
3406 break; | |
3407 } | |
3408 } | |
3409 } | |
3410 if (y_array != NULL) | |
3411 break; | |
3412 y_array = (char_u **)alloc((unsigned) | |
3413 (y_size * sizeof(char_u *))); | |
3414 if (y_array == NULL) | |
3415 goto end; | |
3416 } | |
3417 } | |
3418 else | |
3419 #endif | |
3420 { | |
3421 y_size = 1; /* use fake one-line yank register */ | |
3422 y_array = &insert_string; | |
3423 } | |
3424 } | |
3425 else | |
3426 { | |
3427 get_yank_register(regname, FALSE); | |
3428 | |
3429 y_type = y_current->y_type; | |
3430 y_width = y_current->y_width; | |
3431 y_size = y_current->y_size; | |
3432 y_array = y_current->y_array; | |
3433 } | |
3434 | |
3435 if (y_type == MLINE) | |
3436 { | |
3437 if (flags & PUT_LINE_SPLIT) | |
3438 { | |
6845 | 3439 char_u *p; |
3440 | |
7 | 3441 /* "p" or "P" in Visual mode: split the lines to put the text in |
3442 * between. */ | |
3443 if (u_save_cursor() == FAIL) | |
3444 goto end; | |
6845 | 3445 p = ml_get_cursor(); |
3446 if (dir == FORWARD && *p != NUL) | |
3447 mb_ptr_adv(p); | |
3448 ptr = vim_strsave(p); | |
7 | 3449 if (ptr == NULL) |
3450 goto end; | |
3451 ml_append(curwin->w_cursor.lnum, ptr, (colnr_T)0, FALSE); | |
3452 vim_free(ptr); | |
3453 | |
6845 | 3454 oldp = ml_get_curline(); |
3455 p = oldp + curwin->w_cursor.col; | |
3456 if (dir == FORWARD && *p != NUL) | |
3457 mb_ptr_adv(p); | |
3458 ptr = vim_strnsave(oldp, p - oldp); | |
7 | 3459 if (ptr == NULL) |
3460 goto end; | |
3461 ml_replace(curwin->w_cursor.lnum, ptr, FALSE); | |
3462 ++nr_lines; | |
3463 dir = FORWARD; | |
3464 } | |
3465 if (flags & PUT_LINE_FORWARD) | |
3466 { | |
3467 /* Must be "p" for a Visual block, put lines below the block. */ | |
692 | 3468 curwin->w_cursor = curbuf->b_visual.vi_end; |
7 | 3469 dir = FORWARD; |
3470 } | |
3471 curbuf->b_op_start = curwin->w_cursor; /* default for '[ mark */ | |
3472 curbuf->b_op_end = curwin->w_cursor; /* default for '] mark */ | |
3473 } | |
3474 | |
3475 if (flags & PUT_LINE) /* :put command or "p" in Visual line mode. */ | |
3476 y_type = MLINE; | |
3477 | |
3478 if (y_size == 0 || y_array == NULL) | |
3479 { | |
3480 EMSG2(_("E353: Nothing in register %s"), | |
3481 regname == 0 ? (char_u *)"\"" : transchar(regname)); | |
3482 goto end; | |
3483 } | |
3484 | |
3485 if (y_type == MBLOCK) | |
3486 { | |
3487 lnum = curwin->w_cursor.lnum + y_size + 1; | |
3488 if (lnum > curbuf->b_ml.ml_line_count) | |
3489 lnum = curbuf->b_ml.ml_line_count + 1; | |
3490 if (u_save(curwin->w_cursor.lnum - 1, lnum) == FAIL) | |
3491 goto end; | |
3492 } | |
5735 | 3493 else if (y_type == MLINE) |
7 | 3494 { |
3495 lnum = curwin->w_cursor.lnum; | |
3496 #ifdef FEAT_FOLDING | |
3497 /* Correct line number for closed fold. Don't move the cursor yet, | |
3498 * u_save() uses it. */ | |
3499 if (dir == BACKWARD) | |
3500 (void)hasFolding(lnum, &lnum, NULL); | |
3501 else | |
3502 (void)hasFolding(lnum, NULL, &lnum); | |
3503 #endif | |
3504 if (dir == FORWARD) | |
3505 ++lnum; | |
5053
35b6fc57a286
updated for version 7.3.1270
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3506 /* 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
|
3507 * it in the saved lines. */ |
5100
18b43970fb7a
updated for version 7.3.1293
Bram Moolenaar <bram@vim.org>
parents:
5053
diff
changeset
|
3508 if ((bufempty() ? u_save(0, 2) : u_save(lnum - 1, lnum)) == FAIL) |
7 | 3509 goto end; |
3510 #ifdef FEAT_FOLDING | |
3511 if (dir == FORWARD) | |
3512 curwin->w_cursor.lnum = lnum - 1; | |
3513 else | |
3514 curwin->w_cursor.lnum = lnum; | |
3515 curbuf->b_op_start = curwin->w_cursor; /* for mark_adjust() */ | |
3516 #endif | |
3517 } | |
3518 else if (u_save_cursor() == FAIL) | |
3519 goto end; | |
3520 | |
3521 yanklen = (int)STRLEN(y_array[0]); | |
3522 | |
3523 #ifdef FEAT_VIRTUALEDIT | |
3524 if (ve_flags == VE_ALL && y_type == MCHAR) | |
3525 { | |
3526 if (gchar_cursor() == TAB) | |
3527 { | |
3528 /* Don't need to insert spaces when "p" on the last position of a | |
3529 * tab or "P" on the first position. */ | |
3530 if (dir == FORWARD | |
3531 ? (int)curwin->w_cursor.coladd < curbuf->b_p_ts - 1 | |
3532 : curwin->w_cursor.coladd > 0) | |
3533 coladvance_force(getviscol()); | |
3534 else | |
3535 curwin->w_cursor.coladd = 0; | |
3536 } | |
3537 else if (curwin->w_cursor.coladd > 0 || gchar_cursor() == NUL) | |
3538 coladvance_force(getviscol() + (dir == FORWARD)); | |
3539 } | |
3540 #endif | |
3541 | |
3542 lnum = curwin->w_cursor.lnum; | |
3543 col = curwin->w_cursor.col; | |
3544 | |
3545 /* | |
3546 * Block mode | |
3547 */ | |
3548 if (y_type == MBLOCK) | |
3549 { | |
3550 char c = gchar_cursor(); | |
3551 colnr_T endcol2 = 0; | |
3552 | |
3553 if (dir == FORWARD && c != NUL) | |
3554 { | |
3555 #ifdef FEAT_VIRTUALEDIT | |
3556 if (ve_flags == VE_ALL) | |
3557 getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2); | |
3558 else | |
3559 #endif | |
3560 getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col); | |
3561 | |
3562 #ifdef FEAT_MBYTE | |
3563 if (has_mbyte) | |
3564 /* move to start of next multi-byte character */ | |
474 | 3565 curwin->w_cursor.col += (*mb_ptr2len)(ml_get_cursor()); |
7 | 3566 else |
3567 #endif | |
3568 #ifdef FEAT_VIRTUALEDIT | |
3569 if (c != TAB || ve_flags != VE_ALL) | |
3570 #endif | |
3571 ++curwin->w_cursor.col; | |
3572 ++col; | |
3573 } | |
3574 else | |
3575 getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2); | |
3576 | |
3577 #ifdef FEAT_VIRTUALEDIT | |
3578 col += curwin->w_cursor.coladd; | |
1304 | 3579 if (ve_flags == VE_ALL |
3580 && (curwin->w_cursor.coladd > 0 | |
3581 || endcol2 == curwin->w_cursor.col)) | |
7 | 3582 { |
3583 if (dir == FORWARD && c == NUL) | |
3584 ++col; | |
3585 if (dir != FORWARD && c != NUL) | |
3586 ++curwin->w_cursor.col; | |
3587 if (c == TAB) | |
3588 { | |
3589 if (dir == BACKWARD && curwin->w_cursor.col) | |
3590 curwin->w_cursor.col--; | |
3591 if (dir == FORWARD && col - 1 == endcol2) | |
3592 curwin->w_cursor.col++; | |
3593 } | |
3594 } | |
3595 curwin->w_cursor.coladd = 0; | |
3596 #endif | |
699 | 3597 bd.textcol = 0; |
7 | 3598 for (i = 0; i < y_size; ++i) |
3599 { | |
3600 int spaces; | |
3601 char shortline; | |
3602 | |
3603 bd.startspaces = 0; | |
3604 bd.endspaces = 0; | |
3605 vcol = 0; | |
3606 delcount = 0; | |
3607 | |
3608 /* add a new line */ | |
3609 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
3610 { | |
3611 if (ml_append(curbuf->b_ml.ml_line_count, (char_u *)"", | |
3612 (colnr_T)1, FALSE) == FAIL) | |
3613 break; | |
3614 ++nr_lines; | |
3615 } | |
3616 /* get the old line and advance to the position to insert at */ | |
3617 oldp = ml_get_curline(); | |
3618 oldlen = (int)STRLEN(oldp); | |
3619 for (ptr = oldp; vcol < col && *ptr; ) | |
3620 { | |
3621 /* Count a tab for what it's worth (if list mode not on) */ | |
5995 | 3622 incr = lbr_chartabsize_adv(oldp, &ptr, (colnr_T)vcol); |
7 | 3623 vcol += incr; |
3624 } | |
3625 bd.textcol = (colnr_T)(ptr - oldp); | |
3626 | |
3627 shortline = (vcol < col) || (vcol == col && !*ptr) ; | |
3628 | |
3629 if (vcol < col) /* line too short, padd with spaces */ | |
3630 bd.startspaces = col - vcol; | |
3631 else if (vcol > col) | |
3632 { | |
3633 bd.endspaces = vcol - col; | |
3634 bd.startspaces = incr - bd.endspaces; | |
3635 --bd.textcol; | |
3636 delcount = 1; | |
3637 #ifdef FEAT_MBYTE | |
3638 if (has_mbyte) | |
3639 bd.textcol -= (*mb_head_off)(oldp, oldp + bd.textcol); | |
3640 #endif | |
3641 if (oldp[bd.textcol] != TAB) | |
3642 { | |
3643 /* Only a Tab can be split into spaces. Other | |
3644 * characters will have to be moved to after the | |
3645 * block, causing misalignment. */ | |
3646 delcount = 0; | |
3647 bd.endspaces = 0; | |
3648 } | |
3649 } | |
3650 | |
3651 yanklen = (int)STRLEN(y_array[i]); | |
3652 | |
3653 /* calculate number of spaces required to fill right side of block*/ | |
3654 spaces = y_width + 1; | |
3655 for (j = 0; j < yanklen; j++) | |
5995 | 3656 spaces -= lbr_chartabsize(NULL, &y_array[i][j], 0); |
7 | 3657 if (spaces < 0) |
3658 spaces = 0; | |
3659 | |
3660 /* insert the new text */ | |
3661 totlen = count * (yanklen + spaces) + bd.startspaces + bd.endspaces; | |
3662 newp = alloc_check((unsigned)totlen + oldlen + 1); | |
3663 if (newp == NULL) | |
3664 break; | |
3665 /* copy part up to cursor to new line */ | |
3666 ptr = newp; | |
3667 mch_memmove(ptr, oldp, (size_t)bd.textcol); | |
3668 ptr += bd.textcol; | |
3669 /* may insert some spaces before the new text */ | |
6929 | 3670 vim_memset(ptr, ' ', (size_t)bd.startspaces); |
7 | 3671 ptr += bd.startspaces; |
3672 /* insert the new text */ | |
3673 for (j = 0; j < count; ++j) | |
3674 { | |
3675 mch_memmove(ptr, y_array[i], (size_t)yanklen); | |
3676 ptr += yanklen; | |
3677 | |
3678 /* insert block's trailing spaces only if there's text behind */ | |
3679 if ((j < count - 1 || !shortline) && spaces) | |
3680 { | |
6929 | 3681 vim_memset(ptr, ' ', (size_t)spaces); |
7 | 3682 ptr += spaces; |
3683 } | |
3684 } | |
3685 /* may insert some spaces after the new text */ | |
6929 | 3686 vim_memset(ptr, ' ', (size_t)bd.endspaces); |
7 | 3687 ptr += bd.endspaces; |
3688 /* move the text after the cursor to the end of the line. */ | |
3689 mch_memmove(ptr, oldp + bd.textcol + delcount, | |
3690 (size_t)(oldlen - bd.textcol - delcount + 1)); | |
3691 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
3692 | |
3693 ++curwin->w_cursor.lnum; | |
3694 if (i == 0) | |
3695 curwin->w_cursor.col += bd.startspaces; | |
3696 } | |
3697 | |
3698 changed_lines(lnum, 0, curwin->w_cursor.lnum, nr_lines); | |
3699 | |
3700 /* Set '[ mark. */ | |
3701 curbuf->b_op_start = curwin->w_cursor; | |
3702 curbuf->b_op_start.lnum = lnum; | |
3703 | |
3704 /* adjust '] mark */ | |
3705 curbuf->b_op_end.lnum = curwin->w_cursor.lnum - 1; | |
3706 curbuf->b_op_end.col = bd.textcol + totlen - 1; | |
237 | 3707 # ifdef FEAT_VIRTUALEDIT |
7 | 3708 curbuf->b_op_end.coladd = 0; |
237 | 3709 # endif |
7 | 3710 if (flags & PUT_CURSEND) |
3711 { | |
916 | 3712 colnr_T len; |
3713 | |
7 | 3714 curwin->w_cursor = curbuf->b_op_end; |
3715 curwin->w_cursor.col++; | |
916 | 3716 |
3717 /* in Insert mode we might be after the NUL, correct for that */ | |
3718 len = (colnr_T)STRLEN(ml_get_curline()); | |
3719 if (curwin->w_cursor.col > len) | |
3720 curwin->w_cursor.col = len; | |
7 | 3721 } |
3722 else | |
3723 curwin->w_cursor.lnum = lnum; | |
3724 } | |
3725 else | |
3726 { | |
3727 /* | |
3728 * Character or Line mode | |
3729 */ | |
3730 if (y_type == MCHAR) | |
3731 { | |
3732 /* if type is MCHAR, FORWARD is the same as BACKWARD on the next | |
3733 * char */ | |
3734 if (dir == FORWARD && gchar_cursor() != NUL) | |
3735 { | |
3736 #ifdef FEAT_MBYTE | |
3737 if (has_mbyte) | |
3738 { | |
474 | 3739 int bytelen = (*mb_ptr2len)(ml_get_cursor()); |
7 | 3740 |
3741 /* put it on the next of the multi-byte character. */ | |
3742 col += bytelen; | |
3743 if (yanklen) | |
3744 { | |
3745 curwin->w_cursor.col += bytelen; | |
3746 curbuf->b_op_end.col += bytelen; | |
3747 } | |
3748 } | |
3749 else | |
3750 #endif | |
3751 { | |
3752 ++col; | |
3753 if (yanklen) | |
3754 { | |
3755 ++curwin->w_cursor.col; | |
3756 ++curbuf->b_op_end.col; | |
3757 } | |
3758 } | |
3759 } | |
3760 curbuf->b_op_start = curwin->w_cursor; | |
3761 } | |
3762 /* | |
3763 * Line mode: BACKWARD is the same as FORWARD on the previous line | |
3764 */ | |
3765 else if (dir == BACKWARD) | |
3766 --lnum; | |
699 | 3767 new_cursor = curwin->w_cursor; |
7 | 3768 |
3769 /* | |
3770 * simple case: insert into current line | |
3771 */ | |
3772 if (y_type == MCHAR && y_size == 1) | |
3773 { | |
5365 | 3774 do { |
3775 totlen = count * yanklen; | |
3776 if (totlen > 0) | |
7 | 3777 { |
5365 | 3778 oldp = ml_get(lnum); |
3779 newp = alloc_check((unsigned)(STRLEN(oldp) + totlen + 1)); | |
3780 if (newp == NULL) | |
3781 goto end; /* alloc() gave an error message */ | |
3782 mch_memmove(newp, oldp, (size_t)col); | |
3783 ptr = newp + col; | |
3784 for (i = 0; i < count; ++i) | |
3785 { | |
3786 mch_memmove(ptr, y_array[0], (size_t)yanklen); | |
3787 ptr += yanklen; | |
3788 } | |
3789 STRMOVE(ptr, oldp + col); | |
3790 ml_replace(lnum, newp, FALSE); | |
3791 /* Place cursor on last putted char. */ | |
3792 if (lnum == curwin->w_cursor.lnum) | |
5496 | 3793 { |
3794 /* make sure curwin->w_virtcol is updated */ | |
3795 changed_cline_bef_curs(); | |
5365 | 3796 curwin->w_cursor.col += (colnr_T)(totlen - 1); |
5496 | 3797 } |
7 | 3798 } |
5365 | 3799 if (VIsual_active) |
3800 lnum++; | |
5735 | 3801 } while (VIsual_active && lnum <= curbuf->b_visual.vi_end.lnum); |
5365 | 3802 |
6379 | 3803 if (VIsual_active) /* reset lnum to the last visual line */ |
3804 lnum--; | |
3805 | |
7 | 3806 curbuf->b_op_end = curwin->w_cursor; |
3807 /* For "CTRL-O p" in Insert mode, put cursor after last char */ | |
3808 if (totlen && (restart_edit != 0 || (flags & PUT_CURSEND))) | |
3809 ++curwin->w_cursor.col; | |
3810 changed_bytes(lnum, col); | |
3811 } | |
3812 else | |
3813 { | |
3814 /* | |
3815 * Insert at least one line. When y_type is MCHAR, break the first | |
3816 * line in two. | |
3817 */ | |
3818 for (cnt = 1; cnt <= count; ++cnt) | |
3819 { | |
3820 i = 0; | |
3821 if (y_type == MCHAR) | |
3822 { | |
3823 /* | |
3824 * Split the current line in two at the insert position. | |
3825 * First insert y_array[size - 1] in front of second line. | |
3826 * Then append y_array[0] to first line. | |
3827 */ | |
3828 lnum = new_cursor.lnum; | |
3829 ptr = ml_get(lnum) + col; | |
3830 totlen = (int)STRLEN(y_array[y_size - 1]); | |
3831 newp = alloc_check((unsigned)(STRLEN(ptr) + totlen + 1)); | |
3832 if (newp == NULL) | |
3833 goto error; | |
3834 STRCPY(newp, y_array[y_size - 1]); | |
3835 STRCAT(newp, ptr); | |
3836 /* insert second line */ | |
3837 ml_append(lnum, newp, (colnr_T)0, FALSE); | |
3838 vim_free(newp); | |
3839 | |
3840 oldp = ml_get(lnum); | |
3841 newp = alloc_check((unsigned)(col + yanklen + 1)); | |
3842 if (newp == NULL) | |
3843 goto error; | |
3844 /* copy first part of line */ | |
3845 mch_memmove(newp, oldp, (size_t)col); | |
3846 /* append to first line */ | |
3847 mch_memmove(newp + col, y_array[0], (size_t)(yanklen + 1)); | |
3848 ml_replace(lnum, newp, FALSE); | |
3849 | |
3850 curwin->w_cursor.lnum = lnum; | |
3851 i = 1; | |
3852 } | |
3853 | |
3854 for (; i < y_size; ++i) | |
3855 { | |
3856 if ((y_type != MCHAR || i < y_size - 1) | |
3857 && ml_append(lnum, y_array[i], (colnr_T)0, FALSE) | |
3858 == FAIL) | |
3859 goto error; | |
3860 lnum++; | |
3861 ++nr_lines; | |
3862 if (flags & PUT_FIXINDENT) | |
3863 { | |
3864 old_pos = curwin->w_cursor; | |
3865 curwin->w_cursor.lnum = lnum; | |
3866 ptr = ml_get(lnum); | |
3867 if (cnt == count && i == y_size - 1) | |
3868 lendiff = (int)STRLEN(ptr); | |
3869 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) | |
3870 if (*ptr == '#' && preprocs_left()) | |
3871 indent = 0; /* Leave # lines at start */ | |
3872 else | |
3873 #endif | |
3874 if (*ptr == NUL) | |
3875 indent = 0; /* Ignore empty lines */ | |
3876 else if (first_indent) | |
3877 { | |
3878 indent_diff = orig_indent - get_indent(); | |
3879 indent = orig_indent; | |
3880 first_indent = FALSE; | |
3881 } | |
3882 else if ((indent = get_indent() + indent_diff) < 0) | |
3883 indent = 0; | |
3884 (void)set_indent(indent, 0); | |
3885 curwin->w_cursor = old_pos; | |
3886 /* remember how many chars were removed */ | |
3887 if (cnt == count && i == y_size - 1) | |
3888 lendiff -= (int)STRLEN(ml_get(lnum)); | |
3889 } | |
3890 } | |
3891 } | |
3892 | |
3893 error: | |
3894 /* Adjust marks. */ | |
3895 if (y_type == MLINE) | |
3896 { | |
3897 curbuf->b_op_start.col = 0; | |
3898 if (dir == FORWARD) | |
3899 curbuf->b_op_start.lnum++; | |
3900 } | |
9225
b0b2bd8e5217
commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents:
8989
diff
changeset
|
3901 /* Skip mark_adjust when adding lines after the last one, there |
b0b2bd8e5217
commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents:
8989
diff
changeset
|
3902 * can't be marks there. */ |
b0b2bd8e5217
commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents:
8989
diff
changeset
|
3903 if (curbuf->b_op_start.lnum + (y_type == MCHAR) - 1 + nr_lines |
b0b2bd8e5217
commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents:
8989
diff
changeset
|
3904 < curbuf->b_ml.ml_line_count) |
b0b2bd8e5217
commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents:
8989
diff
changeset
|
3905 mark_adjust(curbuf->b_op_start.lnum + (y_type == MCHAR), |
7 | 3906 (linenr_T)MAXLNUM, nr_lines, 0L); |
3907 | |
3908 /* note changed text for displaying and folding */ | |
3909 if (y_type == MCHAR) | |
3910 changed_lines(curwin->w_cursor.lnum, col, | |
3911 curwin->w_cursor.lnum + 1, nr_lines); | |
3912 else | |
3913 changed_lines(curbuf->b_op_start.lnum, 0, | |
3914 curbuf->b_op_start.lnum, nr_lines); | |
3915 | |
3916 /* put '] mark at last inserted character */ | |
3917 curbuf->b_op_end.lnum = lnum; | |
3918 /* correct length for change in indent */ | |
3919 col = (colnr_T)STRLEN(y_array[y_size - 1]) - lendiff; | |
3920 if (col > 1) | |
3921 curbuf->b_op_end.col = col - 1; | |
3922 else | |
3923 curbuf->b_op_end.col = 0; | |
3924 | |
168 | 3925 if (flags & PUT_CURSLINE) |
3926 { | |
237 | 3927 /* ":put": put cursor on last inserted line */ |
168 | 3928 curwin->w_cursor.lnum = lnum; |
3929 beginline(BL_WHITE | BL_FIX); | |
3930 } | |
3931 else if (flags & PUT_CURSEND) | |
7 | 3932 { |
3933 /* put cursor after inserted text */ | |
3934 if (y_type == MLINE) | |
3935 { | |
3936 if (lnum >= curbuf->b_ml.ml_line_count) | |
3937 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
3938 else | |
3939 curwin->w_cursor.lnum = lnum + 1; | |
3940 curwin->w_cursor.col = 0; | |
3941 } | |
3942 else | |
3943 { | |
3944 curwin->w_cursor.lnum = lnum; | |
3945 curwin->w_cursor.col = col; | |
3946 } | |
3947 } | |
3948 else if (y_type == MLINE) | |
3949 { | |
168 | 3950 /* put cursor on first non-blank in first inserted line */ |
7 | 3951 curwin->w_cursor.col = 0; |
3952 if (dir == FORWARD) | |
3953 ++curwin->w_cursor.lnum; | |
3954 beginline(BL_WHITE | BL_FIX); | |
3955 } | |
3956 else /* put cursor on first inserted character */ | |
3957 curwin->w_cursor = new_cursor; | |
3958 } | |
3959 } | |
3960 | |
3961 msgmore(nr_lines); | |
3962 curwin->w_set_curswant = TRUE; | |
3963 | |
3964 end: | |
3965 if (allocated) | |
3966 vim_free(insert_string); | |
840 | 3967 if (regname == '=') |
3968 vim_free(y_array); | |
3969 | |
5380 | 3970 VIsual_active = FALSE; |
3971 | |
140 | 3972 /* If the cursor is past the end of the line put it at the end. */ |
844 | 3973 adjust_cursor_eol(); |
3974 } | |
3975 | |
3976 /* | |
3977 * When the cursor is on the NUL past the end of the line and it should not be | |
3978 * there move it left. | |
3979 */ | |
3980 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3981 adjust_cursor_eol(void) |
844 | 3982 { |
3983 if (curwin->w_cursor.col > 0 | |
3984 && gchar_cursor() == NUL | |
773 | 3985 #ifdef FEAT_VIRTUALEDIT |
3986 && (ve_flags & VE_ONEMORE) == 0 | |
3987 #endif | |
7 | 3988 && !(restart_edit || (State & INSERT))) |
3989 { | |
557 | 3990 /* Put the cursor on the last character in the line. */ |
555 | 3991 dec_cursor(); |
844 | 3992 |
7 | 3993 #ifdef FEAT_VIRTUALEDIT |
3994 if (ve_flags == VE_ALL) | |
557 | 3995 { |
3996 colnr_T scol, ecol; | |
3997 | |
3998 /* Coladd is set to the width of the last character. */ | |
3999 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); | |
4000 curwin->w_cursor.coladd = ecol - scol + 1; | |
4001 } | |
7 | 4002 #endif |
4003 } | |
4004 } | |
4005 | |
4006 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) || defined(PROTO) | |
4007 /* | |
4008 * Return TRUE if lines starting with '#' should be left aligned. | |
4009 */ | |
4010 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4011 preprocs_left(void) |
7 | 4012 { |
4013 return | |
4014 # ifdef FEAT_SMARTINDENT | |
4015 # ifdef FEAT_CINDENT | |
4016 (curbuf->b_p_si && !curbuf->b_p_cin) || | |
4017 # else | |
4018 curbuf->b_p_si | |
4019 # endif | |
4020 # endif | |
4021 # ifdef FEAT_CINDENT | |
5438 | 4022 (curbuf->b_p_cin && in_cinkeys('#', ' ', TRUE) |
4023 && curbuf->b_ind_hash_comment == 0) | |
7 | 4024 # endif |
4025 ; | |
4026 } | |
4027 #endif | |
4028 | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4029 /* |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4030 * Return the character name of the register with the given number. |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4031 */ |
7 | 4032 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4033 get_register_name(int num) |
7 | 4034 { |
4035 if (num == -1) | |
4036 return '"'; | |
4037 else if (num < 10) | |
4038 return num + '0'; | |
4039 else if (num == DELETION_REGISTER) | |
4040 return '-'; | |
4041 #ifdef FEAT_CLIPBOARD | |
4042 else if (num == STAR_REGISTER) | |
4043 return '*'; | |
4044 else if (num == PLUS_REGISTER) | |
4045 return '+'; | |
4046 #endif | |
4047 else | |
4048 { | |
4049 #ifdef EBCDIC | |
4050 int i; | |
4051 | |
4052 /* EBCDIC is really braindead ... */ | |
4053 i = 'a' + (num - 10); | |
4054 if (i > 'i') | |
4055 i += 7; | |
4056 if (i > 'r') | |
4057 i += 8; | |
4058 return i; | |
4059 #else | |
4060 return num + 'a' - 10; | |
4061 #endif | |
4062 } | |
4063 } | |
4064 | |
4065 /* | |
4066 * ":dis" and ":registers": Display the contents of the yank registers. | |
4067 */ | |
4068 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4069 ex_display(exarg_T *eap) |
7 | 4070 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4071 int i, n; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4072 long j; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4073 char_u *p; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4074 yankreg_T *yb; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4075 int name; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4076 int attr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4077 char_u *arg = eap->arg; |
22 | 4078 #ifdef FEAT_MBYTE |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4079 int clen; |
22 | 4080 #else |
4081 # define clen 1 | |
4082 #endif | |
7 | 4083 |
4084 if (arg != NULL && *arg == NUL) | |
4085 arg = NULL; | |
4086 attr = hl_attr(HLF_8); | |
4087 | |
4088 /* Highlight title */ | |
4089 MSG_PUTS_TITLE(_("\n--- Registers ---")); | |
4090 for (i = -1; i < NUM_REGISTERS && !got_int; ++i) | |
4091 { | |
4092 name = get_register_name(i); | |
2644 | 4093 if (arg != NULL && vim_strchr(arg, name) == NULL |
4094 #ifdef ONE_CLIPBOARD | |
4095 /* Star register and plus register contain the same thing. */ | |
4096 && (name != '*' || vim_strchr(arg, '+') == NULL) | |
4097 #endif | |
4098 ) | |
7 | 4099 continue; /* did not ask for this register */ |
4100 | |
4101 #ifdef FEAT_CLIPBOARD | |
4102 /* Adjust register name for "unnamed" in 'clipboard'. | |
4103 * When it's a clipboard register, fill it with the current contents | |
4104 * of the clipboard. */ | |
4105 adjust_clip_reg(&name); | |
4106 (void)may_get_selection(name); | |
4107 #endif | |
4108 | |
4109 if (i == -1) | |
4110 { | |
4111 if (y_previous != NULL) | |
4112 yb = y_previous; | |
4113 else | |
4114 yb = &(y_regs[0]); | |
4115 } | |
4116 else | |
4117 yb = &(y_regs[i]); | |
2000 | 4118 |
4119 #ifdef FEAT_EVAL | |
4120 if (name == MB_TOLOWER(redir_reg) | |
4121 || (redir_reg == '"' && yb == y_previous)) | |
4122 continue; /* do not list register being written to, the | |
4123 * pointer can be freed */ | |
4124 #endif | |
4125 | |
7 | 4126 if (yb->y_array != NULL) |
4127 { | |
4128 msg_putchar('\n'); | |
4129 msg_putchar('"'); | |
4130 msg_putchar(name); | |
4131 MSG_PUTS(" "); | |
4132 | |
4133 n = (int)Columns - 6; | |
4134 for (j = 0; j < yb->y_size && n > 1; ++j) | |
4135 { | |
4136 if (j) | |
4137 { | |
4138 MSG_PUTS_ATTR("^J", attr); | |
4139 n -= 2; | |
4140 } | |
4141 for (p = yb->y_array[j]; *p && (n -= ptr2cells(p)) >= 0; ++p) | |
4142 { | |
4143 #ifdef FEAT_MBYTE | |
474 | 4144 clen = (*mb_ptr2len)(p); |
22 | 4145 #endif |
4146 msg_outtrans_len(p, clen); | |
4147 #ifdef FEAT_MBYTE | |
4148 p += clen - 1; | |
7 | 4149 #endif |
4150 } | |
4151 } | |
4152 if (n > 1 && yb->y_type == MLINE) | |
4153 MSG_PUTS_ATTR("^J", attr); | |
4154 out_flush(); /* show one line at a time */ | |
4155 } | |
4156 ui_breakcheck(); | |
4157 } | |
4158 | |
4159 /* | |
4160 * display last inserted text | |
4161 */ | |
4162 if ((p = get_last_insert()) != NULL | |
4163 && (arg == NULL || vim_strchr(arg, '.') != NULL) && !got_int) | |
4164 { | |
4165 MSG_PUTS("\n\". "); | |
4166 dis_msg(p, TRUE); | |
4167 } | |
4168 | |
4169 /* | |
4170 * display last command line | |
4171 */ | |
4172 if (last_cmdline != NULL && (arg == NULL || vim_strchr(arg, ':') != NULL) | |
4173 && !got_int) | |
4174 { | |
4175 MSG_PUTS("\n\": "); | |
4176 dis_msg(last_cmdline, FALSE); | |
4177 } | |
4178 | |
4179 /* | |
4180 * display current file name | |
4181 */ | |
4182 if (curbuf->b_fname != NULL | |
4183 && (arg == NULL || vim_strchr(arg, '%') != NULL) && !got_int) | |
4184 { | |
4185 MSG_PUTS("\n\"% "); | |
4186 dis_msg(curbuf->b_fname, FALSE); | |
4187 } | |
4188 | |
4189 /* | |
4190 * display alternate file name | |
4191 */ | |
4192 if ((arg == NULL || vim_strchr(arg, '%') != NULL) && !got_int) | |
4193 { | |
4194 char_u *fname; | |
4195 linenr_T dummy; | |
4196 | |
4197 if (buflist_name_nr(0, &fname, &dummy) != FAIL) | |
4198 { | |
4199 MSG_PUTS("\n\"# "); | |
4200 dis_msg(fname, FALSE); | |
4201 } | |
4202 } | |
4203 | |
4204 /* | |
4205 * display last search pattern | |
4206 */ | |
4207 if (last_search_pat() != NULL | |
4208 && (arg == NULL || vim_strchr(arg, '/') != NULL) && !got_int) | |
4209 { | |
4210 MSG_PUTS("\n\"/ "); | |
4211 dis_msg(last_search_pat(), FALSE); | |
4212 } | |
4213 | |
4214 #ifdef FEAT_EVAL | |
4215 /* | |
4216 * display last used expression | |
4217 */ | |
4218 if (expr_line != NULL && (arg == NULL || vim_strchr(arg, '=') != NULL) | |
4219 && !got_int) | |
4220 { | |
4221 MSG_PUTS("\n\"= "); | |
4222 dis_msg(expr_line, FALSE); | |
4223 } | |
4224 #endif | |
4225 } | |
4226 | |
4227 /* | |
4228 * display a string for do_dis() | |
4229 * truncate at end of screen line | |
4230 */ | |
4231 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4232 dis_msg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4233 char_u *p, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4234 int skip_esc) /* if TRUE, ignore trailing ESC */ |
7 | 4235 { |
4236 int n; | |
4237 #ifdef FEAT_MBYTE | |
4238 int l; | |
4239 #endif | |
4240 | |
4241 n = (int)Columns - 6; | |
4242 while (*p != NUL | |
4243 && !(*p == ESC && skip_esc && *(p + 1) == NUL) | |
4244 && (n -= ptr2cells(p)) >= 0) | |
4245 { | |
4246 #ifdef FEAT_MBYTE | |
474 | 4247 if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) |
7 | 4248 { |
4249 msg_outtrans_len(p, l); | |
4250 p += l; | |
4251 } | |
4252 else | |
4253 #endif | |
4254 msg_outtrans_len(p++, 1); | |
4255 } | |
4256 ui_breakcheck(); | |
4257 } | |
4258 | |
3562 | 4259 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4260 /* | |
4261 * If "process" is TRUE and the line begins with a comment leader (possibly | |
4262 * after some white space), return a pointer to the text after it. Put a boolean | |
4263 * value indicating whether the line ends with an unclosed comment in | |
4264 * "is_comment". | |
4265 * line - line to be processed, | |
4266 * process - if FALSE, will only check whether the line ends with an unclosed | |
3584 | 4267 * comment, |
3562 | 4268 * include_space - whether to also skip space following the comment leader, |
4269 * is_comment - will indicate whether the current line ends with an unclosed | |
3584 | 4270 * comment. |
3562 | 4271 */ |
4272 static char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4273 skip_comment( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4274 char_u *line, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4275 int process, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4276 int include_space, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4277 int *is_comment) |
3562 | 4278 { |
4279 char_u *comment_flags = NULL; | |
4280 int lead_len; | |
4281 int leader_offset = get_last_leader_offset(line, &comment_flags); | |
4282 | |
4283 *is_comment = FALSE; | |
4284 if (leader_offset != -1) | |
4285 { | |
4286 /* Let's check whether the line ends with an unclosed comment. | |
4287 * If the last comment leader has COM_END in flags, there's no comment. | |
4288 */ | |
4289 while (*comment_flags) | |
4290 { | |
4291 if (*comment_flags == COM_END | |
4292 || *comment_flags == ':') | |
4293 break; | |
4294 ++comment_flags; | |
4295 } | |
4296 if (*comment_flags != COM_END) | |
4297 *is_comment = TRUE; | |
4298 } | |
4299 | |
4300 if (process == FALSE) | |
4301 return line; | |
4302 | |
4303 lead_len = get_leader_len(line, &comment_flags, FALSE, include_space); | |
4304 | |
4305 if (lead_len == 0) | |
4306 return line; | |
4307 | |
4308 /* Find: | |
4309 * - COM_END, | |
4310 * - colon, | |
4311 * whichever comes first. | |
4312 */ | |
4313 while (*comment_flags) | |
4314 { | |
3580 | 4315 if (*comment_flags == COM_END |
3562 | 4316 || *comment_flags == ':') |
4317 { | |
4318 break; | |
4319 } | |
4320 ++comment_flags; | |
4321 } | |
4322 | |
4323 /* If we found a colon, it means that we are not processing a line | |
3580 | 4324 * starting with a closing part of a three-part comment. That's good, |
4325 * because we don't want to remove those as this would be annoying. | |
3562 | 4326 */ |
4327 if (*comment_flags == ':' || *comment_flags == NUL) | |
4328 line += lead_len; | |
4329 | |
4330 return line; | |
4331 } | |
4332 #endif | |
4333 | |
7 | 4334 /* |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4335 * 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
|
4336 * When "save_undo" is TRUE save lines for undo first. |
5848 | 4337 * Set "use_formatoptions" to FALSE when e.g. processing backspace and comment |
4338 * leaders should not be removed. | |
4339 * When setmark is TRUE, sets the '[ and '] mark, else, the caller is expected | |
4340 * to set those marks. | |
7 | 4341 * |
1217 | 4342 * return FAIL for failure, OK otherwise |
7 | 4343 */ |
4344 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4345 do_join( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4346 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4347 int insert_space, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4348 int save_undo, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4349 int use_formatoptions UNUSED, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4350 int setmark) |
7 | 4351 { |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4352 char_u *curr = NULL; |
2597 | 4353 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
|
4354 char_u *cend; |
7 | 4355 char_u *newp; |
2597 | 4356 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
|
4357 int endcurr1 = NUL; |
3e4574a4b627
Fix a few compiler warnings.
Bram Moolenaar <bram@vim.org>
parents:
2298
diff
changeset
|
4358 int endcurr2 = NUL; |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4359 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
|
4360 int sumsize = 0; /* size of the long new line */ |
7 | 4361 linenr_T t; |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4362 colnr_T col = 0; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4363 int ret = OK; |
3562 | 4364 #if defined(FEAT_COMMENTS) || defined(PROTO) |
3574 | 4365 int *comments = NULL; |
3562 | 4366 int remove_comments = (use_formatoptions == TRUE) |
4367 && has_format_option(FO_REMOVE_COMS); | |
4368 int prev_was_comment; | |
4369 #endif | |
4370 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4371 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4372 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
|
4373 (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
|
4374 return FAIL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4375 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4376 /* 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
|
4377 * 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
|
4378 * 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
|
4379 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
|
4380 if (spaces == NULL) |
7 | 4381 return FAIL; |
3562 | 4382 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4383 if (remove_comments) | |
4384 { | |
4385 comments = (int *)lalloc_clear((long_u)count * sizeof(int), TRUE); | |
4386 if (comments == NULL) | |
4387 { | |
4388 vim_free(spaces); | |
4389 return FAIL; | |
4390 } | |
4391 } | |
4392 #endif | |
7 | 4393 |
4394 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4395 * 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
|
4396 * and setup the array of space strings lengths |
7 | 4397 */ |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4398 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
|
4399 { |
2597 | 4400 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t)); |
5848 | 4401 if (t == 0 && setmark) |
5664 | 4402 { |
4403 /* Set the '[ mark. */ | |
4404 curwin->w_buffer->b_op_start.lnum = curwin->w_cursor.lnum; | |
4405 curwin->w_buffer->b_op_start.col = (colnr_T)STRLEN(curr); | |
4406 } | |
3562 | 4407 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4408 if (remove_comments) | |
4409 { | |
4410 /* We don't want to remove the comment leader if the | |
4411 * previous line is not a comment. */ | |
4412 if (t > 0 && prev_was_comment) | |
4413 { | |
4414 | |
4415 char_u *new_curr = skip_comment(curr, TRUE, insert_space, | |
4416 &prev_was_comment); | |
3576 | 4417 comments[t] = (int)(new_curr - curr); |
3562 | 4418 curr = new_curr; |
4419 } | |
4420 else | |
4421 curr = skip_comment(curr, FALSE, insert_space, | |
4422 &prev_was_comment); | |
4423 } | |
4424 #endif | |
4425 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4426 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
|
4427 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4428 curr = skipwhite(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4429 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
|
4430 #ifdef FEAT_MBYTE |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4431 && (!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
|
4432 || (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
|
4433 && (!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
|
4434 || 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
|
4435 #endif |
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 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4438 /* 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
|
4439 if (endcurr1 == ' ') |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4440 endcurr1 = endcurr2; |
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 ++spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4443 /* 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
|
4444 if ( p_js |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4445 && (endcurr1 == '.' |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4446 || (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
|
4447 && (endcurr1 == '?' || endcurr1 == '!')))) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4448 ++spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4449 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4450 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4451 currsize = (int)STRLEN(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4452 sumsize += currsize + spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4453 endcurr1 = endcurr2 = NUL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4454 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
|
4455 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4456 #ifdef FEAT_MBYTE |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4457 if (has_mbyte) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4458 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4459 cend = curr + currsize; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4460 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
|
4461 endcurr1 = (*mb_ptr2char)(cend); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4462 if (cend > curr) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4463 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4464 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
|
4465 endcurr2 = (*mb_ptr2char)(cend); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4466 } |
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 else |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4469 #endif |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4470 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4471 endcurr1 = *(curr + currsize - 1); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4472 if (currsize > 1) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4473 endcurr2 = *(curr + currsize - 2); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4474 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4475 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4476 line_breakcheck(); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4477 if (got_int) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4478 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4479 ret = FAIL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4480 goto theend; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4481 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4482 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4483 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4484 /* 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
|
4485 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
|
4486 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4487 /* 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
|
4488 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
|
4489 cend = newp + sumsize; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4490 *cend = 0; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4491 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4492 /* |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4493 * 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
|
4494 * |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4495 * 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
|
4496 * 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
|
4497 * 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
|
4498 */ |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4499 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
|
4500 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4501 cend -= currsize; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4502 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
|
4503 if (spaces[t] > 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4504 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4505 cend -= spaces[t]; |
6929 | 4506 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
|
4507 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4508 mark_col_adjust(curwin->w_cursor.lnum + t, (colnr_T)0, (linenr_T)-t, |
2597 | 4509 (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
|
4510 if (t == 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4511 break; |
2597 | 4512 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t - 1)); |
3562 | 4513 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4514 if (remove_comments) | |
4515 curr += comments[t - 1]; | |
4516 #endif | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4517 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
|
4518 curr = skipwhite(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4519 currsize = (int)STRLEN(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4520 } |
7 | 4521 ml_replace(curwin->w_cursor.lnum, newp, FALSE); |
4522 | |
5848 | 4523 if (setmark) |
4524 { | |
4525 /* Set the '] mark. */ | |
4526 curwin->w_buffer->b_op_end.lnum = curwin->w_cursor.lnum; | |
4527 curwin->w_buffer->b_op_end.col = (colnr_T)STRLEN(newp); | |
4528 } | |
5664 | 4529 |
7 | 4530 /* Only report the change in the first line here, del_lines() will report |
4531 * the deleted line. */ | |
4532 changed_lines(curwin->w_cursor.lnum, currsize, | |
4533 curwin->w_cursor.lnum + 1, 0L); | |
4534 | |
4535 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4536 * Delete following lines. To do this we move the cursor there |
7 | 4537 * briefly, and then move it back. After del_lines() the cursor may |
4538 * have moved up (last line deleted), so the current lnum is kept in t. | |
4539 */ | |
4540 t = curwin->w_cursor.lnum; | |
4541 ++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
|
4542 del_lines(count - 1, FALSE); |
7 | 4543 curwin->w_cursor.lnum = t; |
4544 | |
4545 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4546 * Set the cursor column: |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4547 * 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
|
4548 * vim: use the column of the last join |
7 | 4549 */ |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4550 curwin->w_cursor.col = |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4551 (vim_strchr(p_cpo, CPO_JOINCOL) != NULL ? currsize : col); |
7 | 4552 check_cursor_col(); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4553 |
7 | 4554 #ifdef FEAT_VIRTUALEDIT |
4555 curwin->w_cursor.coladd = 0; | |
4556 #endif | |
4557 curwin->w_set_curswant = TRUE; | |
4558 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4559 theend: |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4560 vim_free(spaces); |
3562 | 4561 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4562 if (remove_comments) | |
4563 vim_free(comments); | |
4564 #endif | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4565 return ret; |
7 | 4566 } |
4567 | |
4568 #ifdef FEAT_COMMENTS | |
4569 /* | |
4570 * Return TRUE if the two comment leaders given are the same. "lnum" is | |
4571 * the first line. White-space is ignored. Note that the whole of | |
4572 * 'leader1' must match 'leader2_len' characters from 'leader2' -- webb | |
4573 */ | |
4574 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4575 same_leader( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4576 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4577 int leader1_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4578 char_u *leader1_flags, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4579 int leader2_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4580 char_u *leader2_flags) |
7 | 4581 { |
4582 int idx1 = 0, idx2 = 0; | |
4583 char_u *p; | |
4584 char_u *line1; | |
4585 char_u *line2; | |
4586 | |
4587 if (leader1_len == 0) | |
4588 return (leader2_len == 0); | |
4589 | |
4590 /* | |
4591 * If first leader has 'f' flag, the lines can be joined only if the | |
4592 * second line does not have a leader. | |
4593 * If first leader has 'e' flag, the lines can never be joined. | |
4594 * If fist leader has 's' flag, the lines can only be joined if there is | |
4595 * some text after it and the second line has the 'm' flag. | |
4596 */ | |
4597 if (leader1_flags != NULL) | |
4598 { | |
4599 for (p = leader1_flags; *p && *p != ':'; ++p) | |
4600 { | |
4601 if (*p == COM_FIRST) | |
4602 return (leader2_len == 0); | |
4603 if (*p == COM_END) | |
4604 return FALSE; | |
4605 if (*p == COM_START) | |
4606 { | |
4607 if (*(ml_get(lnum) + leader1_len) == NUL) | |
4608 return FALSE; | |
4609 if (leader2_flags == NULL || leader2_len == 0) | |
4610 return FALSE; | |
4611 for (p = leader2_flags; *p && *p != ':'; ++p) | |
4612 if (*p == COM_MIDDLE) | |
4613 return TRUE; | |
4614 return FALSE; | |
4615 } | |
4616 } | |
4617 } | |
4618 | |
4619 /* | |
4620 * Get current line and next line, compare the leaders. | |
4621 * The first line has to be saved, only one line can be locked at a time. | |
4622 */ | |
4623 line1 = vim_strsave(ml_get(lnum)); | |
4624 if (line1 != NULL) | |
4625 { | |
4626 for (idx1 = 0; vim_iswhite(line1[idx1]); ++idx1) | |
4627 ; | |
4628 line2 = ml_get(lnum + 1); | |
4629 for (idx2 = 0; idx2 < leader2_len; ++idx2) | |
4630 { | |
4631 if (!vim_iswhite(line2[idx2])) | |
4632 { | |
4633 if (line1[idx1++] != line2[idx2]) | |
4634 break; | |
4635 } | |
4636 else | |
4637 while (vim_iswhite(line1[idx1])) | |
4638 ++idx1; | |
4639 } | |
4640 vim_free(line1); | |
4641 } | |
4642 return (idx2 == leader2_len && idx1 == leader1_len); | |
4643 } | |
4644 #endif | |
4645 | |
4646 /* | |
3252 | 4647 * Implementation of the format operator 'gq'. |
7 | 4648 */ |
4649 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4650 op_format( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4651 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4652 int keep_cursor) /* keep cursor on same text char */ |
7 | 4653 { |
4654 long old_line_count = curbuf->b_ml.ml_line_count; | |
4655 | |
4656 /* Place the cursor where the "gq" or "gw" command was given, so that "u" | |
4657 * can put it back there. */ | |
4658 curwin->w_cursor = oap->cursor_start; | |
4659 | |
4660 if (u_save((linenr_T)(oap->start.lnum - 1), | |
4661 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
4662 return; | |
4663 curwin->w_cursor = oap->start; | |
4664 | |
4665 if (oap->is_VIsual) | |
4666 /* When there is no change: need to remove the Visual selection */ | |
4667 redraw_curbuf_later(INVERTED); | |
4668 | |
4669 /* Set '[ mark at the start of the formatted area */ | |
4670 curbuf->b_op_start = oap->start; | |
4671 | |
4672 /* For "gw" remember the cursor position and put it back below (adjusted | |
4673 * for joined and split lines). */ | |
4674 if (keep_cursor) | |
4675 saved_cursor = oap->cursor_start; | |
4676 | |
1563 | 4677 format_lines(oap->line_count, keep_cursor); |
7 | 4678 |
4679 /* | |
4680 * Leave the cursor at the first non-blank of the last formatted line. | |
4681 * If the cursor was moved one line back (e.g. with "Q}") go to the next | |
4682 * line, so "." will do the next lines. | |
4683 */ | |
4684 if (oap->end_adjusted && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
4685 ++curwin->w_cursor.lnum; | |
4686 beginline(BL_WHITE | BL_FIX); | |
4687 old_line_count = curbuf->b_ml.ml_line_count - old_line_count; | |
4688 msgmore(old_line_count); | |
4689 | |
4690 /* put '] mark on the end of the formatted area */ | |
4691 curbuf->b_op_end = curwin->w_cursor; | |
4692 | |
4693 if (keep_cursor) | |
4694 { | |
4695 curwin->w_cursor = saved_cursor; | |
4696 saved_cursor.lnum = 0; | |
4697 } | |
4698 | |
4699 if (oap->is_VIsual) | |
4700 { | |
4701 win_T *wp; | |
4702 | |
4703 FOR_ALL_WINDOWS(wp) | |
4704 { | |
4705 if (wp->w_old_cursor_lnum != 0) | |
4706 { | |
4707 /* When lines have been inserted or deleted, adjust the end of | |
4708 * the Visual area to be redrawn. */ | |
4709 if (wp->w_old_cursor_lnum > wp->w_old_visual_lnum) | |
4710 wp->w_old_cursor_lnum += old_line_count; | |
4711 else | |
4712 wp->w_old_visual_lnum += old_line_count; | |
4713 } | |
4714 } | |
4715 } | |
4716 } | |
4717 | |
667 | 4718 #if defined(FEAT_EVAL) || defined(PROTO) |
4719 /* | |
4720 * Implementation of the format operator 'gq' for when using 'formatexpr'. | |
4721 */ | |
4722 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4723 op_formatexpr(oparg_T *oap) |
667 | 4724 { |
4725 if (oap->is_VIsual) | |
4726 /* When there is no change: need to remove the Visual selection */ | |
4727 redraw_curbuf_later(INVERTED); | |
4728 | |
2298
a3562a127cf6
When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
4729 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
|
4730 /* 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
|
4731 * internal formatting. */ |
a3562a127cf6
When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
4732 op_format(oap, FALSE); |
667 | 4733 } |
4734 | |
4735 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4736 fex_format( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4737 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4738 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4739 int c) /* character to be inserted */ |
667 | 4740 { |
681 | 4741 int use_sandbox = was_set_insecurely((char_u *)"formatexpr", |
4742 OPT_LOCAL); | |
667 | 4743 int r; |
4744 | |
4745 /* | |
4746 * Set v:lnum to the first line number and v:count to the number of lines. | |
844 | 4747 * Set v:char to the character to be inserted (can be NUL). |
667 | 4748 */ |
4749 set_vim_var_nr(VV_LNUM, lnum); | |
4750 set_vim_var_nr(VV_COUNT, count); | |
1969 | 4751 set_vim_var_char(c); |
844 | 4752 |
667 | 4753 /* |
4754 * Evaluate the function. | |
4755 */ | |
4756 if (use_sandbox) | |
4757 ++sandbox; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
4758 r = (int)eval_to_number(curbuf->b_p_fex); |
667 | 4759 if (use_sandbox) |
4760 --sandbox; | |
844 | 4761 |
4762 set_vim_var_string(VV_CHAR, NULL, -1); | |
4763 | |
667 | 4764 return r; |
4765 } | |
4766 #endif | |
4767 | |
7 | 4768 /* |
4769 * Format "line_count" lines, starting at the cursor position. | |
4770 * When "line_count" is negative, format until the end of the paragraph. | |
4771 * Lines after the cursor line are saved for undo, caller must have saved the | |
4772 * first line. | |
4773 */ | |
4774 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4775 format_lines( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4776 linenr_T line_count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4777 int avoid_fex) /* don't use 'formatexpr' */ |
7 | 4778 { |
4779 int max_len; | |
4780 int is_not_par; /* current line not part of parag. */ | |
4781 int next_is_not_par; /* next line not part of paragraph */ | |
4782 int is_end_par; /* at end of paragraph */ | |
4783 int prev_is_end_par = FALSE;/* prev. line not part of parag. */ | |
4784 int next_is_start_par = FALSE; | |
4785 #ifdef FEAT_COMMENTS | |
4786 int leader_len = 0; /* leader len of current line */ | |
4787 int next_leader_len; /* leader len of next line */ | |
4788 char_u *leader_flags = NULL; /* flags for leader of current line */ | |
4789 char_u *next_leader_flags; /* flags for leader of next line */ | |
4790 int do_comments; /* format comments */ | |
3584 | 4791 int do_comments_list = 0; /* format comments with 'n' or '2' */ |
7 | 4792 #endif |
4793 int advance = TRUE; | |
3584 | 4794 int second_indent = -1; /* indent for second line (comment |
4795 * aware) */ | |
7 | 4796 int do_second_indent; |
4797 int do_number_indent; | |
4798 int do_trail_white; | |
4799 int first_par_line = TRUE; | |
4800 int smd_save; | |
4801 long count; | |
4802 int need_set_indent = TRUE; /* set indent of next paragraph */ | |
4803 int force_format = FALSE; | |
4804 int old_State = State; | |
4805 | |
4806 /* length of a line to force formatting: 3 * 'tw' */ | |
4807 max_len = comp_textwidth(TRUE) * 3; | |
4808 | |
4809 /* check for 'q', '2' and '1' in 'formatoptions' */ | |
4810 #ifdef FEAT_COMMENTS | |
4811 do_comments = has_format_option(FO_Q_COMS); | |
4812 #endif | |
4813 do_second_indent = has_format_option(FO_Q_SECOND); | |
4814 do_number_indent = has_format_option(FO_Q_NUMBER); | |
4815 do_trail_white = has_format_option(FO_WHITE_PAR); | |
4816 | |
4817 /* | |
4818 * Get info about the previous and current line. | |
4819 */ | |
4820 if (curwin->w_cursor.lnum > 1) | |
4821 is_not_par = fmt_check_par(curwin->w_cursor.lnum - 1 | |
4822 #ifdef FEAT_COMMENTS | |
4823 , &leader_len, &leader_flags, do_comments | |
4824 #endif | |
4825 ); | |
4826 else | |
4827 is_not_par = TRUE; | |
4828 next_is_not_par = fmt_check_par(curwin->w_cursor.lnum | |
4829 #ifdef FEAT_COMMENTS | |
4830 , &next_leader_len, &next_leader_flags, do_comments | |
4831 #endif | |
4832 ); | |
4833 is_end_par = (is_not_par || next_is_not_par); | |
4834 if (!is_end_par && do_trail_white) | |
4835 is_end_par = !ends_in_white(curwin->w_cursor.lnum - 1); | |
4836 | |
4837 curwin->w_cursor.lnum--; | |
4838 for (count = line_count; count != 0 && !got_int; --count) | |
4839 { | |
4840 /* | |
4841 * Advance to next paragraph. | |
4842 */ | |
4843 if (advance) | |
4844 { | |
4845 curwin->w_cursor.lnum++; | |
4846 prev_is_end_par = is_end_par; | |
4847 is_not_par = next_is_not_par; | |
4848 #ifdef FEAT_COMMENTS | |
4849 leader_len = next_leader_len; | |
4850 leader_flags = next_leader_flags; | |
4851 #endif | |
4852 } | |
4853 | |
4854 /* | |
4855 * The last line to be formatted. | |
4856 */ | |
4857 if (count == 1 || curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) | |
4858 { | |
4859 next_is_not_par = TRUE; | |
4860 #ifdef FEAT_COMMENTS | |
4861 next_leader_len = 0; | |
4862 next_leader_flags = NULL; | |
4863 #endif | |
4864 } | |
4865 else | |
4866 { | |
4867 next_is_not_par = fmt_check_par(curwin->w_cursor.lnum + 1 | |
4868 #ifdef FEAT_COMMENTS | |
4869 , &next_leader_len, &next_leader_flags, do_comments | |
4870 #endif | |
4871 ); | |
4872 if (do_number_indent) | |
4873 next_is_start_par = | |
4874 (get_number_indent(curwin->w_cursor.lnum + 1) > 0); | |
4875 } | |
4876 advance = TRUE; | |
4877 is_end_par = (is_not_par || next_is_not_par || next_is_start_par); | |
4878 if (!is_end_par && do_trail_white) | |
4879 is_end_par = !ends_in_white(curwin->w_cursor.lnum); | |
4880 | |
4881 /* | |
4882 * Skip lines that are not in a paragraph. | |
4883 */ | |
4884 if (is_not_par) | |
4885 { | |
4886 if (line_count < 0) | |
4887 break; | |
4888 } | |
4889 else | |
4890 { | |
4891 /* | |
4892 * For the first line of a paragraph, check indent of second line. | |
4893 * Don't do this for comments and empty lines. | |
4894 */ | |
4895 if (first_par_line | |
4896 && (do_second_indent || do_number_indent) | |
4897 && prev_is_end_par | |
3584 | 4898 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) |
4899 { | |
4900 if (do_second_indent && !lineempty(curwin->w_cursor.lnum + 1)) | |
4901 { | |
4902 #ifdef FEAT_COMMENTS | |
4903 if (leader_len == 0 && next_leader_len == 0) | |
4904 { | |
4905 /* no comment found */ | |
4906 #endif | |
4907 second_indent = | |
4908 get_indent_lnum(curwin->w_cursor.lnum + 1); | |
7 | 4909 #ifdef FEAT_COMMENTS |
3584 | 4910 } |
4911 else | |
4912 { | |
4913 second_indent = next_leader_len; | |
4914 do_comments_list = 1; | |
4915 } | |
4916 #endif | |
4917 } | |
7 | 4918 else if (do_number_indent) |
3584 | 4919 { |
4920 #ifdef FEAT_COMMENTS | |
4921 if (leader_len == 0 && next_leader_len == 0) | |
4922 { | |
4923 /* no comment found */ | |
4924 #endif | |
4925 second_indent = | |
4926 get_number_indent(curwin->w_cursor.lnum); | |
4927 #ifdef FEAT_COMMENTS | |
4928 } | |
4929 else | |
4930 { | |
4931 /* get_number_indent() is now "comment aware"... */ | |
4932 second_indent = | |
4933 get_number_indent(curwin->w_cursor.lnum); | |
4934 do_comments_list = 1; | |
4935 } | |
4936 #endif | |
4937 } | |
7 | 4938 } |
4939 | |
4940 /* | |
4941 * When the comment leader changes, it's the end of the paragraph. | |
4942 */ | |
4943 if (curwin->w_cursor.lnum >= curbuf->b_ml.ml_line_count | |
4944 #ifdef FEAT_COMMENTS | |
4945 || !same_leader(curwin->w_cursor.lnum, | |
4946 leader_len, leader_flags, | |
4947 next_leader_len, next_leader_flags) | |
4948 #endif | |
4949 ) | |
4950 is_end_par = TRUE; | |
4951 | |
4952 /* | |
4953 * If we have got to the end of a paragraph, or the line is | |
4954 * getting long, format it. | |
4955 */ | |
4956 if (is_end_par || force_format) | |
4957 { | |
4958 if (need_set_indent) | |
4959 /* replace indent in first line with minimal number of | |
4960 * tabs and spaces, according to current options */ | |
4961 (void)set_indent(get_indent(), SIN_CHANGED); | |
4962 | |
4963 /* put cursor on last non-space */ | |
4964 State = NORMAL; /* don't go past end-of-line */ | |
4965 coladvance((colnr_T)MAXCOL); | |
4966 while (curwin->w_cursor.col && vim_isspace(gchar_cursor())) | |
4967 dec_cursor(); | |
4968 | |
4969 /* do the formatting, without 'showmode' */ | |
4970 State = INSERT; /* for open_line() */ | |
4971 smd_save = p_smd; | |
4972 p_smd = FALSE; | |
4973 insertchar(NUL, INSCHAR_FORMAT | |
4974 #ifdef FEAT_COMMENTS | |
4975 + (do_comments ? INSCHAR_DO_COM : 0) | |
3584 | 4976 + (do_comments && do_comments_list |
4977 ? INSCHAR_COM_LIST : 0) | |
7 | 4978 #endif |
1563 | 4979 + (avoid_fex ? INSCHAR_NO_FEX : 0), second_indent); |
7 | 4980 State = old_State; |
4981 p_smd = smd_save; | |
4982 second_indent = -1; | |
4983 /* at end of par.: need to set indent of next par. */ | |
4984 need_set_indent = is_end_par; | |
4985 if (is_end_par) | |
4986 { | |
4987 /* When called with a negative line count, break at the | |
4988 * end of the paragraph. */ | |
4989 if (line_count < 0) | |
4990 break; | |
4991 first_par_line = TRUE; | |
4992 } | |
4993 force_format = FALSE; | |
4994 } | |
4995 | |
4996 /* | |
4997 * When still in same paragraph, join the lines together. But | |
5403 | 4998 * first delete the leader from the second line. |
7 | 4999 */ |
5000 if (!is_end_par) | |
5001 { | |
5002 advance = FALSE; | |
5003 curwin->w_cursor.lnum++; | |
5004 curwin->w_cursor.col = 0; | |
5005 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
|
5006 break; |
7 | 5007 #ifdef FEAT_COMMENTS |
5008 if (next_leader_len > 0) | |
5403 | 5009 { |
5010 (void)del_bytes((long)next_leader_len, FALSE, FALSE); | |
7 | 5011 mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L, |
5012 (long)-next_leader_len); | |
5403 | 5013 } else |
5014 #endif | |
5015 if (second_indent > 0) /* the "leader" for FO_Q_SECOND */ | |
5016 { | |
5017 char_u *p = ml_get_curline(); | |
5415 | 5018 int indent = (int)(skipwhite(p) - p); |
5403 | 5019 |
5020 if (indent > 0) | |
5021 { | |
5022 (void)del_bytes(indent, FALSE, FALSE); | |
5023 mark_col_adjust(curwin->w_cursor.lnum, | |
5024 (colnr_T)0, 0L, (long)-indent); | |
5415 | 5025 } |
5403 | 5026 } |
7 | 5027 curwin->w_cursor.lnum--; |
5848 | 5028 if (do_join(2, TRUE, FALSE, FALSE, FALSE) == FAIL) |
7 | 5029 { |
5030 beep_flush(); | |
5031 break; | |
5032 } | |
5033 first_par_line = FALSE; | |
5034 /* If the line is getting long, format it next time */ | |
5035 if (STRLEN(ml_get_curline()) > (size_t)max_len) | |
5036 force_format = TRUE; | |
5037 else | |
5038 force_format = FALSE; | |
5039 } | |
5040 } | |
5041 line_breakcheck(); | |
5042 } | |
5043 } | |
5044 | |
5045 /* | |
5046 * Return TRUE if line "lnum" ends in a white character. | |
5047 */ | |
5048 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5049 ends_in_white(linenr_T lnum) |
7 | 5050 { |
5051 char_u *s = ml_get(lnum); | |
5052 size_t l; | |
5053 | |
5054 if (*s == NUL) | |
5055 return FALSE; | |
5056 /* Don't use STRLEN() inside vim_iswhite(), SAS/C complains: "macro | |
5057 * invocation may call function multiple times". */ | |
5058 l = STRLEN(s) - 1; | |
5059 return vim_iswhite(s[l]); | |
5060 } | |
5061 | |
5062 /* | |
5063 * Blank lines, and lines containing only the comment leader, are left | |
5064 * untouched by the formatting. The function returns TRUE in this | |
5065 * case. It also returns TRUE when a line starts with the end of a comment | |
5066 * ('e' in comment flags), so that this line is skipped, and not joined to the | |
5067 * previous line. A new paragraph starts after a blank line, or when the | |
5068 * comment leader changes -- webb. | |
5069 */ | |
5070 #ifdef FEAT_COMMENTS | |
5071 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5072 fmt_check_par( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5073 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5074 int *leader_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5075 char_u **leader_flags, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5076 int do_comments) |
7 | 5077 { |
5078 char_u *flags = NULL; /* init for GCC */ | |
5079 char_u *ptr; | |
5080 | |
5081 ptr = ml_get(lnum); | |
5082 if (do_comments) | |
3562 | 5083 *leader_len = get_leader_len(ptr, leader_flags, FALSE, TRUE); |
7 | 5084 else |
5085 *leader_len = 0; | |
5086 | |
5087 if (*leader_len > 0) | |
5088 { | |
5089 /* | |
5090 * Search for 'e' flag in comment leader flags. | |
5091 */ | |
5092 flags = *leader_flags; | |
5093 while (*flags && *flags != ':' && *flags != COM_END) | |
5094 ++flags; | |
5095 } | |
5096 | |
5097 return (*skipwhite(ptr + *leader_len) == NUL | |
5098 || (*leader_len > 0 && *flags == COM_END) | |
5099 || startPS(lnum, NUL, FALSE)); | |
5100 } | |
5101 #else | |
5102 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5103 fmt_check_par(linenr_T lnum) |
7 | 5104 { |
5105 return (*skipwhite(ml_get(lnum)) == NUL || startPS(lnum, NUL, FALSE)); | |
5106 } | |
5107 #endif | |
5108 | |
5109 /* | |
5110 * Return TRUE when a paragraph starts in line "lnum". Return FALSE when the | |
5111 * previous line is in the same paragraph. Used for auto-formatting. | |
5112 */ | |
5113 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5114 paragraph_start(linenr_T lnum) |
7 | 5115 { |
5116 char_u *p; | |
5117 #ifdef FEAT_COMMENTS | |
5118 int leader_len = 0; /* leader len of current line */ | |
5119 char_u *leader_flags = NULL; /* flags for leader of current line */ | |
5120 int next_leader_len; /* leader len of next line */ | |
5121 char_u *next_leader_flags; /* flags for leader of next line */ | |
5122 int do_comments; /* format comments */ | |
5123 #endif | |
5124 | |
5125 if (lnum <= 1) | |
5126 return TRUE; /* start of the file */ | |
5127 | |
5128 p = ml_get(lnum - 1); | |
5129 if (*p == NUL) | |
5130 return TRUE; /* after empty line */ | |
5131 | |
5132 #ifdef FEAT_COMMENTS | |
5133 do_comments = has_format_option(FO_Q_COMS); | |
5134 #endif | |
5135 if (fmt_check_par(lnum - 1 | |
5136 #ifdef FEAT_COMMENTS | |
5137 , &leader_len, &leader_flags, do_comments | |
5138 #endif | |
5139 )) | |
5140 return TRUE; /* after non-paragraph line */ | |
5141 | |
5142 if (fmt_check_par(lnum | |
5143 #ifdef FEAT_COMMENTS | |
5144 , &next_leader_len, &next_leader_flags, do_comments | |
5145 #endif | |
5146 )) | |
5147 return TRUE; /* "lnum" is not a paragraph line */ | |
5148 | |
5149 if (has_format_option(FO_WHITE_PAR) && !ends_in_white(lnum - 1)) | |
5150 return TRUE; /* missing trailing space in previous line. */ | |
5151 | |
5152 if (has_format_option(FO_Q_NUMBER) && (get_number_indent(lnum) > 0)) | |
5153 return TRUE; /* numbered item starts in "lnum". */ | |
5154 | |
5155 #ifdef FEAT_COMMENTS | |
5156 if (!same_leader(lnum - 1, leader_len, leader_flags, | |
5157 next_leader_len, next_leader_flags)) | |
5158 return TRUE; /* change of comment leader. */ | |
5159 #endif | |
5160 | |
5161 return FALSE; | |
5162 } | |
5163 | |
5164 /* | |
5165 * prepare a few things for block mode yank/delete/tilde | |
5166 * | |
5167 * for delete: | |
5168 * - textlen includes the first/last char to be (partly) deleted | |
5169 * - start/endspaces is the number of columns that are taken by the | |
5170 * first/last deleted char minus the number of columns that have to be | |
1839 | 5171 * deleted. |
5172 * for yank and tilde: | |
7 | 5173 * - textlen includes the first/last char to be wholly yanked |
5174 * - start/endspaces is the number of columns of the first/last yanked char | |
5175 * that are to be yanked. | |
5176 */ | |
5177 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5178 block_prep( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5179 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5180 struct block_def *bdp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5181 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5182 int is_del) |
7 | 5183 { |
5184 int incr = 0; | |
5185 char_u *pend; | |
5186 char_u *pstart; | |
5187 char_u *line; | |
5188 char_u *prev_pstart; | |
5189 char_u *prev_pend; | |
5190 | |
5191 bdp->startspaces = 0; | |
5192 bdp->endspaces = 0; | |
5193 bdp->textlen = 0; | |
5194 bdp->start_vcol = 0; | |
5195 bdp->end_vcol = 0; | |
5196 #ifdef FEAT_VISUALEXTRA | |
5197 bdp->is_short = FALSE; | |
5198 bdp->is_oneChar = FALSE; | |
5199 bdp->pre_whitesp = 0; | |
5200 bdp->pre_whitesp_c = 0; | |
5201 bdp->end_char_vcols = 0; | |
5202 #endif | |
5203 bdp->start_char_vcols = 0; | |
5204 | |
5205 line = ml_get(lnum); | |
5206 pstart = line; | |
5207 prev_pstart = line; | |
5208 while (bdp->start_vcol < oap->start_vcol && *pstart) | |
5209 { | |
5210 /* Count a tab for what it's worth (if list mode not on) */ | |
5995 | 5211 incr = lbr_chartabsize(line, pstart, (colnr_T)bdp->start_vcol); |
7 | 5212 bdp->start_vcol += incr; |
5213 #ifdef FEAT_VISUALEXTRA | |
5214 if (vim_iswhite(*pstart)) | |
5215 { | |
5216 bdp->pre_whitesp += incr; | |
5217 bdp->pre_whitesp_c++; | |
5218 } | |
5219 else | |
5220 { | |
5221 bdp->pre_whitesp = 0; | |
5222 bdp->pre_whitesp_c = 0; | |
5223 } | |
5224 #endif | |
5225 prev_pstart = pstart; | |
39 | 5226 mb_ptr_adv(pstart); |
7 | 5227 } |
5228 bdp->start_char_vcols = incr; | |
5229 if (bdp->start_vcol < oap->start_vcol) /* line too short */ | |
5230 { | |
5231 bdp->end_vcol = bdp->start_vcol; | |
5232 #ifdef FEAT_VISUALEXTRA | |
5233 bdp->is_short = TRUE; | |
5234 #endif | |
5235 if (!is_del || oap->op_type == OP_APPEND) | |
5236 bdp->endspaces = oap->end_vcol - oap->start_vcol + 1; | |
5237 } | |
5238 else | |
5239 { | |
5240 /* notice: this converts partly selected Multibyte characters to | |
5241 * spaces, too. */ | |
5242 bdp->startspaces = bdp->start_vcol - oap->start_vcol; | |
5243 if (is_del && bdp->startspaces) | |
5244 bdp->startspaces = bdp->start_char_vcols - bdp->startspaces; | |
5245 pend = pstart; | |
5246 bdp->end_vcol = bdp->start_vcol; | |
5247 if (bdp->end_vcol > oap->end_vcol) /* it's all in one character */ | |
5248 { | |
5249 #ifdef FEAT_VISUALEXTRA | |
5250 bdp->is_oneChar = TRUE; | |
5251 #endif | |
5252 if (oap->op_type == OP_INSERT) | |
5253 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces; | |
5254 else if (oap->op_type == OP_APPEND) | |
5255 { | |
5256 bdp->startspaces += oap->end_vcol - oap->start_vcol + 1; | |
5257 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces; | |
5258 } | |
5259 else | |
5260 { | |
5261 bdp->startspaces = oap->end_vcol - oap->start_vcol + 1; | |
5262 if (is_del && oap->op_type != OP_LSHIFT) | |
5263 { | |
5264 /* just putting the sum of those two into | |
5265 * bdp->startspaces doesn't work for Visual replace, | |
5266 * so we have to split the tab in two */ | |
5267 bdp->startspaces = bdp->start_char_vcols | |
5268 - (bdp->start_vcol - oap->start_vcol); | |
5269 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; | |
5270 } | |
5271 } | |
5272 } | |
5273 else | |
5274 { | |
5275 prev_pend = pend; | |
5276 while (bdp->end_vcol <= oap->end_vcol && *pend != NUL) | |
5277 { | |
5278 /* Count a tab for what it's worth (if list mode not on) */ | |
5279 prev_pend = pend; | |
6535 | 5280 incr = lbr_chartabsize_adv(line, &pend, (colnr_T)bdp->end_vcol); |
7 | 5281 bdp->end_vcol += incr; |
5282 } | |
5283 if (bdp->end_vcol <= oap->end_vcol | |
5284 && (!is_del | |
5285 || oap->op_type == OP_APPEND | |
5286 || oap->op_type == OP_REPLACE)) /* line too short */ | |
5287 { | |
5288 #ifdef FEAT_VISUALEXTRA | |
5289 bdp->is_short = TRUE; | |
5290 #endif | |
5291 /* Alternative: include spaces to fill up the block. | |
5292 * Disadvantage: can lead to trailing spaces when the line is | |
5293 * short where the text is put */ | |
5294 /* if (!is_del || oap->op_type == OP_APPEND) */ | |
5295 if (oap->op_type == OP_APPEND || virtual_op) | |
5296 bdp->endspaces = oap->end_vcol - bdp->end_vcol | |
593 | 5297 + oap->inclusive; |
7 | 5298 else |
5299 bdp->endspaces = 0; /* replace doesn't add characters */ | |
5300 } | |
5301 else if (bdp->end_vcol > oap->end_vcol) | |
5302 { | |
5303 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; | |
5304 if (!is_del && bdp->endspaces) | |
5305 { | |
5306 bdp->endspaces = incr - bdp->endspaces; | |
5307 if (pend != pstart) | |
5308 pend = prev_pend; | |
5309 } | |
5310 } | |
5311 } | |
5312 #ifdef FEAT_VISUALEXTRA | |
5313 bdp->end_char_vcols = incr; | |
5314 #endif | |
5315 if (is_del && bdp->startspaces) | |
5316 pstart = prev_pstart; | |
5317 bdp->textlen = (int)(pend - pstart); | |
5318 } | |
5319 bdp->textcol = (colnr_T) (pstart - line); | |
5320 bdp->textstart = pstart; | |
5321 } | |
5322 | |
5323 /* | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5324 * Handle the add/subtract operator. |
7 | 5325 */ |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5326 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5327 op_addsub( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5328 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5329 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
|
5330 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
|
5331 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5332 pos_T pos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5333 struct block_def bd; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5334 int change_cnt = 0; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5335 linenr_T amount = Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5336 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5337 if (!VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5338 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5339 pos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5340 if (u_save_cursor() == FAIL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5341 return; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5342 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
|
5343 if (change_cnt) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5344 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
|
5345 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5346 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5347 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5348 int one_change; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5349 int length; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5350 pos_T startpos; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5351 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5352 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
|
5353 (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
|
5354 return; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5355 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5356 pos = oap->start; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5357 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
|
5358 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5359 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
|
5360 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5361 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
|
5362 pos.col = bd.textcol; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5363 length = bd.textlen; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5364 } |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5365 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
|
5366 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5367 curwin->w_cursor.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5368 pos.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5369 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
|
5370 } |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5371 else /* oap->motion_type == MCHAR */ |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5372 { |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5373 if (!oap->inclusive) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5374 dec(&(oap->end)); |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5375 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
|
5376 pos.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5377 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
|
5378 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5379 pos.col += oap->start.col; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5380 length -= oap->start.col; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5381 } |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5382 if (pos.lnum == oap->end.lnum) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5383 { |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5384 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
|
5385 if (oap->end.col >= length) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5386 oap->end.col = length - 1; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5387 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
|
5388 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5389 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5390 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
|
5391 if (one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5392 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5393 /* 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
|
5394 if (change_cnt == 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5395 startpos = curbuf->b_op_start; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5396 ++change_cnt; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5397 } |
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 #ifdef FEAT_NETBEANS_INTG |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5400 if (netbeans_active() && one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5401 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5402 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
|
5403 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5404 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
|
5405 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
|
5406 &ptr[pos.col], length); |
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 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5409 if (g_cmd && one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5410 amount += Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5411 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5412 if (change_cnt) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5413 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
|
5414 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5415 if (!change_cnt && oap->is_VIsual) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5416 /* 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
|
5417 redraw_curbuf_later(INVERTED); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5418 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5419 /* 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
|
5420 * position from do_addsub(). */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5421 if (change_cnt > 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5422 curbuf->b_op_start = startpos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5423 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5424 if (change_cnt > p_report) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5425 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5426 if (change_cnt == 1) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5427 MSG(_("1 line changed")); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5428 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5429 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
|
5430 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5431 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5432 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5433 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5434 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5435 * 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
|
5436 * 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
|
5437 * |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5438 * 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
|
5439 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5440 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5441 do_addsub( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5442 int op_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5443 pos_T *pos, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5444 int length, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5445 linenr_T Prenum1) |
7 | 5446 { |
5447 int col; | |
5448 char_u *buf1; | |
5449 char_u buf2[NUMBUFLEN]; | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5450 int pre; /* 'X'/'x': hex; '0': octal; 'B'/'b': bin */ |
7 | 5451 static int hexupper = FALSE; /* 0xABC */ |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5452 uvarnumber_T n; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5453 uvarnumber_T oldn; |
7 | 5454 char_u *ptr; |
5455 int c; | |
5456 int todel; | |
5457 int dohex; | |
5458 int dooct; | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5459 int dobin; |
7 | 5460 int doalp; |
5461 int firstdigit; | |
5462 int subtract; | |
6868 | 5463 int negative = FALSE; |
6891 | 5464 int was_positive = TRUE; |
6868 | 5465 int visual = VIsual_active; |
6921 | 5466 int did_change = FALSE; |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5467 pos_T save_cursor = curwin->w_cursor; |
6927 | 5468 int maxlen = 0; |
7570
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5469 pos_T startpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5470 pos_T endpos; |
7 | 5471 |
5472 dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); /* "heX" */ | |
5473 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
|
5474 dobin = (vim_strchr(curbuf->b_p_nf, 'b') != NULL); /* "Bin" */ |
7 | 5475 doalp = (vim_strchr(curbuf->b_p_nf, 'p') != NULL); /* "alPha" */ |
5476 | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5477 curwin->w_cursor = *pos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5478 ptr = ml_get(pos->lnum); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5479 col = pos->col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5480 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5481 if (*ptr == NUL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5482 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5483 |
7 | 5484 /* |
5485 * First check if we are on a hexadecimal number, after the "0x". | |
5486 */ | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5487 if (!VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5488 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5489 if (dobin) |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5490 while (col > 0 && vim_isbdigit(ptr[col])) |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5491 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5492 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5493 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5494 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5495 col -= (*mb_head_off)(ptr, ptr + col); |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5496 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5497 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5498 |
6868 | 5499 if (dohex) |
5500 while (col > 0 && vim_isxdigit(ptr[col])) | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5501 { |
6868 | 5502 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5503 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5504 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5505 col -= (*mb_head_off)(ptr, ptr + col); |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5506 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5507 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5508 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5509 if ( dobin |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5510 && dohex |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5511 && ! ((col > 0 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5512 && (ptr[col] == 'X' |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5513 || ptr[col] == 'x') |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5514 && ptr[col - 1] == '0' |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5515 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5516 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5517 !(*mb_head_off)(ptr, ptr + col - 1)) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5518 #endif |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5519 && vim_isxdigit(ptr[col + 1])))) |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5520 { |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5521 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5522 /* 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
|
5523 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5524 col = pos->col; |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5525 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5526 while (col > 0 && vim_isdigit(ptr[col])) |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5527 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5528 col--; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5529 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5530 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5531 col -= (*mb_head_off)(ptr, ptr + col); |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5532 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5533 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5534 } |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5535 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5536 if (( dohex |
6868 | 5537 && col > 0 |
5538 && (ptr[col] == 'X' | |
5539 || ptr[col] == 'x') | |
5540 && ptr[col - 1] == '0' | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5541 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5542 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5543 !(*mb_head_off)(ptr, ptr + col - 1)) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5544 #endif |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5545 && vim_isxdigit(ptr[col + 1])) || |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5546 ( dobin |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5547 && col > 0 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5548 && (ptr[col] == 'B' |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5549 || ptr[col] == 'b') |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5550 && ptr[col - 1] == '0' |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5551 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5552 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5553 !(*mb_head_off)(ptr, ptr + col - 1)) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5554 #endif |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5555 && vim_isbdigit(ptr[col + 1]))) |
6868 | 5556 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5557 /* Found hexadecimal or binary number, move to its start. */ |
7 | 5558 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5559 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5560 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5561 col -= (*mb_head_off)(ptr, ptr + col); |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5562 #endif |
6868 | 5563 } |
5564 else | |
7 | 5565 { |
6868 | 5566 /* |
5567 * Search forward and then backward to find the start of number. | |
5568 */ | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5569 col = pos->col; |
6868 | 5570 |
5571 while (ptr[col] != NUL | |
5572 && !vim_isdigit(ptr[col]) | |
5573 && !(doalp && ASCII_ISALPHA(ptr[col]))) | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5574 col += MB_PTR2LEN(ptr + col); |
6868 | 5575 |
5576 while (col > 0 | |
5577 && vim_isdigit(ptr[col - 1]) | |
5578 && !(doalp && ASCII_ISALPHA(ptr[col]))) | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5579 { |
6868 | 5580 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5581 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5582 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5583 col -= (*mb_head_off)(ptr, ptr + col); |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5584 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5585 } |
6868 | 5586 } |
5587 } | |
5588 | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5589 if (visual) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5590 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5591 while (ptr[col] != NUL && length > 0 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5592 && !vim_isdigit(ptr[col]) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5593 && !(doalp && ASCII_ISALPHA(ptr[col]))) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5594 { |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5595 int mb_len = MB_PTR2LEN(ptr + col); |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5596 |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5597 col += mb_len; |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5598 length -= mb_len; |
7574
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 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5601 if (length == 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5602 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5603 |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5604 if (col > pos->col && ptr[col - 1] == '-' |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5605 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5606 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5607 !(*mb_head_off)(ptr, ptr + col - 1)) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5608 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5609 ) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5610 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5611 negative = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5612 was_positive = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5613 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5614 } |
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 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5617 * 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
|
5618 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5619 firstdigit = ptr[col]; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5620 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
|
5621 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5622 beep_flush(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5623 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5624 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5625 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5626 if (doalp && ASCII_ISALPHA(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5627 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5628 /* decrement or increment alphabetic character */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5629 if (op_type == OP_NR_SUB) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5630 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5631 if (CharOrd(firstdigit) < Prenum1) |
6927 | 5632 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5633 if (isupper(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5634 firstdigit = 'A'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5635 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5636 firstdigit = 'a'; |
6927 | 5637 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5638 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5639 #ifdef EBCDIC |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5640 firstdigit = EBCDIC_CHAR_ADD(firstdigit, -Prenum1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5641 #else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5642 firstdigit -= Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5643 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5644 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5645 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5646 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5647 if (26 - CharOrd(firstdigit) - 1 < Prenum1) |
6927 | 5648 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5649 if (isupper(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5650 firstdigit = 'Z'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5651 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5652 firstdigit = 'z'; |
6927 | 5653 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5654 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5655 #ifdef EBCDIC |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5656 firstdigit = EBCDIC_CHAR_ADD(firstdigit, Prenum1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5657 #else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5658 firstdigit += Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5659 #endif |
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 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5662 if (!did_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5663 startpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5664 did_change = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5665 (void)del_char(FALSE); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5666 ins_char(firstdigit); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5667 endpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5668 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5669 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5670 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5671 { |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5672 if (col > 0 && ptr[col - 1] == '-' |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5673 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5674 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5675 !(*mb_head_off)(ptr, ptr + col - 1)) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5676 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5677 && !visual) |
7574
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 /* negative number */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5680 --col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5681 negative = TRUE; |
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 /* get the number value (unsigned) */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5684 if (visual && VIsual_mode != 'V') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5685 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
|
5686 ? (int)STRLEN(ptr) - col |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5687 : length); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5688 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5689 vim_str2nr(ptr + col, &pre, &length, |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5690 0 + (dobin ? STR2NR_BIN : 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5691 + (dooct ? STR2NR_OCT : 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5692 + (dohex ? STR2NR_HEX : 0), |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5693 NULL, &n, maxlen); |
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 /* 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
|
5696 if (pre && negative) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5697 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5698 ++col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5699 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5700 negative = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5701 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5702 /* add or subtract */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5703 subtract = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5704 if (op_type == OP_NR_SUB) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5705 subtract ^= TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5706 if (negative) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5707 subtract ^= TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5708 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5709 oldn = n; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5710 if (subtract) |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5711 n -= (uvarnumber_T)Prenum1; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5712 else |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5713 n += (uvarnumber_T)Prenum1; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5714 /* handle wraparound for decimal numbers */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5715 if (!pre) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5716 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5717 if (subtract) |
6927 | 5718 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5719 if (n > oldn) |
6868 | 5720 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5721 n = 1 + (n ^ (uvarnumber_T)-1); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5722 negative ^= TRUE; |
6868 | 5723 } |
7 | 5724 } |
5725 else | |
6868 | 5726 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5727 /* add */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5728 if (n < oldn) |
6868 | 5729 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5730 n = (n ^ (uvarnumber_T)-1); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5731 negative ^= TRUE; |
6868 | 5732 } |
6927 | 5733 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5734 if (n == 0) |
6868 | 5735 negative = FALSE; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5736 } |
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 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
|
5739 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5740 /* need to remove the '-' */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5741 col--; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5742 length++; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5743 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5744 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5745 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5746 * Delete the old number. |
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 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5749 if (!did_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5750 startpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5751 did_change = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5752 todel = length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5753 c = gchar_cursor(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5754 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5755 * 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
|
5756 * 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
|
5757 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5758 if (c == '-') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5759 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5760 while (todel-- > 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5761 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5762 if (c < 0x100 && isalpha(c)) |
6868 | 5763 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5764 if (isupper(c)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5765 hexupper = TRUE; |
6868 | 5766 else |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5767 hexupper = FALSE; |
6891 | 5768 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5769 /* 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
|
5770 (void)del_char(FALSE); |
6868 | 5771 c = gchar_cursor(); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5772 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5773 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5774 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5775 * Prepare the leading characters in buf1[]. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5776 * 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
|
5777 * Allocate a bit too much. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5778 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5779 buf1 = alloc((unsigned)length + NUMBUFLEN); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5780 if (buf1 == NULL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5781 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5782 ptr = buf1; |
8989
e600e696c0a1
commit https://github.com/vim/vim/commit/dc633cf82758f67f656cda7fa8ccc30414ee53f8
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
5783 if (negative && (!visual || was_positive)) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5784 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5785 *ptr++ = '-'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5786 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5787 if (pre) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5788 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5789 *ptr++ = '0'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5790 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5791 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5792 if (pre == 'b' || pre == 'B' || |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5793 pre == 'x' || pre == 'X') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5794 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5795 *ptr++ = pre; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5796 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5797 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5798 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5799 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5800 * Put the number characters in buf2[]. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5801 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5802 if (pre == 'b' || pre == 'B') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5803 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5804 int i; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5805 int bit = 0; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5806 int bits = sizeof(uvarnumber_T) * 8; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5807 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5808 /* leading zeros */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5809 for (bit = bits; bit > 0; bit--) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5810 if ((n >> (bit - 1)) & 0x1) break; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5811 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5812 for (i = 0; bit > 0; bit--) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5813 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
|
5814 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5815 buf2[i] = '\0'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5816 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5817 else if (pre == 0) |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5818 vim_snprintf((char *)buf2, NUMBUFLEN, "%llu", n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5819 else if (pre == '0') |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5820 vim_snprintf((char *)buf2, NUMBUFLEN, "%llo", n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5821 else if (pre && hexupper) |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5822 vim_snprintf((char *)buf2, NUMBUFLEN, "%llX", n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5823 else |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5824 vim_snprintf((char *)buf2, NUMBUFLEN, "%llx", n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5825 length -= (int)STRLEN(buf2); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5826 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5827 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5828 * 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
|
5829 * 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
|
5830 * Don't do this when |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5831 * 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
|
5832 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5833 if (firstdigit == '0' && !(dooct && pre == 0)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5834 while (length-- > 0) |
6868 | 5835 *ptr++ = '0'; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5836 *ptr = NUL; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5837 STRCAT(buf1, buf2); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5838 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
|
5839 vim_free(buf1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5840 endpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5841 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
|
5842 --curwin->w_cursor.col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5843 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5844 |
7570
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5845 if (did_change) |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5846 { |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5847 /* set the '[ and '] marks */ |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5848 curbuf->b_op_start = startpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5849 curbuf->b_op_end = endpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5850 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
|
5851 --curbuf->b_op_end.col; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5852 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5853 |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5854 theend: |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5855 if (visual) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5856 curwin->w_cursor = save_cursor; |
8690
6a1becf4f282
commit https://github.com/vim/vim/commit/8e08125d3a9afd0b16cd84454ae9ddad0abaaab0
Christian Brabandt <cb@256bit.org>
parents:
8399
diff
changeset
|
5857 else if (did_change) |
6a1becf4f282
commit https://github.com/vim/vim/commit/8e08125d3a9afd0b16cd84454ae9ddad0abaaab0
Christian Brabandt <cb@256bit.org>
parents:
8399
diff
changeset
|
5858 curwin->w_set_curswant = TRUE; |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5859 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5860 return did_change; |
7 | 5861 } |
5862 | |
5863 #ifdef FEAT_VIMINFO | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5864 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5865 static yankreg_T *y_read_regs = NULL; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5866 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5867 #define REG_PREVIOUS 1 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5868 #define REG_EXEC 2 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5869 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5870 /* |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5871 * Prepare for reading viminfo registers when writing viminfo later. |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5872 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5873 void |
9282
9f97a6290c63
commit https://github.com/vim/vim/commit/cf089463492fab53b2a5d81517829d22f882f82e
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
5874 prepare_viminfo_registers(void) |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5875 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5876 y_read_regs = (yankreg_T *)alloc_clear(NUM_REGISTERS |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5877 * (int)sizeof(yankreg_T)); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5878 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5879 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5880 void |
9282
9f97a6290c63
commit https://github.com/vim/vim/commit/cf089463492fab53b2a5d81517829d22f882f82e
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
5881 finish_viminfo_registers(void) |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5882 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5883 int i; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5884 int j; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5885 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5886 if (y_read_regs != NULL) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5887 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5888 for (i = 0; i < NUM_REGISTERS; ++i) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5889 if (y_read_regs[i].y_array != NULL) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5890 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5891 for (j = 0; j < y_read_regs[i].y_size; j++) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5892 vim_free(y_read_regs[i].y_array[j]); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5893 vim_free(y_read_regs[i].y_array); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5894 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5895 vim_free(y_read_regs); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5896 y_read_regs = NULL; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5897 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5898 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5899 |
7 | 5900 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5901 read_viminfo_register(vir_T *virp, int force) |
7 | 5902 { |
5903 int eof; | |
5904 int do_it = TRUE; | |
5905 int size; | |
5906 int limit; | |
5907 int i; | |
5908 int set_prev = FALSE; | |
5909 char_u *str; | |
5910 char_u **array = NULL; | |
6508 | 5911 int new_type = MCHAR; /* init to shut up compiler */ |
5912 colnr_T new_width = 0; /* init to shut up compiler */ | |
7 | 5913 |
5914 /* We only get here (hopefully) if line[0] == '"' */ | |
5915 str = virp->vir_line + 1; | |
1893 | 5916 |
5917 /* If the line starts with "" this is the y_previous register. */ | |
7 | 5918 if (*str == '"') |
5919 { | |
5920 set_prev = TRUE; | |
5921 str++; | |
5922 } | |
1893 | 5923 |
7 | 5924 if (!ASCII_ISALNUM(*str) && *str != '-') |
5925 { | |
5926 if (viminfo_error("E577: ", _("Illegal register name"), virp->vir_line)) | |
5927 return TRUE; /* too many errors, pretend end-of-file */ | |
5928 do_it = FALSE; | |
5929 } | |
5930 get_yank_register(*str++, FALSE); | |
5931 if (!force && y_current->y_array != NULL) | |
5932 do_it = FALSE; | |
1893 | 5933 |
5934 if (*str == '@') | |
5935 { | |
5936 /* "x@: register x used for @@ */ | |
5937 if (force || execreg_lastc == NUL) | |
5938 execreg_lastc = str[-1]; | |
5939 } | |
5940 | |
7 | 5941 size = 0; |
5942 limit = 100; /* Optimized for registers containing <= 100 lines */ | |
5943 if (do_it) | |
5944 { | |
6462 | 5945 /* |
5946 * Build the new register in array[]. | |
5947 * y_array is kept as-is until done. | |
5948 * The "do_it" flag is reset when something is wrong, in which case | |
5949 * array[] needs to be freed. | |
5950 */ | |
7 | 5951 if (set_prev) |
5952 y_previous = y_current; | |
6462 | 5953 array = (char_u **)alloc((unsigned)(limit * sizeof(char_u *))); |
1893 | 5954 str = skipwhite(skiptowhite(str)); |
7 | 5955 if (STRNCMP(str, "CHAR", 4) == 0) |
6462 | 5956 new_type = MCHAR; |
7 | 5957 else if (STRNCMP(str, "BLOCK", 5) == 0) |
6462 | 5958 new_type = MBLOCK; |
7 | 5959 else |
6462 | 5960 new_type = MLINE; |
7 | 5961 /* get the block width; if it's missing we get a zero, which is OK */ |
5962 str = skipwhite(skiptowhite(str)); | |
6462 | 5963 new_width = getdigits(&str); |
7 | 5964 } |
5965 | |
5966 while (!(eof = viminfo_readline(virp)) | |
5967 && (virp->vir_line[0] == TAB || virp->vir_line[0] == '<')) | |
5968 { | |
5969 if (do_it) | |
5970 { | |
6462 | 5971 if (size == limit) |
7 | 5972 { |
6462 | 5973 char_u **new_array = (char_u **) |
7 | 5974 alloc((unsigned)(limit * 2 * sizeof(char_u *))); |
6462 | 5975 |
5976 if (new_array == NULL) | |
5977 { | |
5978 do_it = FALSE; | |
5979 break; | |
5980 } | |
7 | 5981 for (i = 0; i < limit; i++) |
6462 | 5982 new_array[i] = array[i]; |
7 | 5983 vim_free(array); |
6462 | 5984 array = new_array; |
7 | 5985 limit *= 2; |
5986 } | |
5987 str = viminfo_readstring(virp, 1, TRUE); | |
5988 if (str != NULL) | |
5989 array[size++] = str; | |
5990 else | |
6462 | 5991 /* error, don't store the result */ |
7 | 5992 do_it = FALSE; |
5993 } | |
5994 } | |
6508 | 5995 |
7 | 5996 if (do_it) |
5997 { | |
6462 | 5998 /* free y_array[] */ |
5999 for (i = 0; i < y_current->y_size; i++) | |
6000 vim_free(y_current->y_array[i]); | |
6001 vim_free(y_current->y_array); | |
6002 | |
6003 y_current->y_type = new_type; | |
6004 y_current->y_width = new_width; | |
6005 y_current->y_size = size; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6006 y_current->y_time_set = 0; |
7 | 6007 if (size == 0) |
6008 { | |
6009 y_current->y_array = NULL; | |
6010 } | |
6462 | 6011 else |
7 | 6012 { |
6462 | 6013 /* Move the lines from array[] to y_array[]. */ |
7 | 6014 y_current->y_array = |
6015 (char_u **)alloc((unsigned)(size * sizeof(char_u *))); | |
6016 for (i = 0; i < size; i++) | |
6462 | 6017 { |
6018 if (y_current->y_array == NULL) | |
6019 vim_free(array[i]); | |
6020 else | |
6021 y_current->y_array[i] = array[i]; | |
6022 } | |
7 | 6023 } |
6462 | 6024 } |
6025 else | |
6026 { | |
6027 /* Free array[] if it was filled. */ | |
6028 for (i = 0; i < size; i++) | |
6029 vim_free(array[i]); | |
6030 } | |
6031 vim_free(array); | |
6032 | |
7 | 6033 return eof; |
6034 } | |
6035 | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6036 /* |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6037 * Accept a new style register line from the viminfo, store it when it's new. |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6038 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6039 void |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6040 handle_viminfo_register(garray_T *values, int force) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6041 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6042 bval_T *vp = (bval_T *)values->ga_data; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6043 int flags; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6044 int name; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6045 int type; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6046 int linecount; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6047 int width; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6048 time_t timestamp; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6049 yankreg_T *y_ptr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6050 int i; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6051 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6052 /* Check the format: |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6053 * |{bartype},{flags},{name},{type}, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6054 * {linecount},{width},{timestamp},"line1","line2" |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6055 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6056 if (values->ga_len < 6 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6057 || vp[0].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6058 || vp[1].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6059 || vp[2].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6060 || vp[3].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6061 || vp[4].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6062 || vp[5].bv_type != BVAL_NR) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6063 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6064 flags = vp[0].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6065 name = vp[1].bv_nr; |
9307
eb52a2670c96
commit https://github.com/vim/vim/commit/67e3720a9ddd8a9d2e8344358c28fa1f4196db0d
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
6066 if (name < 0 || name >= NUM_REGISTERS) |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6067 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6068 type = vp[2].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6069 if (type != MCHAR && type != MLINE && type != MBLOCK) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6070 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6071 linecount = vp[3].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6072 if (values->ga_len < 6 + linecount) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6073 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6074 width = vp[4].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6075 if (width < 0) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6076 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6077 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6078 if (y_read_regs != NULL) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6079 /* Reading viminfo for merging and writing. Store the register |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6080 * content, don't update the current registers. */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6081 y_ptr = &y_read_regs[name]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6082 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6083 y_ptr = &y_regs[name]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6084 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6085 /* Do not overwrite unless forced or the timestamp is newer. */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6086 timestamp = (time_t)vp[5].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6087 if (y_ptr->y_array != NULL && !force |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6088 && (timestamp == 0 || y_ptr->y_time_set > timestamp)) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6089 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6090 |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
6091 if (y_ptr->y_array != NULL) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
6092 for (i = 0; i < y_ptr->y_size; i++) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
6093 vim_free(y_ptr->y_array[i]); |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6094 vim_free(y_ptr->y_array); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6095 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6096 if (y_read_regs == NULL) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6097 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6098 if (flags & REG_PREVIOUS) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6099 y_previous = y_ptr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6100 if ((flags & REG_EXEC) && (force || execreg_lastc == NUL)) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6101 execreg_lastc = get_register_name(name); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6102 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6103 y_ptr->y_type = type; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6104 y_ptr->y_width = width; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6105 y_ptr->y_size = linecount; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6106 y_ptr->y_time_set = timestamp; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6107 if (linecount == 0) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6108 y_ptr->y_array = NULL; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6109 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6110 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6111 y_ptr->y_array = |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6112 (char_u **)alloc((unsigned)(linecount * sizeof(char_u *))); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6113 for (i = 0; i < linecount; i++) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6114 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6115 if (vp[i + 6].bv_allocated) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6116 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6117 y_ptr->y_array[i] = vp[i + 6].bv_string; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6118 vp[i + 6].bv_string = NULL; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6119 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6120 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6121 y_ptr->y_array[i] = vim_strsave(vp[i + 6].bv_string); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6122 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6123 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6124 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6125 |
7 | 6126 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6127 write_viminfo_registers(FILE *fp) |
7 | 6128 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6129 int i, j; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6130 char_u *type; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6131 char_u c; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6132 int num_lines; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6133 int max_num_lines; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6134 int max_kbyte; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6135 long len; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6136 yankreg_T *y_ptr; |
7 | 6137 |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
6138 fputs(_("\n# Registers:\n"), fp); |
7 | 6139 |
6140 /* Get '<' value, use old '"' value if '<' is not found. */ | |
6141 max_num_lines = get_viminfo_parameter('<'); | |
6142 if (max_num_lines < 0) | |
6143 max_num_lines = get_viminfo_parameter('"'); | |
6144 if (max_num_lines == 0) | |
6145 return; | |
6146 max_kbyte = get_viminfo_parameter('s'); | |
6147 if (max_kbyte == 0) | |
6148 return; | |
1893 | 6149 |
7 | 6150 for (i = 0; i < NUM_REGISTERS; i++) |
6151 { | |
6152 #ifdef FEAT_CLIPBOARD | |
6153 /* Skip '*'/'+' register, we don't want them back next time */ | |
6154 if (i == STAR_REGISTER || i == PLUS_REGISTER) | |
6155 continue; | |
6156 #endif | |
6157 #ifdef FEAT_DND | |
6158 /* Neither do we want the '~' register */ | |
6159 if (i == TILDE_REGISTER) | |
6160 continue; | |
6161 #endif | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6162 /* When reading viminfo for merging and writing: Use the register from |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6163 * viminfo if it's newer. */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6164 if (y_read_regs != NULL |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6165 && y_read_regs[i].y_array != NULL |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6166 && (y_regs[i].y_array == NULL || |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6167 y_read_regs[i].y_time_set > y_regs[i].y_time_set)) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6168 y_ptr = &y_read_regs[i]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6169 else if (y_regs[i].y_array == NULL) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6170 continue; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6171 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6172 y_ptr = &y_regs[i]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6173 |
55 | 6174 /* Skip empty registers. */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6175 num_lines = y_ptr->y_size; |
55 | 6176 if (num_lines == 0 |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6177 || (num_lines == 1 && y_ptr->y_type == MCHAR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6178 && *y_ptr->y_array[0] == NUL)) |
55 | 6179 continue; |
6180 | |
7 | 6181 if (max_kbyte > 0) |
6182 { | |
6183 /* Skip register if there is more text than the maximum size. */ | |
6184 len = 0; | |
6185 for (j = 0; j < num_lines; j++) | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6186 len += (long)STRLEN(y_ptr->y_array[j]) + 1L; |
7 | 6187 if (len > (long)max_kbyte * 1024L) |
6188 continue; | |
6189 } | |
6190 | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6191 switch (y_ptr->y_type) |
7 | 6192 { |
6193 case MLINE: | |
6194 type = (char_u *)"LINE"; | |
6195 break; | |
6196 case MCHAR: | |
6197 type = (char_u *)"CHAR"; | |
6198 break; | |
6199 case MBLOCK: | |
6200 type = (char_u *)"BLOCK"; | |
6201 break; | |
6202 default: | |
6203 sprintf((char *)IObuff, _("E574: Unknown register type %d"), | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6204 y_ptr->y_type); |
7 | 6205 emsg(IObuff); |
6206 type = (char_u *)"LINE"; | |
6207 break; | |
6208 } | |
6209 if (y_previous == &y_regs[i]) | |
6210 fprintf(fp, "\""); | |
6211 c = get_register_name(i); | |
1893 | 6212 fprintf(fp, "\"%c", c); |
6213 if (c == execreg_lastc) | |
6214 fprintf(fp, "@"); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6215 fprintf(fp, "\t%s\t%d\n", type, (int)y_ptr->y_width); |
7 | 6216 |
6217 /* If max_num_lines < 0, then we save ALL the lines in the register */ | |
6218 if (max_num_lines > 0 && num_lines > max_num_lines) | |
6219 num_lines = max_num_lines; | |
6220 for (j = 0; j < num_lines; j++) | |
6221 { | |
6222 putc('\t', fp); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6223 viminfo_writestring(fp, y_ptr->y_array[j]); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6224 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6225 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6226 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6227 int flags = 0; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6228 int remaining; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6229 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6230 /* New style with a bar line. Format: |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6231 * |{bartype},{flags},{name},{type}, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6232 * {linecount},{width},{timestamp},"line1","line2" |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6233 * flags: REG_PREVIOUS - register is y_previous |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6234 * REG_EXEC - used for @@ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6235 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6236 if (y_previous == &y_regs[i]) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6237 flags |= REG_PREVIOUS; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6238 if (c == execreg_lastc) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6239 flags |= REG_EXEC; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6240 fprintf(fp, "|%d,%d,%d,%d,%d,%d,%ld", BARTYPE_REGISTER, flags, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6241 i, y_ptr->y_type, num_lines, (int)y_ptr->y_width, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6242 (long)y_ptr->y_time_set); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6243 /* 11 chars for type/flags/name/type, 3 * 20 for numbers */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6244 remaining = LSIZE - 71; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6245 for (j = 0; j < num_lines; j++) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6246 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6247 putc(',', fp); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6248 --remaining; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6249 remaining = barline_writestring(fp, y_ptr->y_array[j], |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6250 remaining); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6251 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6252 putc('\n', fp); |
7 | 6253 } |
6254 } | |
6255 } | |
6256 #endif /* FEAT_VIMINFO */ | |
6257 | |
6258 #if defined(FEAT_CLIPBOARD) || defined(PROTO) | |
6259 /* | |
6260 * SELECTION / PRIMARY ('*') | |
6261 * | |
6262 * Text selection stuff that uses the GUI selection register '*'. When using a | |
6263 * GUI this may be text from another window, otherwise it is the last text we | |
6264 * had highlighted with VIsual mode. With mouse support, clicking the middle | |
6265 * button performs the paste, otherwise you will need to do <"*p>. " | |
6266 * If not under X, it is synonymous with the clipboard register '+'. | |
6267 * | |
6268 * X CLIPBOARD ('+') | |
6269 * | |
6270 * Text selection stuff that uses the GUI clipboard register '+'. | |
6271 * Under X, this matches the standard cut/paste buffer CLIPBOARD selection. | |
6272 * It will be used for unnamed cut/pasting is 'clipboard' contains "unnamed", | |
6273 * otherwise you will need to do <"+p>. " | |
6274 * If not under X, it is synonymous with the selection register '*'. | |
6275 */ | |
6276 | |
6277 /* | |
6278 * Routine to export any final X selection we had to the environment | |
6279 * so that the text is still available after vim has exited. X selections | |
6280 * only exist while the owning application exists, so we write to the | |
6281 * permanent (while X runs) store CUT_BUFFER0. | |
6282 * Dump the CLIPBOARD selection if we own it (it's logically the more | |
6283 * 'permanent' of the two), otherwise the PRIMARY one. | |
6284 * For now, use a hard-coded sanity limit of 1Mb of data. | |
6285 */ | |
6286 #if defined(FEAT_X11) && defined(FEAT_CLIPBOARD) | |
6287 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6288 x11_export_final_selection(void) |
7 | 6289 { |
6290 Display *dpy; | |
6291 char_u *str = NULL; | |
6292 long_u len = 0; | |
6293 int motion_type = -1; | |
6294 | |
6295 # ifdef FEAT_GUI | |
6296 if (gui.in_use) | |
6297 dpy = X_DISPLAY; | |
6298 else | |
6299 # endif | |
6300 # ifdef FEAT_XCLIPBOARD | |
6301 dpy = xterm_dpy; | |
6302 # else | |
6303 return; | |
6304 # endif | |
6305 | |
6306 /* Get selection to export */ | |
6307 if (clip_plus.owned) | |
6308 motion_type = clip_convert_selection(&str, &len, &clip_plus); | |
6309 else if (clip_star.owned) | |
6310 motion_type = clip_convert_selection(&str, &len, &clip_star); | |
6311 | |
6312 /* Check it's OK */ | |
6313 if (dpy != NULL && str != NULL && motion_type >= 0 | |
6314 && len < 1024*1024 && len > 0) | |
6315 { | |
1924 | 6316 #ifdef FEAT_MBYTE |
4201 | 6317 int ok = TRUE; |
6318 | |
1924 | 6319 /* The CUT_BUFFER0 is supposed to always contain latin1. Convert from |
6320 * 'enc' when it is a multi-byte encoding. When 'enc' is an 8-bit | |
6321 * encoding conversion usually doesn't work, so keep the text as-is. | |
6322 */ | |
6323 if (has_mbyte) | |
6324 { | |
6325 vimconv_T vc; | |
6326 | |
6327 vc.vc_type = CONV_NONE; | |
6328 if (convert_setup(&vc, p_enc, (char_u *)"latin1") == OK) | |
6329 { | |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2007
diff
changeset
|
6330 int intlen = len; |
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2007
diff
changeset
|
6331 char_u *conv_str; |
2007 | 6332 |
4201 | 6333 vc.vc_fail = TRUE; |
2007 | 6334 conv_str = string_convert(&vc, str, &intlen); |
6335 len = intlen; | |
1924 | 6336 if (conv_str != NULL) |
6337 { | |
6338 vim_free(str); | |
6339 str = conv_str; | |
6340 } | |
4201 | 6341 else |
6342 { | |
6343 ok = FALSE; | |
6344 } | |
1924 | 6345 convert_setup(&vc, NULL, NULL); |
6346 } | |
4201 | 6347 else |
6348 { | |
6349 ok = FALSE; | |
6350 } | |
1924 | 6351 } |
4201 | 6352 |
6353 /* Do not store the string if conversion failed. Better to use any | |
6354 * other selection than garbled text. */ | |
6355 if (ok) | |
6356 #endif | |
6357 { | |
6358 XStoreBuffer(dpy, (char *)str, (int)len, 0); | |
6359 XFlush(dpy); | |
6360 } | |
7 | 6361 } |
6362 | |
6363 vim_free(str); | |
6364 } | |
6365 #endif | |
6366 | |
6367 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6368 clip_free_selection(VimClipboard *cbd) |
7 | 6369 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6370 yankreg_T *y_ptr = y_current; |
7 | 6371 |
6372 if (cbd == &clip_plus) | |
6373 y_current = &y_regs[PLUS_REGISTER]; | |
6374 else | |
6375 y_current = &y_regs[STAR_REGISTER]; | |
6376 free_yank_all(); | |
6377 y_current->y_size = 0; | |
6378 y_current = y_ptr; | |
6379 } | |
6380 | |
6381 /* | |
6382 * Get the selected text and put it in the gui selection register '*' or '+'. | |
6383 */ | |
6384 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6385 clip_get_selection(VimClipboard *cbd) |
7 | 6386 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6387 yankreg_T *old_y_previous, *old_y_current; |
7 | 6388 pos_T old_cursor; |
6389 pos_T old_visual; | |
6390 int old_visual_mode; | |
6391 colnr_T old_curswant; | |
6392 int old_set_curswant; | |
6393 pos_T old_op_start, old_op_end; | |
6394 oparg_T oa; | |
6395 cmdarg_T ca; | |
6396 | |
6397 if (cbd->owned) | |
6398 { | |
6399 if ((cbd == &clip_plus && y_regs[PLUS_REGISTER].y_array != NULL) | |
6400 || (cbd == &clip_star && y_regs[STAR_REGISTER].y_array != NULL)) | |
6401 return; | |
6402 | |
6403 /* Get the text between clip_star.start & clip_star.end */ | |
6404 old_y_previous = y_previous; | |
6405 old_y_current = y_current; | |
6406 old_cursor = curwin->w_cursor; | |
6407 old_curswant = curwin->w_curswant; | |
6408 old_set_curswant = curwin->w_set_curswant; | |
6409 old_op_start = curbuf->b_op_start; | |
6410 old_op_end = curbuf->b_op_end; | |
6411 old_visual = VIsual; | |
6412 old_visual_mode = VIsual_mode; | |
6413 clear_oparg(&oa); | |
6414 oa.regname = (cbd == &clip_plus ? '+' : '*'); | |
6415 oa.op_type = OP_YANK; | |
6416 vim_memset(&ca, 0, sizeof(ca)); | |
6417 ca.oap = &oa; | |
6418 ca.cmdchar = 'y'; | |
6419 ca.count1 = 1; | |
6420 ca.retval = CA_NO_ADJ_OP_END; | |
6421 do_pending_operator(&ca, 0, TRUE); | |
6422 y_previous = old_y_previous; | |
6423 y_current = old_y_current; | |
6424 curwin->w_cursor = old_cursor; | |
688 | 6425 changed_cline_bef_curs(); /* need to update w_virtcol et al */ |
7 | 6426 curwin->w_curswant = old_curswant; |
6427 curwin->w_set_curswant = old_set_curswant; | |
6428 curbuf->b_op_start = old_op_start; | |
6429 curbuf->b_op_end = old_op_end; | |
6430 VIsual = old_visual; | |
6431 VIsual_mode = old_visual_mode; | |
6432 } | |
6433 else | |
6434 { | |
6435 clip_free_selection(cbd); | |
6436 | |
6437 /* Try to get selected text from another window */ | |
6438 clip_gen_request_selection(cbd); | |
6439 } | |
6440 } | |
6441 | |
2896 | 6442 /* |
6443 * Convert from the GUI selection string into the '*'/'+' register. | |
6444 */ | |
7 | 6445 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6446 clip_yank_selection( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6447 int type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6448 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6449 long len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6450 VimClipboard *cbd) |
7 | 6451 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6452 yankreg_T *y_ptr; |
7 | 6453 |
6454 if (cbd == &clip_plus) | |
6455 y_ptr = &y_regs[PLUS_REGISTER]; | |
6456 else | |
6457 y_ptr = &y_regs[STAR_REGISTER]; | |
6458 | |
6459 clip_free_selection(cbd); | |
6460 | |
5798 | 6461 str_to_reg(y_ptr, type, str, len, 0L, FALSE); |
7 | 6462 } |
6463 | |
6464 /* | |
6465 * Convert the '*'/'+' register into a GUI selection string returned in *str | |
6466 * with length *len. | |
6467 * Returns the motion type, or -1 for failure. | |
6468 */ | |
6469 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6470 clip_convert_selection(char_u **str, long_u *len, VimClipboard *cbd) |
7 | 6471 { |
6472 char_u *p; | |
6473 int lnum; | |
6474 int i, j; | |
6475 int_u eolsize; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6476 yankreg_T *y_ptr; |
7 | 6477 |
6478 if (cbd == &clip_plus) | |
6479 y_ptr = &y_regs[PLUS_REGISTER]; | |
6480 else | |
6481 y_ptr = &y_regs[STAR_REGISTER]; | |
6482 | |
6483 #ifdef USE_CRNL | |
6484 eolsize = 2; | |
6485 #else | |
6486 eolsize = 1; | |
6487 #endif | |
6488 | |
6489 *str = NULL; | |
6490 *len = 0; | |
6491 if (y_ptr->y_array == NULL) | |
6492 return -1; | |
6493 | |
6494 for (i = 0; i < y_ptr->y_size; i++) | |
6495 *len += (long_u)STRLEN(y_ptr->y_array[i]) + eolsize; | |
6496 | |
6497 /* | |
6498 * Don't want newline character at end of last line if we're in MCHAR mode. | |
6499 */ | |
6500 if (y_ptr->y_type == MCHAR && *len >= eolsize) | |
6501 *len -= eolsize; | |
6502 | |
6503 p = *str = lalloc(*len + 1, TRUE); /* add one to avoid zero */ | |
6504 if (p == NULL) | |
6505 return -1; | |
6506 lnum = 0; | |
6507 for (i = 0, j = 0; i < (int)*len; i++, j++) | |
6508 { | |
6509 if (y_ptr->y_array[lnum][j] == '\n') | |
6510 p[i] = NUL; | |
6511 else if (y_ptr->y_array[lnum][j] == NUL) | |
6512 { | |
6513 #ifdef USE_CRNL | |
6514 p[i++] = '\r'; | |
6515 #endif | |
6516 #ifdef USE_CR | |
6517 p[i] = '\r'; | |
6518 #else | |
6519 p[i] = '\n'; | |
6520 #endif | |
6521 lnum++; | |
6522 j = -1; | |
6523 } | |
6524 else | |
6525 p[i] = y_ptr->y_array[lnum][j]; | |
6526 } | |
6527 return y_ptr->y_type; | |
6528 } | |
6529 | |
6530 | |
6531 /* | |
6532 * If we have written to a clipboard register, send the text to the clipboard. | |
6533 */ | |
6534 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6535 may_set_selection(void) |
7 | 6536 { |
6537 if (y_current == &(y_regs[STAR_REGISTER]) && clip_star.available) | |
6538 { | |
6539 clip_own_selection(&clip_star); | |
6540 clip_gen_set_selection(&clip_star); | |
6541 } | |
6542 else if (y_current == &(y_regs[PLUS_REGISTER]) && clip_plus.available) | |
6543 { | |
6544 clip_own_selection(&clip_plus); | |
6545 clip_gen_set_selection(&clip_plus); | |
6546 } | |
6547 } | |
6548 | |
6549 #endif /* FEAT_CLIPBOARD || PROTO */ | |
6550 | |
6551 | |
6552 #if defined(FEAT_DND) || defined(PROTO) | |
6553 /* | |
6554 * Replace the contents of the '~' register with str. | |
6555 */ | |
6556 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6557 dnd_yank_drag_data(char_u *str, long len) |
7 | 6558 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6559 yankreg_T *curr; |
7 | 6560 |
6561 curr = y_current; | |
6562 y_current = &y_regs[TILDE_REGISTER]; | |
6563 free_yank_all(); | |
5798 | 6564 str_to_reg(y_current, MCHAR, str, len, 0L, FALSE); |
7 | 6565 y_current = curr; |
6566 } | |
6567 #endif | |
6568 | |
6569 | |
6570 #if defined(FEAT_EVAL) || defined(PROTO) | |
6571 /* | |
6572 * Return the type of a register. | |
6573 * Used for getregtype() | |
6574 * Returns MAUTO for error. | |
6575 */ | |
6576 char_u | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6577 get_reg_type(int regname, long *reglen) |
7 | 6578 { |
6579 switch (regname) | |
6580 { | |
6581 case '%': /* file name */ | |
6582 case '#': /* alternate file name */ | |
6583 case '=': /* expression */ | |
6584 case ':': /* last command line */ | |
6585 case '/': /* last search-pattern */ | |
6586 case '.': /* last inserted text */ | |
6587 #ifdef FEAT_SEARCHPATH | |
6588 case Ctrl_F: /* Filename under cursor */ | |
6589 case Ctrl_P: /* Path under cursor, expand via "path" */ | |
6590 #endif | |
6591 case Ctrl_W: /* word under cursor */ | |
6592 case Ctrl_A: /* WORD (mnemonic All) under cursor */ | |
6593 case '_': /* black hole: always empty */ | |
6594 return MCHAR; | |
6595 } | |
6596 | |
6597 #ifdef FEAT_CLIPBOARD | |
6598 regname = may_get_selection(regname); | |
6599 #endif | |
6600 | |
5596 | 6601 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
|
6602 return MAUTO; |
5596 | 6603 |
7 | 6604 get_yank_register(regname, FALSE); |
6605 | |
6606 if (y_current->y_array != NULL) | |
6607 { | |
6608 if (reglen != NULL && y_current->y_type == MBLOCK) | |
6609 *reglen = y_current->y_width; | |
6610 return y_current->y_type; | |
6611 } | |
6612 return MAUTO; | |
6613 } | |
6614 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
6615 static char_u *getreg_wrap_one_line(char_u *s, int flags); |
5796 | 6616 |
6617 /* | |
6618 * When "flags" has GREG_LIST return a list with text "s". | |
6619 * Otherwise just return "s". | |
6620 */ | |
6621 static char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6622 getreg_wrap_one_line(char_u *s, int flags) |
5796 | 6623 { |
6624 if (flags & GREG_LIST) | |
6625 { | |
6626 list_T *list = list_alloc(); | |
6627 | |
6628 if (list != NULL) | |
6629 { | |
6630 if (list_append_string(list, NULL, -1) == FAIL) | |
6631 { | |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8690
diff
changeset
|
6632 list_free(list); |
5796 | 6633 return NULL; |
6634 } | |
6635 list->lv_first->li_tv.vval.v_string = s; | |
6636 } | |
6637 return (char_u *)list; | |
6638 } | |
6639 return s; | |
6640 } | |
6641 | |
7 | 6642 /* |
6643 * Return the contents of a register as a single allocated string. | |
6644 * Used for "@r" in expressions and for getreg(). | |
6645 * Returns NULL for error. | |
5796 | 6646 * Flags: |
6647 * GREG_NO_EXPR Do not allow expression register | |
6648 * GREG_EXPR_SRC For the expression register: return expression itself, | |
6649 * not the result of its evaluation. | |
6650 * GREG_LIST Return a list of lines in place of a single string. | |
7 | 6651 */ |
6652 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6653 get_reg_contents(int regname, int flags) |
7 | 6654 { |
6655 long i; | |
6656 char_u *retval; | |
6657 int allocated; | |
6658 long len; | |
6659 | |
6660 /* Don't allow using an expression register inside an expression */ | |
6661 if (regname == '=') | |
6662 { | |
5796 | 6663 if (flags & GREG_NO_EXPR) |
6664 return NULL; | |
6665 if (flags & GREG_EXPR_SRC) | |
6666 return getreg_wrap_one_line(get_expr_line_src(), flags); | |
6667 return getreg_wrap_one_line(get_expr_line(), flags); | |
7 | 6668 } |
6669 | |
6670 if (regname == '@') /* "@@" is used for unnamed register */ | |
6671 regname = '"'; | |
6672 | |
6673 /* check for valid regname */ | |
6674 if (regname != NUL && !valid_yank_reg(regname, FALSE)) | |
6675 return NULL; | |
6676 | |
6677 #ifdef FEAT_CLIPBOARD | |
6678 regname = may_get_selection(regname); | |
6679 #endif | |
6680 | |
6681 if (get_spec_reg(regname, &retval, &allocated, FALSE)) | |
6682 { | |
6683 if (retval == NULL) | |
6684 return NULL; | |
5796 | 6685 if (allocated) |
6686 return getreg_wrap_one_line(retval, flags); | |
6687 return getreg_wrap_one_line(vim_strsave(retval), flags); | |
7 | 6688 } |
6689 | |
6690 get_yank_register(regname, FALSE); | |
6691 if (y_current->y_array == NULL) | |
6692 return NULL; | |
6693 | |
5796 | 6694 if (flags & GREG_LIST) |
6695 { | |
6696 list_T *list = list_alloc(); | |
6697 int error = FALSE; | |
6698 | |
6699 if (list == NULL) | |
6700 return NULL; | |
6701 for (i = 0; i < y_current->y_size; ++i) | |
6702 if (list_append_string(list, y_current->y_array[i], -1) == FAIL) | |
6703 error = TRUE; | |
6704 if (error) | |
6705 { | |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8690
diff
changeset
|
6706 list_free(list); |
5796 | 6707 return NULL; |
6708 } | |
6709 return (char_u *)list; | |
6710 } | |
6711 | |
7 | 6712 /* |
6713 * Compute length of resulting string. | |
6714 */ | |
6715 len = 0; | |
6716 for (i = 0; i < y_current->y_size; ++i) | |
6717 { | |
6718 len += (long)STRLEN(y_current->y_array[i]); | |
6719 /* | |
6720 * Insert a newline between lines and after last line if | |
6721 * y_type is MLINE. | |
6722 */ | |
6723 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | |
6724 ++len; | |
6725 } | |
6726 | |
6727 retval = lalloc(len + 1, TRUE); | |
6728 | |
6729 /* | |
6730 * Copy the lines of the yank register into the string. | |
6731 */ | |
6732 if (retval != NULL) | |
6733 { | |
6734 len = 0; | |
6735 for (i = 0; i < y_current->y_size; ++i) | |
6736 { | |
6737 STRCPY(retval + len, y_current->y_array[i]); | |
6738 len += (long)STRLEN(retval + len); | |
6739 | |
6740 /* | |
6741 * Insert a NL between lines and after the last line if y_type is | |
6742 * MLINE. | |
6743 */ | |
6744 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | |
6745 retval[len++] = '\n'; | |
6746 } | |
6747 retval[len] = NUL; | |
6748 } | |
6749 | |
6750 return retval; | |
6751 } | |
6752 | |
5798 | 6753 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6754 init_write_reg( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6755 int name, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6756 yankreg_T **old_y_previous, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6757 yankreg_T **old_y_current, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6758 int must_append, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6759 int *yank_type UNUSED) |
5798 | 6760 { |
6761 if (!valid_yank_reg(name, TRUE)) /* check for valid reg name */ | |
6762 { | |
6763 emsg_invreg(name); | |
6764 return FAIL; | |
6765 } | |
6766 | |
6767 /* Don't want to change the current (unnamed) register */ | |
6768 *old_y_previous = y_previous; | |
6769 *old_y_current = y_current; | |
6770 | |
6771 get_yank_register(name, TRUE); | |
6772 if (!y_append && !must_append) | |
6773 free_yank_all(); | |
6774 return OK; | |
6775 } | |
6776 | |
6777 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6778 finish_write_reg( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6779 int name, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6780 yankreg_T *old_y_previous, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6781 yankreg_T *old_y_current) |
5798 | 6782 { |
6783 # ifdef FEAT_CLIPBOARD | |
6784 /* Send text of clipboard register to the clipboard. */ | |
6785 may_set_selection(); | |
6786 # endif | |
6787 | |
6788 /* ':let @" = "val"' should change the meaning of the "" register */ | |
6789 if (name != '"') | |
6790 y_previous = old_y_previous; | |
6791 y_current = old_y_current; | |
6792 } | |
6793 | |
7 | 6794 /* |
6795 * Store string "str" in register "name". | |
6796 * "maxlen" is the maximum number of bytes to use, -1 for all bytes. | |
6797 * If "must_append" is TRUE, always append to the register. Otherwise append | |
6798 * if "name" is an uppercase letter. | |
6799 * Note: "maxlen" and "must_append" don't work for the "/" register. | |
6800 * Careful: 'str' is modified, you may have to use a copy! | |
6801 * If "str" ends in '\n' or '\r', use linewise, otherwise use characterwise. | |
6802 */ | |
6803 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6804 write_reg_contents( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6805 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6806 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6807 int maxlen, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6808 int must_append) |
7 | 6809 { |
6810 write_reg_contents_ex(name, str, maxlen, must_append, MAUTO, 0L); | |
6811 } | |
6812 | |
6813 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6814 write_reg_contents_lst( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6815 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6816 char_u **strings, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6817 int maxlen UNUSED, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6818 int must_append, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6819 int yank_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6820 long block_len) |
5798 | 6821 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6822 yankreg_T *old_y_previous, *old_y_current; |
5798 | 6823 |
6824 if (name == '/' | |
6825 #ifdef FEAT_EVAL | |
6826 || name == '=' | |
6827 #endif | |
6828 ) | |
6829 { | |
6830 char_u *s; | |
6831 | |
6832 if (strings[0] == NULL) | |
6833 s = (char_u *)""; | |
6834 else if (strings[1] != NULL) | |
6835 { | |
6836 EMSG(_("E883: search pattern and expression register may not " | |
6837 "contain two or more lines")); | |
6838 return; | |
6839 } | |
6840 else | |
6841 s = strings[0]; | |
6842 write_reg_contents_ex(name, s, -1, must_append, yank_type, block_len); | |
6843 return; | |
6844 } | |
6845 | |
6846 if (name == '_') /* black hole: nothing to do */ | |
6847 return; | |
6848 | |
6849 if (init_write_reg(name, &old_y_previous, &old_y_current, must_append, | |
6850 &yank_type) == FAIL) | |
6851 return; | |
6852 | |
6853 str_to_reg(y_current, yank_type, (char_u *) strings, -1, block_len, TRUE); | |
6854 | |
6855 finish_write_reg(name, old_y_previous, old_y_current); | |
6856 } | |
6857 | |
6858 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6859 write_reg_contents_ex( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6860 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6861 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6862 int maxlen, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6863 int must_append, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6864 int yank_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6865 long block_len) |
7 | 6866 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6867 yankreg_T *old_y_previous, *old_y_current; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6868 long len; |
7 | 6869 |
336 | 6870 if (maxlen >= 0) |
6871 len = maxlen; | |
6872 else | |
6873 len = (long)STRLEN(str); | |
6874 | |
7 | 6875 /* Special case: '/' search pattern */ |
6876 if (name == '/') | |
6877 { | |
6878 set_last_search_pat(str, RE_SEARCH, TRUE, TRUE); | |
6879 return; | |
6880 } | |
6881 | |
6557 | 6882 if (name == '#') |
6883 { | |
6884 buf_T *buf; | |
6885 | |
6886 if (VIM_ISDIGIT(*str)) | |
6887 { | |
6888 int num = atoi((char *)str); | |
6889 | |
6890 buf = buflist_findnr(num); | |
6891 if (buf == NULL) | |
6892 EMSGN(_(e_nobufnr), (long)num); | |
6893 } | |
6894 else | |
6895 buf = buflist_findnr(buflist_findpat(str, str + STRLEN(str), | |
6896 TRUE, FALSE, FALSE)); | |
6897 if (buf == NULL) | |
6898 return; | |
6899 curwin->w_alt_fnum = buf->b_fnum; | |
6900 return; | |
6901 } | |
6902 | |
336 | 6903 #ifdef FEAT_EVAL |
6904 if (name == '=') | |
6905 { | |
6906 char_u *p, *s; | |
6907 | |
6908 p = vim_strnsave(str, (int)len); | |
6909 if (p == NULL) | |
6910 return; | |
6911 if (must_append) | |
6912 { | |
6913 s = concat_str(get_expr_line_src(), p); | |
6914 vim_free(p); | |
6915 p = s; | |
6916 } | |
6917 set_expr_line(p); | |
6918 return; | |
6919 } | |
6920 #endif | |
6921 | |
7 | 6922 if (name == '_') /* black hole: nothing to do */ |
6923 return; | |
6924 | |
5798 | 6925 if (init_write_reg(name, &old_y_previous, &old_y_current, must_append, |
6926 &yank_type) == FAIL) | |
6927 return; | |
6928 | |
6929 str_to_reg(y_current, yank_type, str, len, block_len, FALSE); | |
6930 | |
6931 finish_write_reg(name, old_y_previous, old_y_current); | |
7 | 6932 } |
6933 #endif /* FEAT_EVAL */ | |
6934 | |
6935 #if defined(FEAT_CLIPBOARD) || defined(FEAT_EVAL) | |
6936 /* | |
6937 * Put a string into a register. When the register is not empty, the string | |
6938 * is appended. | |
6939 */ | |
6940 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6941 str_to_reg( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6942 yankreg_T *y_ptr, /* pointer to yank register */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6943 int yank_type, /* MCHAR, MLINE, MBLOCK, MAUTO */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6944 char_u *str, /* string to put in register */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6945 long len, /* length of string */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6946 long blocklen, /* width of Visual block */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6947 int str_list) /* TRUE if str is char_u ** */ |
7 | 6948 { |
2896 | 6949 int type; /* MCHAR, MLINE or MBLOCK */ |
7 | 6950 int lnum; |
6951 long start; | |
6952 long i; | |
6953 int extra; | |
6954 int newlines; /* number of lines added */ | |
6955 int extraline = 0; /* extra line at the end */ | |
6956 int append = FALSE; /* append to last line in register */ | |
6957 char_u *s; | |
5798 | 6958 char_u **ss; |
7 | 6959 char_u **pp; |
6960 long maxlen; | |
6961 | |
2000 | 6962 if (y_ptr->y_array == NULL) /* NULL means empty register */ |
7 | 6963 y_ptr->y_size = 0; |
6964 | |
2896 | 6965 if (yank_type == MAUTO) |
5798 | 6966 type = ((str_list || (len > 0 && (str[len - 1] == NL |
6967 || str[len - 1] == CAR))) | |
2896 | 6968 ? MLINE : MCHAR); |
6969 else | |
6970 type = yank_type; | |
6971 | |
7 | 6972 /* |
6973 * Count the number of lines within the string | |
6974 */ | |
6975 newlines = 0; | |
5798 | 6976 if (str_list) |
6977 { | |
6978 for (ss = (char_u **) str; *ss != NULL; ++ss) | |
7 | 6979 ++newlines; |
5798 | 6980 } |
6981 else | |
6982 { | |
6983 for (i = 0; i < len; i++) | |
6984 if (str[i] == '\n') | |
6985 ++newlines; | |
6986 if (type == MCHAR || len == 0 || str[len - 1] != '\n') | |
6987 { | |
6988 extraline = 1; | |
6989 ++newlines; /* count extra newline at the end */ | |
6990 } | |
6991 if (y_ptr->y_size > 0 && y_ptr->y_type == MCHAR) | |
6992 { | |
6993 append = TRUE; | |
6994 --newlines; /* uncount newline when appending first line */ | |
6995 } | |
7 | 6996 } |
6997 | |
6807 | 6998 /* Without any lines make the register empty. */ |
6999 if (y_ptr->y_size + newlines == 0) | |
7000 { | |
7001 vim_free(y_ptr->y_array); | |
7002 y_ptr->y_array = NULL; | |
7003 return; | |
7004 } | |
7005 | |
7 | 7006 /* |
7007 * Allocate an array to hold the pointers to the new register lines. | |
7008 * If the register was not empty, move the existing lines to the new array. | |
7009 */ | |
7010 pp = (char_u **)lalloc_clear((y_ptr->y_size + newlines) | |
7011 * sizeof(char_u *), TRUE); | |
7012 if (pp == NULL) /* out of memory */ | |
7013 return; | |
7014 for (lnum = 0; lnum < y_ptr->y_size; ++lnum) | |
7015 pp[lnum] = y_ptr->y_array[lnum]; | |
7016 vim_free(y_ptr->y_array); | |
7017 y_ptr->y_array = pp; | |
7018 maxlen = 0; | |
7019 | |
7020 /* | |
7021 * Find the end of each line and save it into the array. | |
7022 */ | |
5798 | 7023 if (str_list) |
7024 { | |
7025 for (ss = (char_u **) str; *ss != NULL; ++ss, ++lnum) | |
7 | 7026 { |
5856 | 7027 i = (long)STRLEN(*ss); |
5798 | 7028 pp[lnum] = vim_strnsave(*ss, i); |
7029 if (i > maxlen) | |
7030 maxlen = i; | |
7 | 7031 } |
5798 | 7032 } |
7033 else | |
7034 { | |
7035 for (start = 0; start < len + extraline; start += i + 1) | |
7 | 7036 { |
5798 | 7037 for (i = start; i < len; ++i) /* find the end of the line */ |
7038 if (str[i] == '\n') | |
7039 break; | |
7040 i -= start; /* i is now length of line */ | |
7041 if (i > maxlen) | |
7042 maxlen = i; | |
7043 if (append) | |
7044 { | |
7045 --lnum; | |
7046 extra = (int)STRLEN(y_ptr->y_array[lnum]); | |
7047 } | |
7048 else | |
7049 extra = 0; | |
7050 s = alloc((unsigned)(i + extra + 1)); | |
7051 if (s == NULL) | |
7052 break; | |
7053 if (extra) | |
7054 mch_memmove(s, y_ptr->y_array[lnum], (size_t)extra); | |
7055 if (append) | |
7056 vim_free(y_ptr->y_array[lnum]); | |
7057 if (i) | |
7058 mch_memmove(s + extra, str + start, (size_t)i); | |
7059 extra += i; | |
7060 s[extra] = NUL; | |
7061 y_ptr->y_array[lnum++] = s; | |
7062 while (--extra >= 0) | |
7063 { | |
7064 if (*s == NUL) | |
7065 *s = '\n'; /* replace NUL with newline */ | |
7066 ++s; | |
7067 } | |
7068 append = FALSE; /* only first line is appended */ | |
7 | 7069 } |
7070 } | |
7071 y_ptr->y_type = type; | |
7072 y_ptr->y_size = lnum; | |
7073 if (type == MBLOCK) | |
7074 y_ptr->y_width = (blocklen < 0 ? maxlen - 1 : blocklen); | |
7075 else | |
7076 y_ptr->y_width = 0; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7077 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7078 y_ptr->y_time_set = vim_time(); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7079 #endif |
7 | 7080 } |
7081 #endif /* FEAT_CLIPBOARD || FEAT_EVAL || PROTO */ | |
7082 | |
7083 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7084 clear_oparg(oparg_T *oap) |
7 | 7085 { |
7086 vim_memset(oap, 0, sizeof(oparg_T)); | |
7087 } | |
7088 | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7089 static varnumber_T line_count_info(char_u *line, varnumber_T *wc, varnumber_T *cc, varnumber_T limit, int eol_size); |
7 | 7090 |
7091 /* | |
161 | 7092 * Count the number of bytes, characters and "words" in a line. |
7 | 7093 * |
7094 * "Words" are counted by looking for boundaries between non-space and | |
7095 * space characters. (it seems to produce results that match 'wc'.) | |
7096 * | |
161 | 7097 * Return value is byte count; word count for the line is added to "*wc". |
7098 * Char count is added to "*cc". | |
7 | 7099 * |
7100 * The function will only examine the first "limit" characters in the | |
7101 * line, stopping if it encounters an end-of-line (NUL byte). In that | |
7102 * case, eol_size will be added to the character count to account for | |
7103 * the size of the EOL character. | |
7104 */ | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7105 static varnumber_T |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7106 line_count_info( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7107 char_u *line, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7108 varnumber_T *wc, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7109 varnumber_T *cc, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7110 varnumber_T limit, |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7111 int eol_size) |
7 | 7112 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7113 varnumber_T i; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7114 varnumber_T words = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7115 varnumber_T chars = 0; |
7 | 7116 int is_word = 0; |
7117 | |
3626 | 7118 for (i = 0; i < limit && line[i] != NUL; ) |
7 | 7119 { |
7120 if (is_word) | |
7121 { | |
7122 if (vim_isspace(line[i])) | |
7123 { | |
7124 words++; | |
7125 is_word = 0; | |
7126 } | |
7127 } | |
7128 else if (!vim_isspace(line[i])) | |
7129 is_word = 1; | |
161 | 7130 ++chars; |
7131 #ifdef FEAT_MBYTE | |
474 | 7132 i += (*mb_ptr2len)(line + i); |
161 | 7133 #else |
7134 ++i; | |
7135 #endif | |
7 | 7136 } |
7137 | |
7138 if (is_word) | |
7139 words++; | |
7140 *wc += words; | |
7141 | |
7142 /* Add eol_size if the end of line was reached before hitting limit. */ | |
2996 | 7143 if (i < limit && line[i] == NUL) |
161 | 7144 { |
7 | 7145 i += eol_size; |
161 | 7146 chars += eol_size; |
7147 } | |
7148 *cc += chars; | |
7 | 7149 return i; |
7150 } | |
7151 | |
7152 /* | |
7153 * Give some info about the position of the cursor (for "g CTRL-G"). | |
7154 * In Visual mode, give some info about the selected region. (In this case, | |
7155 * 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
|
7156 * When "dict" is not NULL store the info there instead of showing it. |
7 | 7157 */ |
7158 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7159 cursor_pos_info(dict_T *dict) |
7 | 7160 { |
7161 char_u *p; | |
274 | 7162 char_u buf1[50]; |
7163 char_u buf2[40]; | |
7 | 7164 linenr_T lnum; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7165 varnumber_T byte_count = 0; |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7166 #ifdef FEAT_MBYTE |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7167 varnumber_T bom_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7168 #endif |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7169 varnumber_T byte_count_cursor = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7170 varnumber_T char_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7171 varnumber_T char_count_cursor = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7172 varnumber_T word_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7173 varnumber_T word_count_cursor = 0; |
7 | 7174 int eol_size; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7175 varnumber_T last_check = 100000L; |
7 | 7176 long line_count_selected = 0; |
7177 pos_T min_pos, max_pos; | |
7178 oparg_T oparg; | |
7179 struct block_def bd; | |
7180 | |
7181 /* | |
7182 * Compute the length of the file in characters. | |
7183 */ | |
7184 if (curbuf->b_ml.ml_flags & ML_EMPTY) | |
7185 { | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7186 if (dict == NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7187 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7188 MSG(_(no_lines_msg)); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7189 return; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7190 } |
7 | 7191 } |
7192 else | |
7193 { | |
7194 if (get_fileformat(curbuf) == EOL_DOS) | |
7195 eol_size = 2; | |
7196 else | |
7197 eol_size = 1; | |
7198 | |
7199 if (VIsual_active) | |
7200 { | |
7201 if (lt(VIsual, curwin->w_cursor)) | |
7202 { | |
7203 min_pos = VIsual; | |
7204 max_pos = curwin->w_cursor; | |
7205 } | |
7206 else | |
7207 { | |
7208 min_pos = curwin->w_cursor; | |
7209 max_pos = VIsual; | |
7210 } | |
7211 if (*p_sel == 'e' && max_pos.col > 0) | |
7212 --max_pos.col; | |
7213 | |
7214 if (VIsual_mode == Ctrl_V) | |
7215 { | |
1866 | 7216 #ifdef FEAT_LINEBREAK |
7217 char_u * saved_sbr = p_sbr; | |
7218 | |
7219 /* Make 'sbr' empty for a moment to get the correct size. */ | |
7220 p_sbr = empty_option; | |
7221 #endif | |
7 | 7222 oparg.is_VIsual = 1; |
7223 oparg.block_mode = TRUE; | |
7224 oparg.op_type = OP_NOP; | |
7225 getvcols(curwin, &min_pos, &max_pos, | |
688 | 7226 &oparg.start_vcol, &oparg.end_vcol); |
1866 | 7227 #ifdef FEAT_LINEBREAK |
7228 p_sbr = saved_sbr; | |
7229 #endif | |
688 | 7230 if (curwin->w_curswant == MAXCOL) |
7231 oparg.end_vcol = MAXCOL; | |
7 | 7232 /* Swap the start, end vcol if needed */ |
7233 if (oparg.end_vcol < oparg.start_vcol) | |
7234 { | |
7235 oparg.end_vcol += oparg.start_vcol; | |
7236 oparg.start_vcol = oparg.end_vcol - oparg.start_vcol; | |
7237 oparg.end_vcol -= oparg.start_vcol; | |
7238 } | |
7239 } | |
7240 line_count_selected = max_pos.lnum - min_pos.lnum + 1; | |
7241 } | |
7242 | |
7243 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) | |
7244 { | |
7245 /* Check for a CTRL-C every 100000 characters. */ | |
161 | 7246 if (byte_count > last_check) |
7 | 7247 { |
7248 ui_breakcheck(); | |
7249 if (got_int) | |
7250 return; | |
161 | 7251 last_check = byte_count + 100000L; |
7 | 7252 } |
7253 | |
7254 /* Do extra processing for VIsual mode. */ | |
7255 if (VIsual_active | |
7256 && lnum >= min_pos.lnum && lnum <= max_pos.lnum) | |
7257 { | |
45 | 7258 char_u *s = NULL; |
7259 long len = 0L; | |
7260 | |
7 | 7261 switch (VIsual_mode) |
7262 { | |
7263 case Ctrl_V: | |
5735 | 7264 #ifdef FEAT_VIRTUALEDIT |
7 | 7265 virtual_op = virtual_active(); |
5735 | 7266 #endif |
7 | 7267 block_prep(&oparg, &bd, lnum, 0); |
5735 | 7268 #ifdef FEAT_VIRTUALEDIT |
7 | 7269 virtual_op = MAYBE; |
5735 | 7270 #endif |
45 | 7271 s = bd.textstart; |
7272 len = (long)bd.textlen; | |
7 | 7273 break; |
7274 case 'V': | |
45 | 7275 s = ml_get(lnum); |
7276 len = MAXCOL; | |
7 | 7277 break; |
7278 case 'v': | |
7279 { | |
7280 colnr_T start_col = (lnum == min_pos.lnum) | |
7281 ? min_pos.col : 0; | |
7282 colnr_T end_col = (lnum == max_pos.lnum) | |
7283 ? max_pos.col - start_col + 1 : MAXCOL; | |
7284 | |
45 | 7285 s = ml_get(lnum) + start_col; |
7286 len = end_col; | |
7 | 7287 } |
7288 break; | |
7289 } | |
45 | 7290 if (s != NULL) |
7291 { | |
161 | 7292 byte_count_cursor += line_count_info(s, &word_count_cursor, |
7293 &char_count_cursor, len, eol_size); | |
45 | 7294 if (lnum == curbuf->b_ml.ml_line_count |
7295 && !curbuf->b_p_eol | |
6933 | 7296 && (curbuf->b_p_bin || !curbuf->b_p_fixeol) |
50 | 7297 && (long)STRLEN(s) < len) |
161 | 7298 byte_count_cursor -= eol_size; |
45 | 7299 } |
7 | 7300 } |
7301 else | |
7302 { | |
7303 /* In non-visual mode, check for the line the cursor is on */ | |
7304 if (lnum == curwin->w_cursor.lnum) | |
7305 { | |
7306 word_count_cursor += word_count; | |
161 | 7307 char_count_cursor += char_count; |
7308 byte_count_cursor = byte_count + | |
7309 line_count_info(ml_get(lnum), | |
7310 &word_count_cursor, &char_count_cursor, | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7311 (varnumber_T)(curwin->w_cursor.col + 1), |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7312 eol_size); |
7 | 7313 } |
7314 } | |
7315 /* Add to the running totals */ | |
161 | 7316 byte_count += line_count_info(ml_get(lnum), &word_count, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7317 &char_count, (varnumber_T)MAXCOL, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7318 eol_size); |
7 | 7319 } |
7320 | |
7321 /* Correction for when last line doesn't have an EOL. */ | |
6933 | 7322 if (!curbuf->b_p_eol && (curbuf->b_p_bin || !curbuf->b_p_fixeol)) |
161 | 7323 byte_count -= eol_size; |
7 | 7324 |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7325 if (dict == NULL) |
7 | 7326 { |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7327 if (VIsual_active) |
7 | 7328 { |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7329 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
|
7330 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7331 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
|
7332 &max_pos.col); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7333 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
|
7334 (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
|
7335 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7336 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7337 buf1[0] = NUL; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7338 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7339 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
|
7340 && char_count == byte_count) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7341 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7342 _("Selected %s%ld of %ld Lines; %lld of %lld Words; %lld of %lld Bytes"), |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7343 buf1, line_count_selected, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7344 (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
|
7345 word_count_cursor, word_count, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7346 byte_count_cursor, byte_count); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7347 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7348 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7349 _("Selected %s%ld of %ld Lines; %lld of %lld Words; %lld of %lld Chars; %lld of %lld Bytes"), |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7350 buf1, line_count_selected, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7351 (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
|
7352 word_count_cursor, word_count, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7353 char_count_cursor, char_count, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7354 byte_count_cursor, byte_count); |
7 | 7355 } |
7356 else | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7357 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7358 p = ml_get_curline(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7359 validate_virtcol(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7360 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
|
7361 (int)curwin->w_virtcol + 1); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7362 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
|
7363 linetabsize(p)); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7364 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7365 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
|
7366 && char_count == byte_count) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7367 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7368 _("Col %s of %s; Line %ld of %ld; Word %lld of %lld; Byte %lld of %lld"), |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7369 (char *)buf1, (char *)buf2, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7370 (long)curwin->w_cursor.lnum, |
7 | 7371 (long)curbuf->b_ml.ml_line_count, |
7372 word_count_cursor, word_count, | |
161 | 7373 byte_count_cursor, byte_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7374 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7375 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7376 _("Col %s of %s; Line %ld of %ld; Word %lld of %lld; Char %lld of %lld; Byte %lld of %lld"), |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7377 (char *)buf1, (char *)buf2, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7378 (long)curwin->w_cursor.lnum, |
161 | 7379 (long)curbuf->b_ml.ml_line_count, |
7380 word_count_cursor, word_count, | |
7381 char_count_cursor, char_count, | |
7382 byte_count_cursor, byte_count); | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7383 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7384 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7385 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7386 #ifdef FEAT_MBYTE |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7387 bom_count = bomb_size(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7388 if (bom_count > 0) |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7389 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
|
7390 _("(+%ld for BOM)"), bom_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7391 #endif |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7392 if (dict == NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7393 { |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7394 /* 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
|
7395 p = p_shm; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7396 p_shm = (char_u *)""; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7397 msg(IObuff); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7398 p_shm = p; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7399 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7400 } |
7484
1fe988587423
commit https://github.com/vim/vim/commit/718272a7e13c71095ce07eb3b3d5e1f9790a6991
Christian Brabandt <cb@256bit.org>
parents:
7480
diff
changeset
|
7401 #if defined(FEAT_EVAL) |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7402 if (dict != NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7403 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7404 dict_add_nr_str(dict, "words", word_count, NULL); |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7405 dict_add_nr_str(dict, "chars", char_count, NULL); |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7406 dict_add_nr_str(dict, "bytes", byte_count |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7407 # ifdef FEAT_MBYTE |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7408 + bom_count |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7409 # endif |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7410 , NULL); |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7411 dict_add_nr_str(dict, VIsual_active ? "visual_bytes" : "cursor_bytes", |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7412 byte_count_cursor, NULL); |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7413 dict_add_nr_str(dict, VIsual_active ? "visual_chars" : "cursor_chars", |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7414 char_count_cursor, NULL); |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7415 dict_add_nr_str(dict, VIsual_active ? "visual_words" : "cursor_words", |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7416 word_count_cursor, NULL); |
7 | 7417 } |
7484
1fe988587423
commit https://github.com/vim/vim/commit/718272a7e13c71095ce07eb3b3d5e1f9790a6991
Christian Brabandt <cb@256bit.org>
parents:
7480
diff
changeset
|
7418 #endif |
7 | 7419 } |