Mercurial > vim
annotate src/ops.c @ 13357:179586a64f53 v8.0.1552
patch 8.0.1552: may leak file descriptors when executing job
commit https://github.com/vim/vim/commit/8195247054a659fe5cbc238197634d5e13e8e8e9
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Feb 27 19:10:00 2018 +0100
patch 8.0.1552: may leak file descriptors when executing job
Problem: May leak file descriptors when executing job.
Solution: Close more file descriptors. (Ozaki Kiichi, closes https://github.com/vim/vim/issues/2531)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 27 Feb 2018 19:15:05 +0100 |
parents | 88cc06dc1a50 |
children | 69517d67421f |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9834
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 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); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
116 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
|
117 static int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1); |
7 | 118 #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
|
119 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
|
120 #endif |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
121 static int ends_in_white(linenr_T lnum); |
7 | 122 #ifdef FEAT_COMMENTS |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
123 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
|
124 static int fmt_check_par(linenr_T, int *, char_u **, int do_comments); |
7 | 125 #else |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
126 static int fmt_check_par(linenr_T); |
7 | 127 #endif |
128 | |
129 /* | |
130 * The names of operators. | |
131 * IMPORTANT: Index must correspond with defines in vim.h!!! | |
132 * The third field indicates whether the operator always works on lines. | |
133 */ | |
134 static char opchars[][3] = | |
135 { | |
136 {NUL, NUL, FALSE}, /* OP_NOP */ | |
137 {'d', NUL, FALSE}, /* OP_DELETE */ | |
138 {'y', NUL, FALSE}, /* OP_YANK */ | |
139 {'c', NUL, FALSE}, /* OP_CHANGE */ | |
140 {'<', NUL, TRUE}, /* OP_LSHIFT */ | |
141 {'>', NUL, TRUE}, /* OP_RSHIFT */ | |
142 {'!', NUL, TRUE}, /* OP_FILTER */ | |
143 {'g', '~', FALSE}, /* OP_TILDE */ | |
144 {'=', NUL, TRUE}, /* OP_INDENT */ | |
145 {'g', 'q', TRUE}, /* OP_FORMAT */ | |
146 {':', NUL, TRUE}, /* OP_COLON */ | |
147 {'g', 'U', FALSE}, /* OP_UPPER */ | |
148 {'g', 'u', FALSE}, /* OP_LOWER */ | |
149 {'J', NUL, TRUE}, /* DO_JOIN */ | |
150 {'g', 'J', TRUE}, /* DO_JOIN_NS */ | |
151 {'g', '?', FALSE}, /* OP_ROT13 */ | |
152 {'r', NUL, FALSE}, /* OP_REPLACE */ | |
153 {'I', NUL, FALSE}, /* OP_INSERT */ | |
154 {'A', NUL, FALSE}, /* OP_APPEND */ | |
155 {'z', 'f', TRUE}, /* OP_FOLD */ | |
156 {'z', 'o', TRUE}, /* OP_FOLDOPEN */ | |
157 {'z', 'O', TRUE}, /* OP_FOLDOPENREC */ | |
158 {'z', 'c', TRUE}, /* OP_FOLDCLOSE */ | |
159 {'z', 'C', TRUE}, /* OP_FOLDCLOSEREC */ | |
160 {'z', 'd', TRUE}, /* OP_FOLDDEL */ | |
161 {'z', 'D', TRUE}, /* OP_FOLDDELREC */ | |
162 {'g', 'w', TRUE}, /* OP_FORMAT2 */ | |
603 | 163 {'g', '@', FALSE}, /* OP_FUNCTION */ |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
164 {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
|
165 {Ctrl_X, NUL, FALSE}, /* OP_NR_SUB */ |
7 | 166 }; |
167 | |
168 /* | |
169 * Translate a command name into an operator type. | |
170 * Must only be called with a valid operator name! | |
171 */ | |
172 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
173 get_op_type(int char1, int char2) |
7 | 174 { |
175 int i; | |
176 | |
177 if (char1 == 'r') /* ignore second character */ | |
178 return OP_REPLACE; | |
179 if (char1 == '~') /* when tilde is an operator */ | |
180 return OP_TILDE; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
181 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
|
182 return OP_NR_ADD; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
183 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
|
184 return OP_NR_SUB; |
7 | 185 for (i = 0; ; ++i) |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
186 { |
7 | 187 if (opchars[i][0] == char1 && opchars[i][1] == char2) |
188 break; | |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
189 if (i == (int)(sizeof(opchars) / sizeof(char [3]) - 1)) |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
190 { |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
191 internal_error("get_op_type()"); |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
192 break; |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
193 } |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
194 } |
7 | 195 return i; |
196 } | |
197 | |
198 /* | |
199 * Return TRUE if operator "op" always works on whole lines. | |
200 */ | |
201 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
202 op_on_lines(int op) |
7 | 203 { |
204 return opchars[op][2]; | |
205 } | |
206 | |
207 /* | |
208 * Get first operator command character. | |
209 * Returns 'g' or 'z' if there is another command character. | |
210 */ | |
211 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
212 get_op_char(int optype) |
7 | 213 { |
214 return opchars[optype][0]; | |
215 } | |
216 | |
217 /* | |
218 * Get second operator command character. | |
219 */ | |
220 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
221 get_extra_op_char(int optype) |
7 | 222 { |
223 return opchars[optype][1]; | |
224 } | |
225 | |
226 /* | |
227 * op_shift - handle a shift operation | |
228 */ | |
229 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
230 op_shift(oparg_T *oap, int curs_top, int amount) |
7 | 231 { |
232 long i; | |
233 int first_char; | |
234 char_u *s; | |
235 int block_col = 0; | |
236 | |
237 if (u_save((linenr_T)(oap->start.lnum - 1), | |
238 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
239 return; | |
240 | |
241 if (oap->block_mode) | |
242 block_col = curwin->w_cursor.col; | |
243 | |
244 for (i = oap->line_count; --i >= 0; ) | |
245 { | |
246 first_char = *ml_get_curline(); | |
247 if (first_char == NUL) /* empty line */ | |
248 curwin->w_cursor.col = 0; | |
249 #ifdef FEAT_VISUALEXTRA | |
250 else if (oap->block_mode) | |
251 shift_block(oap, amount); | |
252 #endif | |
253 else | |
254 /* Move the line right if it doesn't start with '#', 'smartindent' | |
255 * isn't set or 'cindent' isn't set or '#' isn't in 'cino'. */ | |
256 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) | |
257 if (first_char != '#' || !preprocs_left()) | |
258 #endif | |
259 { | |
1516 | 260 shift_line(oap->op_type == OP_LSHIFT, p_sr, amount, FALSE); |
7 | 261 } |
262 ++curwin->w_cursor.lnum; | |
263 } | |
264 | |
265 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); | |
266 if (oap->block_mode) | |
267 { | |
268 curwin->w_cursor.lnum = oap->start.lnum; | |
269 curwin->w_cursor.col = block_col; | |
270 } | |
5735 | 271 else if (curs_top) /* put cursor on first line, for ">>" */ |
7 | 272 { |
273 curwin->w_cursor.lnum = oap->start.lnum; | |
274 beginline(BL_SOL | BL_FIX); /* shift_line() may have set cursor.col */ | |
275 } | |
276 else | |
277 --curwin->w_cursor.lnum; /* put cursor on last line, for ":>" */ | |
278 | |
10486
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
279 #ifdef FEAT_FOLDING |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
280 /* The cursor line is not in a closed fold */ |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
281 foldOpenCursor(); |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
282 #endif |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
283 |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
284 |
7 | 285 if (oap->line_count > p_report) |
286 { | |
287 if (oap->op_type == OP_RSHIFT) | |
288 s = (char_u *)">"; | |
289 else | |
290 s = (char_u *)"<"; | |
291 if (oap->line_count == 1) | |
292 { | |
293 if (amount == 1) | |
294 sprintf((char *)IObuff, _("1 line %sed 1 time"), s); | |
295 else | |
296 sprintf((char *)IObuff, _("1 line %sed %d times"), s, amount); | |
297 } | |
298 else | |
299 { | |
300 if (amount == 1) | |
301 sprintf((char *)IObuff, _("%ld lines %sed 1 time"), | |
302 oap->line_count, s); | |
303 else | |
304 sprintf((char *)IObuff, _("%ld lines %sed %d times"), | |
305 oap->line_count, s, amount); | |
306 } | |
307 msg(IObuff); | |
308 } | |
309 | |
310 /* | |
311 * Set "'[" and "']" marks. | |
312 */ | |
313 curbuf->b_op_start = oap->start; | |
314 curbuf->b_op_end.lnum = oap->end.lnum; | |
315 curbuf->b_op_end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
316 if (curbuf->b_op_end.col > 0) | |
317 --curbuf->b_op_end.col; | |
318 } | |
319 | |
320 /* | |
321 * shift the current line one shiftwidth left (if left != 0) or right | |
322 * leaves cursor on first blank in the line | |
323 */ | |
324 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
325 shift_line( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
326 int left, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
327 int round, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
328 int amount, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
329 int call_changed_bytes) /* call changed_bytes() */ |
7 | 330 { |
331 int count; | |
332 int i, j; | |
5438 | 333 int p_sw = (int)get_sw_value(curbuf); |
7 | 334 |
335 count = get_indent(); /* get current indent */ | |
336 | |
337 if (round) /* round off indent */ | |
338 { | |
339 i = count / p_sw; /* number of p_sw rounded down */ | |
340 j = count % p_sw; /* extra spaces */ | |
341 if (j && left) /* first remove extra spaces */ | |
342 --amount; | |
343 if (left) | |
344 { | |
345 i -= amount; | |
346 if (i < 0) | |
347 i = 0; | |
348 } | |
349 else | |
350 i += amount; | |
351 count = i * p_sw; | |
352 } | |
353 else /* original vi indent */ | |
354 { | |
355 if (left) | |
356 { | |
357 count -= p_sw * amount; | |
358 if (count < 0) | |
359 count = 0; | |
360 } | |
361 else | |
362 count += p_sw * amount; | |
363 } | |
364 | |
365 /* Set new indent */ | |
366 #ifdef FEAT_VREPLACE | |
367 if (State & VREPLACE_FLAG) | |
1516 | 368 change_indent(INDENT_SET, count, FALSE, NUL, call_changed_bytes); |
7 | 369 else |
370 #endif | |
1516 | 371 (void)set_indent(count, call_changed_bytes ? SIN_CHANGED : 0); |
7 | 372 } |
373 | |
374 #if defined(FEAT_VISUALEXTRA) || defined(PROTO) | |
375 /* | |
376 * Shift one line of the current block one shiftwidth right or left. | |
377 * Leaves cursor on first character in block. | |
378 */ | |
379 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
380 shift_block(oparg_T *oap, int amount) |
7 | 381 { |
382 int left = (oap->op_type == OP_LSHIFT); | |
383 int oldstate = State; | |
1839 | 384 int total; |
385 char_u *newp, *oldp; | |
7 | 386 int oldcol = curwin->w_cursor.col; |
5438 | 387 int p_sw = (int)get_sw_value(curbuf); |
7 | 388 int p_ts = (int)curbuf->b_p_ts; |
389 struct block_def bd; | |
390 int incr; | |
1839 | 391 colnr_T ws_vcol; |
7 | 392 int i = 0, j = 0; |
393 int len; | |
394 #ifdef FEAT_RIGHTLEFT | |
395 int old_p_ri = p_ri; | |
396 | |
4352 | 397 p_ri = 0; /* don't want revins in indent */ |
7 | 398 #endif |
399 | |
400 State = INSERT; /* don't want REPLACE for State */ | |
401 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); | |
402 if (bd.is_short) | |
403 return; | |
404 | |
405 /* total is number of screen columns to be inserted/removed */ | |
11997
66b677c77467
patch 8.0.0879: crash when shifting with huge number
Christian Brabandt <cb@256bit.org>
parents:
11688
diff
changeset
|
406 total = (int)((unsigned)amount * (unsigned)p_sw); |
66b677c77467
patch 8.0.0879: crash when shifting with huge number
Christian Brabandt <cb@256bit.org>
parents:
11688
diff
changeset
|
407 if ((total / p_sw) != amount) |
66b677c77467
patch 8.0.0879: crash when shifting with huge number
Christian Brabandt <cb@256bit.org>
parents:
11688
diff
changeset
|
408 return; /* multiplication overflow */ |
66b677c77467
patch 8.0.0879: crash when shifting with huge number
Christian Brabandt <cb@256bit.org>
parents:
11688
diff
changeset
|
409 |
7 | 410 oldp = ml_get_curline(); |
411 | |
412 if (!left) | |
413 { | |
414 /* | |
415 * 1. Get start vcol | |
416 * 2. Total ws vcols | |
417 * 3. Divvy into TABs & spp | |
418 * 4. Construct new string | |
419 */ | |
420 total += bd.pre_whitesp; /* all virtual WS upto & incl a split TAB */ | |
421 ws_vcol = bd.start_vcol - bd.pre_whitesp; | |
422 if (bd.startspaces) | |
423 { | |
424 #ifdef FEAT_MBYTE | |
425 if (has_mbyte) | |
8399
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
426 { |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
427 if ((*mb_ptr2len)(bd.textstart) == 1) |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
428 ++bd.textstart; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
429 else |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
430 { |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
431 ws_vcol = 0; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
432 bd.startspaces = 0; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
433 } |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
434 } |
1995 | 435 else |
436 #endif | |
437 ++bd.textstart; | |
7 | 438 } |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
439 for ( ; VIM_ISWHITE(*bd.textstart); ) |
7 | 440 { |
5995 | 441 /* TODO: is passing bd.textstart for start of the line OK? */ |
442 incr = lbr_chartabsize_adv(bd.textstart, &bd.textstart, | |
443 (colnr_T)(bd.start_vcol)); | |
7 | 444 total += incr; |
445 bd.start_vcol += incr; | |
446 } | |
447 /* OK, now total=all the VWS reqd, and textstart points at the 1st | |
448 * non-ws char in the block. */ | |
449 if (!curbuf->b_p_et) | |
450 i = ((ws_vcol % p_ts) + total) / p_ts; /* number of tabs */ | |
451 if (i) | |
452 j = ((ws_vcol % p_ts) + total) % p_ts; /* number of spp */ | |
453 else | |
454 j = total; | |
455 /* if we're splitting a TAB, allow for it */ | |
456 bd.textcol -= bd.pre_whitesp_c - (bd.startspaces != 0); | |
457 len = (int)STRLEN(bd.textstart) + 1; | |
458 newp = alloc_check((unsigned)(bd.textcol + i + j + len)); | |
459 if (newp == NULL) | |
460 return; | |
461 vim_memset(newp, NUL, (size_t)(bd.textcol + i + j + len)); | |
462 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
6929 | 463 vim_memset(newp + bd.textcol, TAB, (size_t)i); |
464 vim_memset(newp + bd.textcol + i, ' ', (size_t)j); | |
7 | 465 /* the end */ |
466 mch_memmove(newp + bd.textcol + i + j, bd.textstart, (size_t)len); | |
467 } | |
468 else /* left */ | |
469 { | |
1839 | 470 colnr_T destination_col; /* column to which text in block will |
471 be shifted */ | |
472 char_u *verbatim_copy_end; /* end of the part of the line which is | |
473 copied verbatim */ | |
474 colnr_T verbatim_copy_width;/* the (displayed) width of this part | |
475 of line */ | |
476 unsigned fill; /* nr of spaces that replace a TAB */ | |
477 unsigned new_line_len; /* the length of the line after the | |
478 block shift */ | |
479 size_t block_space_width; | |
480 size_t shift_amount; | |
481 char_u *non_white = bd.textstart; | |
482 colnr_T non_white_col; | |
483 | |
484 /* | |
485 * Firstly, let's find the first non-whitespace character that is | |
486 * displayed after the block's start column and the character's column | |
487 * number. Also, let's calculate the width of all the whitespace | |
488 * characters that are displayed in the block and precede the searched | |
489 * non-whitespace character. | |
490 */ | |
491 | |
492 /* If "bd.startspaces" is set, "bd.textstart" points to the character, | |
493 * the part of which is displayed at the block's beginning. Let's start | |
494 * searching from the next character. */ | |
495 if (bd.startspaces) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
496 MB_PTR_ADV(non_white); |
1839 | 497 |
498 /* The character's column is in "bd.start_vcol". */ | |
499 non_white_col = bd.start_vcol; | |
500 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
501 while (VIM_ISWHITE(*non_white)) |
7 | 502 { |
5995 | 503 incr = lbr_chartabsize_adv(bd.textstart, &non_white, non_white_col); |
1839 | 504 non_white_col += incr; |
7 | 505 } |
1839 | 506 |
507 block_space_width = non_white_col - oap->start_vcol; | |
508 /* We will shift by "total" or "block_space_width", whichever is less. | |
509 */ | |
1860 | 510 shift_amount = (block_space_width < (size_t)total |
511 ? block_space_width : (size_t)total); | |
1839 | 512 |
513 /* The column to which we will shift the text. */ | |
1860 | 514 destination_col = (colnr_T)(non_white_col - shift_amount); |
1839 | 515 |
516 /* Now let's find out how much of the beginning of the line we can | |
517 * reuse without modification. */ | |
518 verbatim_copy_end = bd.textstart; | |
519 verbatim_copy_width = bd.start_vcol; | |
520 | |
521 /* If "bd.startspaces" is set, "bd.textstart" points to the character | |
522 * preceding the block. We have to subtract its width to obtain its | |
523 * column number. */ | |
524 if (bd.startspaces) | |
525 verbatim_copy_width -= bd.start_char_vcols; | |
526 while (verbatim_copy_width < destination_col) | |
7 | 527 { |
5995 | 528 char_u *line = verbatim_copy_end; |
529 | |
530 /* TODO: is passing verbatim_copy_end for start of the line OK? */ | |
531 incr = lbr_chartabsize(line, verbatim_copy_end, | |
532 verbatim_copy_width); | |
1839 | 533 if (verbatim_copy_width + incr > destination_col) |
534 break; | |
535 verbatim_copy_width += incr; | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
536 MB_PTR_ADV(verbatim_copy_end); |
7 | 537 } |
538 | |
1839 | 539 /* If "destination_col" is different from the width of the initial |
540 * part of the line that will be copied, it means we encountered a tab | |
541 * character, which we will have to partly replace with spaces. */ | |
542 fill = destination_col - verbatim_copy_width; | |
543 | |
544 /* The replacement line will consist of: | |
545 * - the beginning of the original line up to "verbatim_copy_end", | |
546 * - "fill" number of spaces, | |
547 * - the rest of the line, pointed to by non_white. */ | |
548 new_line_len = (unsigned)(verbatim_copy_end - oldp) | |
549 + fill | |
550 + (unsigned)STRLEN(non_white) + 1; | |
551 | |
552 newp = alloc_check(new_line_len); | |
7 | 553 if (newp == NULL) |
554 return; | |
1839 | 555 mch_memmove(newp, oldp, (size_t)(verbatim_copy_end - oldp)); |
6929 | 556 vim_memset(newp + (verbatim_copy_end - oldp), ' ', (size_t)fill); |
1839 | 557 STRMOVE(newp + (verbatim_copy_end - oldp) + fill, non_white); |
7 | 558 } |
559 /* replace the line */ | |
560 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
561 changed_bytes(curwin->w_cursor.lnum, (colnr_T)bd.textcol); | |
562 State = oldstate; | |
563 curwin->w_cursor.col = oldcol; | |
564 #ifdef FEAT_RIGHTLEFT | |
565 p_ri = old_p_ri; | |
566 #endif | |
567 } | |
568 #endif | |
569 | |
570 #ifdef FEAT_VISUALEXTRA | |
571 /* | |
572 * Insert string "s" (b_insert ? before : after) block :AKelly | |
573 * Caller must prepare for undo. | |
574 */ | |
575 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
576 block_insert( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
577 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
578 char_u *s, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
579 int b_insert, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
580 struct block_def *bdp) |
7 | 581 { |
582 int p_ts; | |
583 int count = 0; /* extra spaces to replace a cut TAB */ | |
584 int spaces = 0; /* non-zero if cutting a TAB */ | |
585 colnr_T offset; /* pointer along new line */ | |
586 unsigned s_len; /* STRLEN(s) */ | |
587 char_u *newp, *oldp; /* new, old lines */ | |
588 linenr_T lnum; /* loop var */ | |
589 int oldstate = State; | |
590 | |
591 State = INSERT; /* don't want REPLACE for State */ | |
592 s_len = (unsigned)STRLEN(s); | |
593 | |
594 for (lnum = oap->start.lnum + 1; lnum <= oap->end.lnum; lnum++) | |
595 { | |
596 block_prep(oap, bdp, lnum, TRUE); | |
597 if (bdp->is_short && b_insert) | |
598 continue; /* OP_INSERT, line ends before block start */ | |
599 | |
600 oldp = ml_get(lnum); | |
601 | |
602 if (b_insert) | |
603 { | |
604 p_ts = bdp->start_char_vcols; | |
605 spaces = bdp->startspaces; | |
606 if (spaces != 0) | |
607 count = p_ts - 1; /* we're cutting a TAB */ | |
608 offset = bdp->textcol; | |
609 } | |
610 else /* append */ | |
611 { | |
612 p_ts = bdp->end_char_vcols; | |
613 if (!bdp->is_short) /* spaces = padding after block */ | |
614 { | |
615 spaces = (bdp->endspaces ? p_ts - bdp->endspaces : 0); | |
616 if (spaces != 0) | |
617 count = p_ts - 1; /* we're cutting a TAB */ | |
618 offset = bdp->textcol + bdp->textlen - (spaces != 0); | |
619 } | |
620 else /* spaces = padding to block edge */ | |
621 { | |
622 /* if $ used, just append to EOL (ie spaces==0) */ | |
623 if (!bdp->is_MAX) | |
624 spaces = (oap->end_vcol - bdp->end_vcol) + 1; | |
625 count = spaces; | |
626 offset = bdp->textcol + bdp->textlen; | |
627 } | |
628 } | |
629 | |
6140 | 630 #ifdef FEAT_MBYTE |
631 if (has_mbyte && spaces > 0) | |
632 { | |
6460 | 633 int off; |
634 | |
6140 | 635 /* Avoid starting halfway a multi-byte character. */ |
636 if (b_insert) | |
637 { | |
6460 | 638 off = (*mb_head_off)(oldp, oldp + offset + spaces); |
6140 | 639 } |
640 else | |
641 { | |
6460 | 642 off = (*mb_off_next)(oldp, oldp + offset); |
6140 | 643 offset += off; |
644 } | |
6460 | 645 spaces -= off; |
646 count -= off; | |
6140 | 647 } |
648 #endif | |
649 | |
7 | 650 newp = alloc_check((unsigned)(STRLEN(oldp)) + s_len + count + 1); |
651 if (newp == NULL) | |
652 continue; | |
653 | |
654 /* copy up to shifted part */ | |
655 mch_memmove(newp, oldp, (size_t)(offset)); | |
656 oldp += offset; | |
657 | |
658 /* insert pre-padding */ | |
6929 | 659 vim_memset(newp + offset, ' ', (size_t)spaces); |
7 | 660 |
661 /* copy the new text */ | |
662 mch_memmove(newp + offset + spaces, s, (size_t)s_len); | |
663 offset += s_len; | |
664 | |
665 if (spaces && !bdp->is_short) | |
666 { | |
667 /* insert post-padding */ | |
6929 | 668 vim_memset(newp + offset + spaces, ' ', (size_t)(p_ts - spaces)); |
7 | 669 /* We're splitting a TAB, don't copy it. */ |
670 oldp++; | |
671 /* We allowed for that TAB, remember this now */ | |
672 count++; | |
673 } | |
674 | |
675 if (spaces > 0) | |
676 offset += count; | |
1622 | 677 STRMOVE(newp + offset, oldp); |
7 | 678 |
679 ml_replace(lnum, newp, FALSE); | |
680 | |
681 if (lnum == oap->end.lnum) | |
682 { | |
683 /* Set "']" mark to the end of the block instead of the end of | |
684 * the insert in the first line. */ | |
685 curbuf->b_op_end.lnum = oap->end.lnum; | |
686 curbuf->b_op_end.col = offset; | |
687 } | |
688 } /* for all lnum */ | |
689 | |
690 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); | |
691 | |
692 State = oldstate; | |
693 } | |
694 #endif | |
695 | |
696 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) || defined(PROTO) | |
697 /* | |
698 * op_reindent - handle reindenting a block of lines. | |
699 */ | |
700 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
701 op_reindent(oparg_T *oap, int (*how)(void)) |
7 | 702 { |
703 long i; | |
704 char_u *l; | |
6971 | 705 int amount; |
7 | 706 linenr_T first_changed = 0; |
707 linenr_T last_changed = 0; | |
708 linenr_T start_lnum = curwin->w_cursor.lnum; | |
709 | |
216 | 710 /* Don't even try when 'modifiable' is off. */ |
711 if (!curbuf->b_p_ma) | |
712 { | |
713 EMSG(_(e_modifiable)); | |
714 return; | |
715 } | |
716 | |
7 | 717 for (i = oap->line_count; --i >= 0 && !got_int; ) |
718 { | |
719 /* it's a slow thing to do, so give feedback so there's no worry that | |
720 * the computer's just hung. */ | |
721 | |
722 if (i > 1 | |
723 && (i % 50 == 0 || i == oap->line_count - 1) | |
724 && oap->line_count > p_report) | |
725 smsg((char_u *)_("%ld lines to indent... "), i); | |
726 | |
727 /* | |
728 * Be vi-compatible: For lisp indenting the first line is not | |
729 * indented, unless there is only one line. | |
730 */ | |
731 #ifdef FEAT_LISP | |
732 if (i != oap->line_count - 1 || oap->line_count == 1 | |
733 || how != get_lisp_indent) | |
734 #endif | |
735 { | |
736 l = skipwhite(ml_get_curline()); | |
737 if (*l == NUL) /* empty or blank line */ | |
6971 | 738 amount = 0; |
7 | 739 else |
6971 | 740 amount = how(); /* get the indent for this line */ |
741 | |
742 if (amount >= 0 && set_indent(amount, SIN_UNDO)) | |
7 | 743 { |
744 /* did change the indent, call changed_lines() later */ | |
745 if (first_changed == 0) | |
746 first_changed = curwin->w_cursor.lnum; | |
747 last_changed = curwin->w_cursor.lnum; | |
748 } | |
749 } | |
750 ++curwin->w_cursor.lnum; | |
1550 | 751 curwin->w_cursor.col = 0; /* make sure it's valid */ |
7 | 752 } |
753 | |
754 /* put cursor on first non-blank of indented line */ | |
755 curwin->w_cursor.lnum = start_lnum; | |
756 beginline(BL_SOL | BL_FIX); | |
757 | |
758 /* Mark changed lines so that they will be redrawn. When Visual | |
759 * highlighting was present, need to continue until the last line. When | |
760 * there is no change still need to remove the Visual highlighting. */ | |
761 if (last_changed != 0) | |
762 changed_lines(first_changed, 0, | |
763 oap->is_VIsual ? start_lnum + oap->line_count : | |
764 last_changed + 1, 0L); | |
765 else if (oap->is_VIsual) | |
766 redraw_curbuf_later(INVERTED); | |
767 | |
768 if (oap->line_count > p_report) | |
769 { | |
770 i = oap->line_count - (i + 1); | |
771 if (i == 1) | |
772 MSG(_("1 line indented ")); | |
773 else | |
774 smsg((char_u *)_("%ld lines indented "), i); | |
775 } | |
776 /* set '[ and '] marks */ | |
777 curbuf->b_op_start = oap->start; | |
778 curbuf->b_op_end = oap->end; | |
779 } | |
780 #endif /* defined(FEAT_LISP) || defined(FEAT_CINDENT) */ | |
781 | |
782 #if defined(FEAT_EVAL) || defined(PROTO) | |
783 /* | |
784 * Keep the last expression line here, for repeating. | |
785 */ | |
786 static char_u *expr_line = NULL; | |
787 | |
788 /* | |
789 * Get an expression for the "\"=expr1" or "CTRL-R =expr1" | |
790 * Returns '=' when OK, NUL otherwise. | |
791 */ | |
792 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
793 get_expr_register(void) |
7 | 794 { |
795 char_u *new_line; | |
796 | |
797 new_line = getcmdline('=', 0L, 0); | |
798 if (new_line == NULL) | |
799 return NUL; | |
800 if (*new_line == NUL) /* use previous line */ | |
801 vim_free(new_line); | |
802 else | |
803 set_expr_line(new_line); | |
804 return '='; | |
805 } | |
806 | |
807 /* | |
808 * Set the expression for the '=' register. | |
809 * Argument must be an allocated string. | |
810 */ | |
811 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
812 set_expr_line(char_u *new_line) |
7 | 813 { |
814 vim_free(expr_line); | |
815 expr_line = new_line; | |
816 } | |
817 | |
818 /* | |
819 * Get the result of the '=' register expression. | |
820 * Returns a pointer to allocated memory, or NULL for failure. | |
821 */ | |
822 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
823 get_expr_line(void) |
7 | 824 { |
825 char_u *expr_copy; | |
826 char_u *rv; | |
994 | 827 static int nested = 0; |
7 | 828 |
829 if (expr_line == NULL) | |
830 return NULL; | |
831 | |
832 /* Make a copy of the expression, because evaluating it may cause it to be | |
833 * changed. */ | |
834 expr_copy = vim_strsave(expr_line); | |
835 if (expr_copy == NULL) | |
836 return NULL; | |
837 | |
994 | 838 /* When we are invoked recursively limit the evaluation to 10 levels. |
839 * Then return the string as-is. */ | |
840 if (nested >= 10) | |
841 return expr_copy; | |
842 | |
843 ++nested; | |
714 | 844 rv = eval_to_string(expr_copy, NULL, TRUE); |
994 | 845 --nested; |
7 | 846 vim_free(expr_copy); |
847 return rv; | |
848 } | |
283 | 849 |
850 /* | |
851 * Get the '=' register expression itself, without evaluating it. | |
852 */ | |
853 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
854 get_expr_line_src(void) |
283 | 855 { |
856 if (expr_line == NULL) | |
857 return NULL; | |
858 return vim_strsave(expr_line); | |
859 } | |
7 | 860 #endif /* FEAT_EVAL */ |
861 | |
862 /* | |
863 * Check if 'regname' is a valid name of a yank register. | |
864 * Note: There is no check for 0 (default register), caller should do this | |
865 */ | |
866 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
867 valid_yank_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
868 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
869 int writing) /* if TRUE check for writable registers */ |
7 | 870 { |
871 if ( (regname > 0 && ASCII_ISALNUM(regname)) | |
872 || (!writing && vim_strchr((char_u *) | |
873 #ifdef FEAT_EVAL | |
6557 | 874 "/.%:=" |
7 | 875 #else |
6557 | 876 "/.%:" |
7 | 877 #endif |
878 , regname) != NULL) | |
6557 | 879 || regname == '#' |
7 | 880 || regname == '"' |
881 || regname == '-' | |
882 || regname == '_' | |
883 #ifdef FEAT_CLIPBOARD | |
884 || regname == '*' | |
885 || regname == '+' | |
886 #endif | |
887 #ifdef FEAT_DND | |
888 || (!writing && regname == '~') | |
889 #endif | |
890 ) | |
891 return TRUE; | |
892 return FALSE; | |
893 } | |
894 | |
895 /* | |
896 * Set y_current and y_append, according to the value of "regname". | |
897 * Cannot handle the '_' register. | |
140 | 898 * Must only be called with a valid register name! |
7 | 899 * |
900 * If regname is 0 and writing, use register 0 | |
901 * If regname is 0 and reading, use previous register | |
902 */ | |
15 | 903 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
904 get_yank_register(int regname, int writing) |
7 | 905 { |
906 int i; | |
907 | |
908 y_append = FALSE; | |
909 if ((regname == 0 || regname == '"') && !writing && y_previous != NULL) | |
910 { | |
911 y_current = y_previous; | |
912 return; | |
913 } | |
914 i = regname; | |
915 if (VIM_ISDIGIT(i)) | |
916 i -= '0'; | |
917 else if (ASCII_ISLOWER(i)) | |
918 i = CharOrdLow(i) + 10; | |
919 else if (ASCII_ISUPPER(i)) | |
920 { | |
921 i = CharOrdUp(i) + 10; | |
922 y_append = TRUE; | |
923 } | |
924 else if (regname == '-') | |
925 i = DELETION_REGISTER; | |
926 #ifdef FEAT_CLIPBOARD | |
927 /* When selection is not available, use register 0 instead of '*' */ | |
928 else if (clip_star.available && regname == '*') | |
929 i = STAR_REGISTER; | |
930 /* When clipboard is not available, use register 0 instead of '+' */ | |
931 else if (clip_plus.available && regname == '+') | |
932 i = PLUS_REGISTER; | |
933 #endif | |
934 #ifdef FEAT_DND | |
935 else if (!writing && regname == '~') | |
936 i = TILDE_REGISTER; | |
937 #endif | |
938 else /* not 0-9, a-z, A-Z or '-': use register 0 */ | |
939 i = 0; | |
940 y_current = &(y_regs[i]); | |
941 if (writing) /* remember the register we write into for do_put() */ | |
942 y_previous = y_current; | |
943 } | |
944 | |
15 | 945 #if defined(FEAT_CLIPBOARD) || defined(PROTO) |
7 | 946 /* |
947 * When "regname" is a clipboard register, obtain the selection. If it's not | |
948 * available return zero, otherwise return "regname". | |
949 */ | |
15 | 950 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
951 may_get_selection(int regname) |
7 | 952 { |
953 if (regname == '*') | |
954 { | |
955 if (!clip_star.available) | |
956 regname = 0; | |
957 else | |
958 clip_get_selection(&clip_star); | |
959 } | |
960 else if (regname == '+') | |
961 { | |
962 if (!clip_plus.available) | |
963 regname = 0; | |
964 else | |
965 clip_get_selection(&clip_plus); | |
966 } | |
967 return regname; | |
968 } | |
969 #endif | |
970 | |
971 /* | |
972 * Obtain the contents of a "normal" register. The register is made empty. | |
973 * The returned pointer has allocated memory, use put_register() later. | |
974 */ | |
975 void * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
976 get_register( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
977 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
978 int copy) /* make a copy, if FALSE make register empty. */ |
7 | 979 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
980 yankreg_T *reg; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
981 int i; |
7 | 982 |
983 #ifdef FEAT_CLIPBOARD | |
984 /* When Visual area changed, may have to update selection. Obtain the | |
985 * selection too. */ | |
1435 | 986 if (name == '*' && clip_star.available) |
7 | 987 { |
3674 | 988 if (clip_isautosel_star()) |
989 clip_update_selection(&clip_star); | |
990 may_get_selection(name); | |
991 } | |
992 if (name == '+' && clip_plus.available) | |
993 { | |
994 if (clip_isautosel_plus()) | |
995 clip_update_selection(&clip_plus); | |
7 | 996 may_get_selection(name); |
997 } | |
998 #endif | |
999 | |
1000 get_yank_register(name, 0); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1001 reg = (yankreg_T *)alloc((unsigned)sizeof(yankreg_T)); |
7 | 1002 if (reg != NULL) |
1003 { | |
1004 *reg = *y_current; | |
1005 if (copy) | |
1006 { | |
1007 /* If we run out of memory some or all of the lines are empty. */ | |
1008 if (reg->y_size == 0) | |
1009 reg->y_array = NULL; | |
1010 else | |
1011 reg->y_array = (char_u **)alloc((unsigned)(sizeof(char_u *) | |
1012 * reg->y_size)); | |
1013 if (reg->y_array != NULL) | |
1014 { | |
1015 for (i = 0; i < reg->y_size; ++i) | |
1016 reg->y_array[i] = vim_strsave(y_current->y_array[i]); | |
1017 } | |
1018 } | |
1019 else | |
1020 y_current->y_array = NULL; | |
1021 } | |
1022 return (void *)reg; | |
1023 } | |
1024 | |
1025 /* | |
1451 | 1026 * Put "reg" into register "name". Free any previous contents and "reg". |
7 | 1027 */ |
1028 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1029 put_register(int name, void *reg) |
7 | 1030 { |
1031 get_yank_register(name, 0); | |
1032 free_yank_all(); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1033 *y_current = *(yankreg_T *)reg; |
1451 | 1034 vim_free(reg); |
7 | 1035 |
5735 | 1036 #ifdef FEAT_CLIPBOARD |
7 | 1037 /* Send text written to clipboard register to the clipboard. */ |
1038 may_set_selection(); | |
5735 | 1039 #endif |
7 | 1040 } |
4209 | 1041 |
1042 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1043 free_register(void *reg) |
4209 | 1044 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1045 yankreg_T tmp; |
4209 | 1046 |
1047 tmp = *y_current; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1048 *y_current = *(yankreg_T *)reg; |
4209 | 1049 free_yank_all(); |
1050 vim_free(reg); | |
1051 *y_current = tmp; | |
1052 } | |
7 | 1053 |
1054 #if defined(FEAT_MOUSE) || defined(PROTO) | |
1055 /* | |
1056 * return TRUE if the current yank register has type MLINE | |
1057 */ | |
1058 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1059 yank_register_mline(int regname) |
7 | 1060 { |
1061 if (regname != 0 && !valid_yank_reg(regname, FALSE)) | |
1062 return FALSE; | |
1063 if (regname == '_') /* black hole is always empty */ | |
1064 return FALSE; | |
1065 get_yank_register(regname, FALSE); | |
1066 return (y_current->y_type == MLINE); | |
1067 } | |
1068 #endif | |
1069 | |
1070 /* | |
1157 | 1071 * Start or stop recording into a yank register. |
7 | 1072 * |
1157 | 1073 * Return FAIL for failure, OK otherwise. |
7 | 1074 */ |
1075 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1076 do_record(int c) |
7 | 1077 { |
1157 | 1078 char_u *p; |
1079 static int regname; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1080 yankreg_T *old_y_previous, *old_y_current; |
1157 | 1081 int retval; |
7 | 1082 |
1083 if (Recording == FALSE) /* start recording */ | |
1084 { | |
1085 /* registers 0-9, a-z and " are allowed */ | |
1086 if (c < 0 || (!ASCII_ISALNUM(c) && c != '"')) | |
1087 retval = FAIL; | |
1088 else | |
1089 { | |
7233
9487ea110214
commit https://github.com/vim/vim/commit/a0ed84a26897c994512873a895b9fc54e90c6845
Christian Brabandt <cb@256bit.org>
parents:
7011
diff
changeset
|
1090 Recording = c; |
7 | 1091 showmode(); |
1092 regname = c; | |
1093 retval = OK; | |
1094 } | |
1095 } | |
1096 else /* stop recording */ | |
1097 { | |
1098 /* | |
1157 | 1099 * Get the recorded key hits. K_SPECIAL and CSI will be escaped, this |
1100 * needs to be removed again to put it in a register. exec_reg then | |
1101 * adds the escaping back later. | |
7 | 1102 */ |
1103 Recording = FALSE; | |
1104 MSG(""); | |
1105 p = get_recorded(); | |
1106 if (p == NULL) | |
1107 retval = FAIL; | |
1108 else | |
1109 { | |
1081 | 1110 /* Remove escaping for CSI and K_SPECIAL in multi-byte chars. */ |
1111 vim_unescape_csi(p); | |
1112 | |
7 | 1113 /* |
1114 * We don't want to change the default register here, so save and | |
1115 * restore the current register name. | |
1116 */ | |
1117 old_y_previous = y_previous; | |
1118 old_y_current = y_current; | |
1119 | |
1120 retval = stuff_yank(regname, p); | |
1121 | |
1122 y_previous = old_y_previous; | |
1123 y_current = old_y_current; | |
1124 } | |
1125 } | |
1126 return retval; | |
1127 } | |
1128 | |
1129 /* | |
1130 * Stuff string "p" into yank register "regname" as a single line (append if | |
1131 * uppercase). "p" must have been alloced. | |
1132 * | |
1133 * return FAIL for failure, OK otherwise | |
1134 */ | |
1135 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1136 stuff_yank(int regname, char_u *p) |
7 | 1137 { |
1138 char_u *lp; | |
1139 char_u **pp; | |
1140 | |
1141 /* check for read-only register */ | |
1142 if (regname != 0 && !valid_yank_reg(regname, TRUE)) | |
1143 { | |
1144 vim_free(p); | |
1145 return FAIL; | |
1146 } | |
1147 if (regname == '_') /* black hole: don't do anything */ | |
1148 { | |
1149 vim_free(p); | |
1150 return OK; | |
1151 } | |
1152 get_yank_register(regname, TRUE); | |
1153 if (y_append && y_current->y_array != NULL) | |
1154 { | |
1155 pp = &(y_current->y_array[y_current->y_size - 1]); | |
1156 lp = lalloc((long_u)(STRLEN(*pp) + STRLEN(p) + 1), TRUE); | |
1157 if (lp == NULL) | |
1158 { | |
1159 vim_free(p); | |
1160 return FAIL; | |
1161 } | |
1162 STRCPY(lp, *pp); | |
1163 STRCAT(lp, p); | |
1164 vim_free(p); | |
1165 vim_free(*pp); | |
1166 *pp = lp; | |
1167 } | |
1168 else | |
1169 { | |
1170 free_yank_all(); | |
1171 if ((y_current->y_array = | |
1172 (char_u **)alloc((unsigned)sizeof(char_u *))) == NULL) | |
1173 { | |
1174 vim_free(p); | |
1175 return FAIL; | |
1176 } | |
1177 y_current->y_array[0] = p; | |
1178 y_current->y_size = 1; | |
1179 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
|
1180 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1181 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
|
1182 #endif |
7 | 1183 } |
1184 return OK; | |
1185 } | |
1186 | |
1893 | 1187 static int execreg_lastc = NUL; |
1188 | |
7 | 1189 /* |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
1190 * Execute a yank register: copy it into the stuff buffer. |
7 | 1191 * |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
1192 * Return FAIL for failure, OK otherwise. |
7 | 1193 */ |
1194 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1195 do_execreg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1196 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1197 int colon, /* insert ':' before each line */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1198 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
|
1199 int silent) /* set "silent" flag in typeahead buffer */ |
7 | 1200 { |
1201 long i; | |
1202 char_u *p; | |
1203 int retval = OK; | |
1204 int remap; | |
1205 | |
1206 if (regname == '@') /* repeat previous one */ | |
168 | 1207 { |
1893 | 1208 if (execreg_lastc == NUL) |
168 | 1209 { |
1210 EMSG(_("E748: No previously used register")); | |
1211 return FAIL; | |
1212 } | |
1893 | 1213 regname = execreg_lastc; |
168 | 1214 } |
7 | 1215 /* check for valid regname */ |
1216 if (regname == '%' || regname == '#' || !valid_yank_reg(regname, FALSE)) | |
168 | 1217 { |
1218 emsg_invreg(regname); | |
7 | 1219 return FAIL; |
168 | 1220 } |
1893 | 1221 execreg_lastc = regname; |
7 | 1222 |
1223 #ifdef FEAT_CLIPBOARD | |
1224 regname = may_get_selection(regname); | |
1225 #endif | |
1226 | |
1227 if (regname == '_') /* black hole: don't stuff anything */ | |
1228 return OK; | |
1229 | |
1230 #ifdef FEAT_CMDHIST | |
1231 if (regname == ':') /* use last command line */ | |
1232 { | |
1233 if (last_cmdline == NULL) | |
1234 { | |
1235 EMSG(_(e_nolastcmd)); | |
1236 return FAIL; | |
1237 } | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
1238 VIM_CLEAR(new_last_cmdline); /* don't keep the cmdline containing @: */ |
16 | 1239 /* Escape all control characters with a CTRL-V */ |
1240 p = vim_strsave_escaped_ext(last_cmdline, | |
20 | 1241 (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 | 1242 if (p != NULL) |
480 | 1243 { |
1244 /* When in Visual mode "'<,'>" will be prepended to the command. | |
1245 * Remove it when it's already there. */ | |
1246 if (VIsual_active && STRNCMP(p, "'<,'>", 5) == 0) | |
1077 | 1247 retval = put_in_typebuf(p + 5, TRUE, TRUE, silent); |
480 | 1248 else |
1077 | 1249 retval = put_in_typebuf(p, TRUE, TRUE, silent); |
480 | 1250 } |
16 | 1251 vim_free(p); |
7 | 1252 } |
1253 #endif | |
1254 #ifdef FEAT_EVAL | |
1255 else if (regname == '=') | |
1256 { | |
1257 p = get_expr_line(); | |
1258 if (p == NULL) | |
1259 return FAIL; | |
1077 | 1260 retval = put_in_typebuf(p, TRUE, colon, silent); |
7 | 1261 vim_free(p); |
1262 } | |
1263 #endif | |
1264 else if (regname == '.') /* use last inserted text */ | |
1265 { | |
1266 p = get_last_insert_save(); | |
1267 if (p == NULL) | |
1268 { | |
1269 EMSG(_(e_noinstext)); | |
1270 return FAIL; | |
1271 } | |
1077 | 1272 retval = put_in_typebuf(p, FALSE, colon, silent); |
7 | 1273 vim_free(p); |
1274 } | |
1275 else | |
1276 { | |
1277 get_yank_register(regname, FALSE); | |
1278 if (y_current->y_array == NULL) | |
1279 return FAIL; | |
1280 | |
1281 /* Disallow remaping for ":@r". */ | |
1282 remap = colon ? REMAP_NONE : REMAP_YES; | |
1283 | |
1284 /* | |
1285 * Insert lines into typeahead buffer, from last one to first one. | |
1286 */ | |
1034 | 1287 put_reedit_in_typebuf(silent); |
7 | 1288 for (i = y_current->y_size; --i >= 0; ) |
1289 { | |
1077 | 1290 char_u *escaped; |
1291 | |
7 | 1292 /* insert NL between lines and after last line if type is MLINE */ |
1293 if (y_current->y_type == MLINE || i < y_current->y_size - 1 | |
1294 || addcr) | |
1295 { | |
1034 | 1296 if (ins_typebuf((char_u *)"\n", remap, 0, TRUE, silent) == FAIL) |
7 | 1297 return FAIL; |
1298 } | |
1077 | 1299 escaped = vim_strsave_escape_csi(y_current->y_array[i]); |
1300 if (escaped == NULL) | |
1301 return FAIL; | |
1302 retval = ins_typebuf(escaped, remap, 0, TRUE, silent); | |
1303 vim_free(escaped); | |
1304 if (retval == FAIL) | |
7 | 1305 return FAIL; |
1034 | 1306 if (colon && ins_typebuf((char_u *)":", remap, 0, TRUE, silent) |
7 | 1307 == FAIL) |
1308 return FAIL; | |
1309 } | |
1310 Exec_reg = TRUE; /* disable the 'q' command */ | |
1311 } | |
1312 return retval; | |
1313 } | |
1314 | |
1315 /* | |
1316 * If "restart_edit" is not zero, put it in the typeahead buffer, so that it's | |
1317 * used only after other typeahead has been processed. | |
1318 */ | |
1319 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1320 put_reedit_in_typebuf(int silent) |
7 | 1321 { |
1322 char_u buf[3]; | |
1323 | |
1324 if (restart_edit != NUL) | |
1325 { | |
1326 if (restart_edit == 'V') | |
1327 { | |
1328 buf[0] = 'g'; | |
1329 buf[1] = 'R'; | |
1330 buf[2] = NUL; | |
1331 } | |
1332 else | |
1333 { | |
1334 buf[0] = restart_edit == 'I' ? 'i' : restart_edit; | |
1335 buf[1] = NUL; | |
1336 } | |
1034 | 1337 if (ins_typebuf(buf, REMAP_NONE, 0, TRUE, silent) == OK) |
7 | 1338 restart_edit = NUL; |
1339 } | |
1340 } | |
1341 | |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1342 /* |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1343 * 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
|
1344 * executed again. |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1345 * 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
|
1346 * no remapping. |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1347 */ |
7 | 1348 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1349 put_in_typebuf( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1350 char_u *s, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1351 int esc, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1352 int colon, /* add ':' before the line */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1353 int silent) |
7 | 1354 { |
1355 int retval = OK; | |
1356 | |
1034 | 1357 put_reedit_in_typebuf(silent); |
7 | 1358 if (colon) |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1359 retval = ins_typebuf((char_u *)"\n", REMAP_NONE, 0, TRUE, silent); |
7 | 1360 if (retval == OK) |
1077 | 1361 { |
1362 char_u *p; | |
1363 | |
1364 if (esc) | |
1365 p = vim_strsave_escape_csi(s); | |
1366 else | |
1367 p = s; | |
1368 if (p == NULL) | |
1369 retval = FAIL; | |
1370 else | |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1371 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
|
1372 0, TRUE, silent); |
1077 | 1373 if (esc) |
1374 vim_free(p); | |
1375 } | |
7 | 1376 if (colon && retval == OK) |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1377 retval = ins_typebuf((char_u *)":", REMAP_NONE, 0, TRUE, silent); |
7 | 1378 return retval; |
1379 } | |
1380 | |
1381 /* | |
1382 * Insert a yank register: copy it into the Read buffer. | |
1383 * Used by CTRL-R command and middle mouse button in insert mode. | |
1384 * | |
1385 * return FAIL for failure, OK otherwise | |
1386 */ | |
1387 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1388 insert_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1389 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1390 int literally) /* insert literally, not as if typed */ |
7 | 1391 { |
1392 long i; | |
1393 int retval = OK; | |
1394 char_u *arg; | |
1395 int allocated; | |
1396 | |
1397 /* | |
1398 * It is possible to get into an endless loop by having CTRL-R a in | |
1399 * register a and then, in insert mode, doing CTRL-R a. | |
1400 * If you hit CTRL-C, the loop will be broken here. | |
1401 */ | |
1402 ui_breakcheck(); | |
1403 if (got_int) | |
1404 return FAIL; | |
1405 | |
1406 /* check for valid regname */ | |
1407 if (regname != NUL && !valid_yank_reg(regname, FALSE)) | |
1408 return FAIL; | |
1409 | |
1410 #ifdef FEAT_CLIPBOARD | |
1411 regname = may_get_selection(regname); | |
1412 #endif | |
1413 | |
1414 if (regname == '.') /* insert last inserted text */ | |
1415 retval = stuff_inserted(NUL, 1L, TRUE); | |
1416 else if (get_spec_reg(regname, &arg, &allocated, TRUE)) | |
1417 { | |
1418 if (arg == NULL) | |
1419 return FAIL; | |
1420 stuffescaped(arg, literally); | |
1421 if (allocated) | |
1422 vim_free(arg); | |
1423 } | |
1424 else /* name or number register */ | |
1425 { | |
1426 get_yank_register(regname, FALSE); | |
1427 if (y_current->y_array == NULL) | |
1428 retval = FAIL; | |
1429 else | |
1430 { | |
1431 for (i = 0; i < y_current->y_size; ++i) | |
1432 { | |
1433 stuffescaped(y_current->y_array[i], literally); | |
1434 /* | |
1435 * Insert a newline between lines and after last line if | |
1436 * y_type is MLINE. | |
1437 */ | |
1438 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | |
1439 stuffcharReadbuff('\n'); | |
1440 } | |
1441 } | |
1442 } | |
1443 | |
1444 return retval; | |
1445 } | |
1446 | |
1447 /* | |
1448 * Stuff a string into the typeahead buffer, such that edit() will insert it | |
1449 * literally ("literally" TRUE) or interpret is as typed characters. | |
1450 */ | |
1451 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1452 stuffescaped(char_u *arg, int literally) |
7 | 1453 { |
1454 int c; | |
1455 char_u *start; | |
1456 | |
1457 while (*arg != NUL) | |
1458 { | |
1459 /* Stuff a sequence of normal ASCII characters, that's fast. Also | |
1460 * stuff K_SPECIAL to get the effect of a special key when "literally" | |
1461 * is TRUE. */ | |
1462 start = arg; | |
1463 while ((*arg >= ' ' | |
1464 #ifndef EBCDIC | |
1465 && *arg < DEL /* EBCDIC: chars above space are normal */ | |
1466 #endif | |
1467 ) | |
1468 || (*arg == K_SPECIAL && !literally)) | |
1469 ++arg; | |
1470 if (arg > start) | |
1471 stuffReadbuffLen(start, (long)(arg - start)); | |
1472 | |
1473 /* stuff a single special character */ | |
1474 if (*arg != NUL) | |
1475 { | |
1476 #ifdef FEAT_MBYTE | |
1477 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
|
1478 c = mb_cptr2char_adv(&arg); |
7 | 1479 else |
1480 #endif | |
1481 c = *arg++; | |
1482 if (literally && ((c < ' ' && c != TAB) || c == DEL)) | |
1483 stuffcharReadbuff(Ctrl_V); | |
1484 stuffcharReadbuff(c); | |
1485 } | |
1486 } | |
1487 } | |
1488 | |
1489 /* | |
1157 | 1490 * If "regname" is a special register, return TRUE and store a pointer to its |
1491 * value in "argp". | |
7 | 1492 */ |
15 | 1493 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1494 get_spec_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1495 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1496 char_u **argp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1497 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
|
1498 int errmsg) /* give error message when failing */ |
7 | 1499 { |
1500 int cnt; | |
1501 | |
1502 *argp = NULL; | |
1503 *allocated = FALSE; | |
1504 switch (regname) | |
1505 { | |
1506 case '%': /* file name */ | |
1507 if (errmsg) | |
1508 check_fname(); /* will give emsg if not set */ | |
1509 *argp = curbuf->b_fname; | |
1510 return TRUE; | |
1511 | |
1512 case '#': /* alternate file name */ | |
1513 *argp = getaltfname(errmsg); /* may give emsg if not set */ | |
1514 return TRUE; | |
1515 | |
1516 #ifdef FEAT_EVAL | |
1517 case '=': /* result of expression */ | |
1518 *argp = get_expr_line(); | |
1519 *allocated = TRUE; | |
1520 return TRUE; | |
1521 #endif | |
1522 | |
1523 case ':': /* last command line */ | |
1524 if (last_cmdline == NULL && errmsg) | |
1525 EMSG(_(e_nolastcmd)); | |
1526 *argp = last_cmdline; | |
1527 return TRUE; | |
1528 | |
1529 case '/': /* last search-pattern */ | |
1530 if (last_search_pat() == NULL && errmsg) | |
1531 EMSG(_(e_noprevre)); | |
1532 *argp = last_search_pat(); | |
1533 return TRUE; | |
1534 | |
1535 case '.': /* last inserted text */ | |
1536 *argp = get_last_insert_save(); | |
1537 *allocated = TRUE; | |
1538 if (*argp == NULL && errmsg) | |
1539 EMSG(_(e_noinstext)); | |
1540 return TRUE; | |
1541 | |
1542 #ifdef FEAT_SEARCHPATH | |
1543 case Ctrl_F: /* Filename under cursor */ | |
1544 case Ctrl_P: /* Path under cursor, expand via "path" */ | |
1545 if (!errmsg) | |
1546 return FALSE; | |
1547 *argp = file_name_at_cursor(FNAME_MESS | FNAME_HYP | |
681 | 1548 | (regname == Ctrl_P ? FNAME_EXP : 0), 1L, NULL); |
7 | 1549 *allocated = TRUE; |
1550 return TRUE; | |
1551 #endif | |
1552 | |
1553 case Ctrl_W: /* word under cursor */ | |
1554 case Ctrl_A: /* WORD (mnemonic All) under cursor */ | |
1555 if (!errmsg) | |
1556 return FALSE; | |
1557 cnt = find_ident_under_cursor(argp, regname == Ctrl_W | |
1558 ? (FIND_IDENT|FIND_STRING) : FIND_STRING); | |
1559 *argp = cnt ? vim_strnsave(*argp, cnt) : NULL; | |
1560 *allocated = TRUE; | |
1561 return TRUE; | |
1562 | |
1563 case '_': /* black hole: always empty */ | |
1564 *argp = (char_u *)""; | |
1565 return TRUE; | |
1566 } | |
1567 | |
1568 return FALSE; | |
1569 } | |
1570 | |
1571 /* | |
15 | 1572 * Paste a yank register into the command line. |
1573 * Only for non-special registers. | |
1574 * Used by CTRL-R command in command-line mode | |
7 | 1575 * insert_reg() can't be used here, because special characters from the |
1576 * register contents will be interpreted as commands. | |
1577 * | |
1578 * return FAIL for failure, OK otherwise | |
1579 */ | |
1580 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1581 cmdline_paste_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1582 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1583 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
|
1584 int remcr) /* don't add CR characters */ |
7 | 1585 { |
1586 long i; | |
1587 | |
1588 get_yank_register(regname, FALSE); | |
1589 if (y_current->y_array == NULL) | |
1590 return FAIL; | |
1591 | |
1592 for (i = 0; i < y_current->y_size; ++i) | |
1593 { | |
1594 cmdline_paste_str(y_current->y_array[i], literally); | |
1595 | |
1015 | 1596 /* 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
|
1597 * 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
|
1598 if ((y_current->y_type == MLINE || i < y_current->y_size - 1) && !remcr) |
7 | 1599 cmdline_paste_str((char_u *)"\r", literally); |
1600 | |
1601 /* Check for CTRL-C, in case someone tries to paste a few thousand | |
1602 * lines and gets bored. */ | |
1603 ui_breakcheck(); | |
1604 if (got_int) | |
1605 return FAIL; | |
1606 } | |
1607 return OK; | |
1608 } | |
1609 | |
1610 #if defined(FEAT_CLIPBOARD) || defined(PROTO) | |
1611 /* | |
1612 * Adjust the register name pointed to with "rp" for the clipboard being | |
1613 * used always and the clipboard being available. | |
1614 */ | |
1615 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1616 adjust_clip_reg(int *rp) |
7 | 1617 { |
2654 | 1618 /* If no reg. specified, and "unnamed" or "unnamedplus" is in 'clipboard', |
1619 * use '*' or '+' reg, respectively. "unnamedplus" prevails. */ | |
6116 | 1620 if (*rp == 0 && (clip_unnamed != 0 || clip_unnamed_saved != 0)) |
1621 { | |
1622 if (clip_unnamed != 0) | |
1623 *rp = ((clip_unnamed & CLIP_UNNAMED_PLUS) && clip_plus.available) | |
2654 | 1624 ? '+' : '*'; |
6116 | 1625 else |
1626 *rp = ((clip_unnamed_saved & CLIP_UNNAMED_PLUS) && clip_plus.available) | |
1627 ? '+' : '*'; | |
1628 } | |
7 | 1629 if (!clip_star.available && *rp == '*') |
1630 *rp = 0; | |
1631 if (!clip_plus.available && *rp == '+') | |
1632 *rp = 0; | |
1633 } | |
1634 #endif | |
1635 | |
1636 /* | |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1637 * Shift the delete registers: "9 is cleared, "8 becomes "9, etc. |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1638 */ |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1639 void |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1640 shift_delete_registers() |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1641 { |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1642 int n; |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1643 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1644 y_current = &y_regs[9]; |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1645 free_yank_all(); /* free register nine */ |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1646 for (n = 9; n > 1; --n) |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1647 y_regs[n] = y_regs[n - 1]; |
11597
72b20190dce6
patch 8.0.0681: unnamed register only contains the last deleted text
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
1648 y_current = &y_regs[1]; |
72b20190dce6
patch 8.0.0681: unnamed register only contains the last deleted text
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
1649 if (!y_append) |
72b20190dce6
patch 8.0.0681: unnamed register only contains the last deleted text
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
1650 y_previous = y_current; |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1651 y_regs[1].y_array = NULL; /* set register one to empty */ |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1652 } |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1653 |
13047
669c4f75a69e
patch 8.0.1399: warnings and errors when building tiny version
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
1654 #ifdef FEAT_AUTOCMD |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1655 static void |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1656 yank_do_autocmd(oparg_T *oap, yankreg_T *reg) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1657 { |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1658 static int recursive = FALSE; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1659 dict_T *v_event; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1660 list_T *list; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1661 int n; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1662 char_u buf[NUMBUFLEN + 2]; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1663 long reglen = 0; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1664 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1665 if (recursive) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1666 return; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1667 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1668 v_event = get_vim_var_dict(VV_EVENT); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1669 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1670 list = list_alloc(); |
13254
88cc06dc1a50
patch 8.0.1501: out-of-memory situation not correctly handled
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1671 if (list == NULL) |
88cc06dc1a50
patch 8.0.1501: out-of-memory situation not correctly handled
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1672 return; |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1673 for (n = 0; n < reg->y_size; n++) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1674 list_append_string(list, reg->y_array[n], -1); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1675 list->lv_lock = VAR_FIXED; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1676 dict_add_list(v_event, "regcontents", list); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1677 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1678 buf[0] = (char_u)oap->regname; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1679 buf[1] = NUL; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1680 dict_add_nr_str(v_event, "regname", 0, buf); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1681 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1682 buf[0] = get_op_char(oap->op_type); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1683 buf[1] = get_extra_op_char(oap->op_type); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1684 buf[2] = NUL; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1685 dict_add_nr_str(v_event, "operator", 0, buf); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1686 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1687 buf[0] = NUL; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1688 buf[1] = NUL; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1689 switch (get_reg_type(oap->regname, ®len)) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1690 { |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1691 case MLINE: buf[0] = 'V'; break; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1692 case MCHAR: buf[0] = 'v'; break; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1693 case MBLOCK: |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1694 vim_snprintf((char *)buf, sizeof(buf), "%c%ld", Ctrl_V, |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1695 reglen + 1); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1696 break; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1697 } |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1698 dict_add_nr_str(v_event, "regtype", 0, buf); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1699 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1700 /* Lock the dictionary and its keys */ |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1701 dict_set_items_ro(v_event); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1702 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1703 recursive = TRUE; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1704 textlock++; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1705 apply_autocmds(EVENT_TEXTYANKPOST, NULL, NULL, FALSE, curbuf); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1706 textlock--; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1707 recursive = FALSE; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1708 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1709 /* Empty the dictionary, v:event is still valid */ |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1710 dict_free_contents(v_event); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1711 hash_init(&v_event->dv_hashtab); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1712 } |
13047
669c4f75a69e
patch 8.0.1399: warnings and errors when building tiny version
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
1713 #endif |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1714 |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1715 /* |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1716 * Handle a delete operation. |
7 | 1717 * |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1718 * Return FAIL if undo failed, OK otherwise. |
7 | 1719 */ |
1720 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1721 op_delete(oparg_T *oap) |
7 | 1722 { |
1723 int n; | |
1724 linenr_T lnum; | |
1725 char_u *ptr; | |
1726 char_u *newp, *oldp; | |
1727 struct block_def bd; | |
1728 linenr_T old_lcount = curbuf->b_ml.ml_line_count; | |
1729 int did_yank = FALSE; | |
3782 | 1730 int orig_regname = oap->regname; |
7 | 1731 |
1732 if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to do */ | |
1733 return OK; | |
1734 | |
1735 /* Nothing to delete, return here. Do prepare undo, for op_change(). */ | |
1736 if (oap->empty) | |
1737 return u_save_cursor(); | |
1738 | |
1739 if (!curbuf->b_p_ma) | |
1740 { | |
1741 EMSG(_(e_modifiable)); | |
1742 return FAIL; | |
1743 } | |
1744 | |
1745 #ifdef FEAT_CLIPBOARD | |
1746 adjust_clip_reg(&oap->regname); | |
1747 #endif | |
1748 | |
1749 #ifdef FEAT_MBYTE | |
1750 if (has_mbyte) | |
1751 mb_adjust_opend(oap); | |
1752 #endif | |
1753 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1754 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1755 * 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
|
1756 * 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
|
1757 * 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
|
1758 */ |
7 | 1759 if ( oap->motion_type == MCHAR |
1760 && !oap->is_VIsual | |
50 | 1761 && !oap->block_mode |
7 | 1762 && oap->line_count > 1 |
3254 | 1763 && oap->motion_force == NUL |
7 | 1764 && oap->op_type == OP_DELETE) |
1765 { | |
2957 | 1766 ptr = ml_get(oap->end.lnum) + oap->end.col; |
1767 if (*ptr != NUL) | |
1768 ptr += oap->inclusive; | |
7 | 1769 ptr = skipwhite(ptr); |
1770 if (*ptr == NUL && inindent(0)) | |
1771 oap->motion_type = MLINE; | |
1772 } | |
1773 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1774 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1775 * 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
|
1776 * 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
|
1777 */ |
7 | 1778 if ( oap->motion_type == MCHAR |
1779 && oap->line_count == 1 | |
1780 && oap->op_type == OP_DELETE | |
1781 && *ml_get(oap->start.lnum) == NUL) | |
1782 { | |
1783 /* | |
446 | 1784 * It's an error to operate on an empty region, when 'E' included in |
7 | 1785 * 'cpoptions' (Vi compatible). |
1786 */ | |
446 | 1787 #ifdef FEAT_VIRTUALEDIT |
1788 if (virtual_op) | |
1789 /* Virtual editing: Nothing gets deleted, but we set the '[ and '] | |
1790 * marks as if it happened. */ | |
1791 goto setmarks; | |
1792 #endif | |
7 | 1793 if (vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL) |
1794 beep_flush(); | |
1795 return OK; | |
1796 } | |
1797 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1798 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1799 * 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
|
1800 * 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
|
1801 * 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
|
1802 */ |
7 | 1803 if (oap->regname != '_') |
1804 { | |
1805 if (oap->regname != 0) | |
1806 { | |
1807 /* check for read-only register */ | |
1808 if (!valid_yank_reg(oap->regname, TRUE)) | |
1809 { | |
1810 beep_flush(); | |
1811 return OK; | |
1812 } | |
1813 get_yank_register(oap->regname, TRUE); /* yank into specif'd reg. */ | |
1814 if (op_yank(oap, TRUE, FALSE) == OK) /* yank without message */ | |
1815 did_yank = TRUE; | |
1816 } | |
1817 | |
1818 /* | |
1819 * Put deleted text into register 1 and shift number registers if the | |
1820 * delete contains a line break, or when a regname has been specified. | |
3782 | 1821 * Use the register name from before adjust_clip_reg() may have |
1822 * changed it. | |
7 | 1823 */ |
3782 | 1824 if (orig_regname != 0 || oap->motion_type == MLINE |
7 | 1825 || oap->line_count > 1 || oap->use_reg_one) |
1826 { | |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1827 shift_delete_registers(); |
7 | 1828 if (op_yank(oap, TRUE, FALSE) == OK) |
1829 did_yank = TRUE; | |
1830 } | |
1831 | |
3468 | 1832 /* Yank into small delete register when no named register specified |
1833 * and the delete is within one line. */ | |
1834 if (( | |
1835 #ifdef FEAT_CLIPBOARD | |
3584 | 1836 ((clip_unnamed & CLIP_UNNAMED) && oap->regname == '*') || |
1837 ((clip_unnamed & CLIP_UNNAMED_PLUS) && oap->regname == '+') || | |
3468 | 1838 #endif |
1839 oap->regname == 0) && oap->motion_type != MLINE | |
7 | 1840 && oap->line_count == 1) |
1841 { | |
1842 oap->regname = '-'; | |
1843 get_yank_register(oap->regname, TRUE); | |
1844 if (op_yank(oap, TRUE, FALSE) == OK) | |
1845 did_yank = TRUE; | |
1846 oap->regname = 0; | |
1847 } | |
1848 | |
1849 /* | |
1850 * If there's too much stuff to fit in the yank register, then get a | |
1851 * confirmation before doing the delete. This is crude, but simple. | |
1852 * And it avoids doing a delete of something we can't put back if we | |
1853 * want. | |
1854 */ | |
1855 if (!did_yank) | |
1856 { | |
1857 int msg_silent_save = msg_silent; | |
1858 | |
1859 msg_silent = 0; /* must display the prompt */ | |
1860 n = ask_yesno((char_u *)_("cannot yank; delete anyway"), TRUE); | |
1861 msg_silent = msg_silent_save; | |
1862 if (n != 'y') | |
1863 { | |
1864 EMSG(_(e_abort)); | |
1865 return FAIL; | |
1866 } | |
1867 } | |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1868 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1869 #ifdef FEAT_AUTOCMD |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1870 if (did_yank && has_textyankpost()) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1871 yank_do_autocmd(oap, y_current); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1872 #endif |
7 | 1873 } |
1874 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1875 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1876 * 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
|
1877 */ |
7 | 1878 if (oap->block_mode) |
1879 { | |
1880 if (u_save((linenr_T)(oap->start.lnum - 1), | |
1881 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
1882 return FAIL; | |
1883 | |
1884 for (lnum = curwin->w_cursor.lnum; lnum <= oap->end.lnum; ++lnum) | |
1885 { | |
1886 block_prep(oap, &bd, lnum, TRUE); | |
1887 if (bd.textlen == 0) /* nothing to delete */ | |
1888 continue; | |
1889 | |
1890 /* Adjust cursor position for tab replaced by spaces and 'lbr'. */ | |
1891 if (lnum == curwin->w_cursor.lnum) | |
1892 { | |
1893 curwin->w_cursor.col = bd.textcol + bd.startspaces; | |
1894 # ifdef FEAT_VIRTUALEDIT | |
1895 curwin->w_cursor.coladd = 0; | |
1896 # endif | |
1897 } | |
1898 | |
1899 /* n == number of chars deleted | |
1900 * If we delete a TAB, it may be replaced by several characters. | |
1901 * Thus the number of characters may increase! | |
1902 */ | |
1903 n = bd.textlen - bd.startspaces - bd.endspaces; | |
1904 oldp = ml_get(lnum); | |
1905 newp = alloc_check((unsigned)STRLEN(oldp) + 1 - n); | |
1906 if (newp == NULL) | |
1907 continue; | |
1908 /* copy up to deleted part */ | |
1909 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
1910 /* insert spaces */ | |
6929 | 1911 vim_memset(newp + bd.textcol, ' ', |
7 | 1912 (size_t)(bd.startspaces + bd.endspaces)); |
1913 /* copy the part after the deleted part */ | |
1914 oldp += bd.textcol + bd.textlen; | |
1622 | 1915 STRMOVE(newp + bd.textcol + bd.startspaces + bd.endspaces, oldp); |
7 | 1916 /* replace the line */ |
1917 ml_replace(lnum, newp, FALSE); | |
1918 } | |
1919 | |
1920 check_cursor_col(); | |
1921 changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col, | |
1922 oap->end.lnum + 1, 0L); | |
1923 oap->line_count = 0; /* no lines deleted */ | |
1924 } | |
5735 | 1925 else if (oap->motion_type == MLINE) |
7 | 1926 { |
1927 if (oap->op_type == OP_CHANGE) | |
1928 { | |
1929 /* Delete the lines except the first one. Temporarily move the | |
1930 * cursor to the next line. Save the current line number, if the | |
1931 * last line is deleted it may be changed. | |
1932 */ | |
1933 if (oap->line_count > 1) | |
1934 { | |
1935 lnum = curwin->w_cursor.lnum; | |
1936 ++curwin->w_cursor.lnum; | |
1937 del_lines((long)(oap->line_count - 1), TRUE); | |
1938 curwin->w_cursor.lnum = lnum; | |
1939 } | |
1940 if (u_save_cursor() == FAIL) | |
1941 return FAIL; | |
1942 if (curbuf->b_p_ai) /* don't delete indent */ | |
1943 { | |
1944 beginline(BL_WHITE); /* cursor on first non-white */ | |
1945 did_ai = TRUE; /* delete the indent when ESC hit */ | |
1946 ai_col = curwin->w_cursor.col; | |
1947 } | |
1948 else | |
1949 beginline(0); /* cursor in column 0 */ | |
1950 truncate_line(FALSE); /* delete the rest of the line */ | |
1951 /* leave cursor past last char in line */ | |
1952 if (oap->line_count > 1) | |
1953 u_clearline(); /* "U" command not possible after "2cc" */ | |
1954 } | |
1955 else | |
1956 { | |
1957 del_lines(oap->line_count, TRUE); | |
1958 beginline(BL_WHITE | BL_FIX); | |
1959 u_clearline(); /* "U" command not possible after "dd" */ | |
1960 } | |
1961 } | |
1962 else | |
1963 { | |
1964 #ifdef FEAT_VIRTUALEDIT | |
1965 if (virtual_op) | |
1966 { | |
1967 int endcol = 0; | |
1968 | |
1969 /* For virtualedit: break the tabs that are partly included. */ | |
1970 if (gchar_pos(&oap->start) == '\t') | |
1971 { | |
1972 if (u_save_cursor() == FAIL) /* save first line for undo */ | |
1973 return FAIL; | |
1974 if (oap->line_count == 1) | |
1975 endcol = getviscol2(oap->end.col, oap->end.coladd); | |
1976 coladvance_force(getviscol2(oap->start.col, oap->start.coladd)); | |
1977 oap->start = curwin->w_cursor; | |
1978 if (oap->line_count == 1) | |
1979 { | |
1980 coladvance(endcol); | |
1981 oap->end.col = curwin->w_cursor.col; | |
1982 oap->end.coladd = curwin->w_cursor.coladd; | |
1983 curwin->w_cursor = oap->start; | |
1984 } | |
1985 } | |
1986 | |
1987 /* Break a tab only when it's included in the area. */ | |
1988 if (gchar_pos(&oap->end) == '\t' | |
1989 && (int)oap->end.coladd < oap->inclusive) | |
1990 { | |
1991 /* save last line for undo */ | |
1992 if (u_save((linenr_T)(oap->end.lnum - 1), | |
1993 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
1994 return FAIL; | |
1995 curwin->w_cursor = oap->end; | |
1996 coladvance_force(getviscol2(oap->end.col, oap->end.coladd)); | |
1997 oap->end = curwin->w_cursor; | |
1998 curwin->w_cursor = oap->start; | |
1999 } | |
2000 } | |
2001 #endif | |
2002 | |
2003 if (oap->line_count == 1) /* delete characters within one line */ | |
2004 { | |
2005 if (u_save_cursor() == FAIL) /* save line for undo */ | |
2006 return FAIL; | |
2007 | |
2008 /* if 'cpoptions' contains '$', display '$' at end of change */ | |
5735 | 2009 if ( vim_strchr(p_cpo, CPO_DOLLAR) != NULL |
7 | 2010 && oap->op_type == OP_CHANGE |
2011 && oap->end.lnum == curwin->w_cursor.lnum | |
5735 | 2012 && !oap->is_VIsual) |
7 | 2013 display_dollar(oap->end.col - !oap->inclusive); |
2014 | |
2015 n = oap->end.col - oap->start.col + 1 - !oap->inclusive; | |
2016 | |
2017 #ifdef FEAT_VIRTUALEDIT | |
2018 if (virtual_op) | |
2019 { | |
2020 /* fix up things for virtualedit-delete: | |
2021 * break the tabs which are going to get in our way | |
2022 */ | |
2023 char_u *curline = ml_get_curline(); | |
2024 int len = (int)STRLEN(curline); | |
2025 | |
2026 if (oap->end.coladd != 0 | |
2027 && (int)oap->end.col >= len - 1 | |
2028 && !(oap->start.coladd && (int)oap->end.col >= len - 1)) | |
2029 n++; | |
2030 /* Delete at least one char (e.g, when on a control char). */ | |
2031 if (n == 0 && oap->start.coladd != oap->end.coladd) | |
2032 n = 1; | |
2033 | |
2034 /* When deleted a char in the line, reset coladd. */ | |
2035 if (gchar_cursor() != NUL) | |
2036 curwin->w_cursor.coladd = 0; | |
2037 } | |
2038 #endif | |
6826 | 2039 (void)del_bytes((long)n, !virtual_op, |
2040 oap->op_type == OP_DELETE && !oap->is_VIsual); | |
7 | 2041 } |
2042 else /* delete characters between lines */ | |
2043 { | |
2044 pos_T curpos; | |
2045 | |
2046 /* save deleted and changed lines for undo */ | |
2047 if (u_save((linenr_T)(curwin->w_cursor.lnum - 1), | |
2048 (linenr_T)(curwin->w_cursor.lnum + oap->line_count)) == FAIL) | |
2049 return FAIL; | |
2050 | |
2051 truncate_line(TRUE); /* delete from cursor to end of line */ | |
2052 | |
2053 curpos = curwin->w_cursor; /* remember curwin->w_cursor */ | |
2054 ++curwin->w_cursor.lnum; | |
2055 del_lines((long)(oap->line_count - 2), FALSE); | |
2056 | |
6826 | 2057 /* delete from start of line until op_end */ |
2957 | 2058 n = (oap->end.col + 1 - !oap->inclusive); |
6826 | 2059 curwin->w_cursor.col = 0; |
2060 (void)del_bytes((long)n, !virtual_op, | |
2061 oap->op_type == OP_DELETE && !oap->is_VIsual); | |
2062 curwin->w_cursor = curpos; /* restore curwin->w_cursor */ | |
2063 (void)do_join(2, FALSE, FALSE, FALSE, FALSE); | |
7 | 2064 } |
2065 } | |
2066 | |
2067 msgmore(curbuf->b_ml.ml_line_count - old_lcount); | |
2068 | |
446 | 2069 #ifdef FEAT_VIRTUALEDIT |
2070 setmarks: | |
2071 #endif | |
7 | 2072 if (oap->block_mode) |
2073 { | |
2074 curbuf->b_op_end.lnum = oap->end.lnum; | |
2075 curbuf->b_op_end.col = oap->start.col; | |
2076 } | |
2077 else | |
2078 curbuf->b_op_end = oap->start; | |
2079 curbuf->b_op_start = oap->start; | |
2080 | |
2081 return OK; | |
2082 } | |
2083 | |
2084 #ifdef FEAT_MBYTE | |
2085 /* | |
2086 * Adjust end of operating area for ending on a multi-byte character. | |
2087 * Used for deletion. | |
2088 */ | |
2089 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2090 mb_adjust_opend(oparg_T *oap) |
7 | 2091 { |
2092 char_u *p; | |
2093 | |
2094 if (oap->inclusive) | |
2095 { | |
2096 p = ml_get(oap->end.lnum); | |
2097 oap->end.col += mb_tail_off(p, p + oap->end.col); | |
2098 } | |
2099 } | |
2100 #endif | |
2101 | |
2102 #if defined(FEAT_VISUALEXTRA) || defined(PROTO) | |
2103 /* | |
2104 * Replace a whole area with one character. | |
2105 */ | |
2106 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2107 op_replace(oparg_T *oap, int c) |
7 | 2108 { |
2109 int n, numc; | |
2110 #ifdef FEAT_MBYTE | |
2111 int num_chars; | |
2112 #endif | |
2113 char_u *newp, *oldp; | |
2114 size_t oldlen; | |
2115 struct block_def bd; | |
5428 | 2116 char_u *after_p = NULL; |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2117 int had_ctrl_v_cr = FALSE; |
7 | 2118 |
2119 if ((curbuf->b_ml.ml_flags & ML_EMPTY ) || oap->empty) | |
2120 return OK; /* nothing to do */ | |
2121 | |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2122 if (c == REPLACE_CR_NCHAR) |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2123 { |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2124 had_ctrl_v_cr = TRUE; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2125 c = CAR; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2126 } |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2127 else if (c == REPLACE_NL_NCHAR) |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2128 { |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2129 had_ctrl_v_cr = TRUE; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2130 c = NL; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2131 } |
5428 | 2132 |
7 | 2133 #ifdef FEAT_MBYTE |
2134 if (has_mbyte) | |
2135 mb_adjust_opend(oap); | |
2136 #endif | |
2137 | |
2138 if (u_save((linenr_T)(oap->start.lnum - 1), | |
2139 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
2140 return FAIL; | |
2141 | |
2142 /* | |
2143 * block mode replace | |
2144 */ | |
2145 if (oap->block_mode) | |
2146 { | |
2147 bd.is_MAX = (curwin->w_curswant == MAXCOL); | |
2148 for ( ; curwin->w_cursor.lnum <= oap->end.lnum; ++curwin->w_cursor.lnum) | |
2149 { | |
1982 | 2150 curwin->w_cursor.col = 0; /* make sure cursor position is valid */ |
7 | 2151 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); |
2152 if (bd.textlen == 0 && (!virtual_op || bd.is_MAX)) | |
2153 continue; /* nothing to replace */ | |
2154 | |
2155 /* n == number of extra chars required | |
2156 * If we split a TAB, it may be replaced by several characters. | |
2157 * Thus the number of characters may increase! | |
2158 */ | |
2159 #ifdef FEAT_VIRTUALEDIT | |
2160 /* If the range starts in virtual space, count the initial | |
2161 * coladd offset as part of "startspaces" */ | |
2162 if (virtual_op && bd.is_short && *bd.textstart == NUL) | |
2163 { | |
2164 pos_T vpos; | |
2165 | |
1982 | 2166 vpos.lnum = curwin->w_cursor.lnum; |
7 | 2167 getvpos(&vpos, oap->start_vcol); |
2168 bd.startspaces += vpos.coladd; | |
2169 n = bd.startspaces; | |
2170 } | |
2171 else | |
2172 #endif | |
2173 /* allow for pre spaces */ | |
2174 n = (bd.startspaces ? bd.start_char_vcols - 1 : 0); | |
2175 | |
2176 /* allow for post spp */ | |
2177 n += (bd.endspaces | |
2178 #ifdef FEAT_VIRTUALEDIT | |
2179 && !bd.is_oneChar | |
2180 #endif | |
2181 && bd.end_char_vcols > 0) ? bd.end_char_vcols - 1 : 0; | |
2182 /* Figure out how many characters to replace. */ | |
2183 numc = oap->end_vcol - oap->start_vcol + 1; | |
2184 if (bd.is_short && (!virtual_op || bd.is_MAX)) | |
2185 numc -= (oap->end_vcol - bd.end_vcol) + 1; | |
2186 | |
2187 #ifdef FEAT_MBYTE | |
2188 /* A double-wide character can be replaced only up to half the | |
2189 * times. */ | |
2190 if ((*mb_char2cells)(c) > 1) | |
2191 { | |
2192 if ((numc & 1) && !bd.is_short) | |
2193 { | |
2194 ++bd.endspaces; | |
2195 ++n; | |
2196 } | |
2197 numc = numc / 2; | |
2198 } | |
2199 | |
2200 /* Compute bytes needed, move character count to num_chars. */ | |
2201 num_chars = numc; | |
2202 numc *= (*mb_char2len)(c); | |
2203 #endif | |
2204 /* oldlen includes textlen, so don't double count */ | |
2205 n += numc - bd.textlen; | |
2206 | |
2207 oldp = ml_get_curline(); | |
2208 oldlen = STRLEN(oldp); | |
2209 newp = alloc_check((unsigned)oldlen + 1 + n); | |
2210 if (newp == NULL) | |
2211 continue; | |
2212 vim_memset(newp, NUL, (size_t)(oldlen + 1 + n)); | |
2213 /* copy up to deleted part */ | |
2214 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
2215 oldp += bd.textcol + bd.textlen; | |
2216 /* insert pre-spaces */ | |
6929 | 2217 vim_memset(newp + bd.textcol, ' ', (size_t)bd.startspaces); |
7 | 2218 /* insert replacement chars CHECK FOR ALLOCATED SPACE */ |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2219 /* REPLACE_CR_NCHAR/REPLACE_NL_NCHAR is used for entering CR |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2220 * literally. */ |
5428 | 2221 if (had_ctrl_v_cr || (c != '\r' && c != '\n')) |
7 | 2222 { |
5428 | 2223 #ifdef FEAT_MBYTE |
2224 if (has_mbyte) | |
2225 { | |
2226 n = (int)STRLEN(newp); | |
2227 while (--num_chars >= 0) | |
2228 n += (*mb_char2bytes)(c, newp + n); | |
2229 } | |
2230 else | |
2231 #endif | |
6929 | 2232 vim_memset(newp + STRLEN(newp), c, (size_t)numc); |
5428 | 2233 if (!bd.is_short) |
2234 { | |
2235 /* insert post-spaces */ | |
6929 | 2236 vim_memset(newp + STRLEN(newp), ' ', (size_t)bd.endspaces); |
5428 | 2237 /* copy the part after the changed part */ |
2238 STRMOVE(newp + STRLEN(newp), oldp); | |
2239 } | |
7 | 2240 } |
2241 else | |
2242 { | |
5428 | 2243 /* Replacing with \r or \n means splitting the line. */ |
5475 | 2244 after_p = alloc_check( |
2245 (unsigned)(oldlen + 1 + n - STRLEN(newp))); | |
5428 | 2246 if (after_p != NULL) |
2247 STRMOVE(after_p, oldp); | |
7 | 2248 } |
2249 /* replace the line */ | |
2250 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
5428 | 2251 if (after_p != NULL) |
2252 { | |
2253 ml_append(curwin->w_cursor.lnum++, after_p, 0, FALSE); | |
2254 appended_lines_mark(curwin->w_cursor.lnum, 1L); | |
2255 oap->end.lnum++; | |
2256 vim_free(after_p); | |
2257 } | |
7 | 2258 } |
2259 } | |
2260 else | |
2261 { | |
2262 /* | |
2263 * MCHAR and MLINE motion replace. | |
2264 */ | |
2265 if (oap->motion_type == MLINE) | |
2266 { | |
2267 oap->start.col = 0; | |
2268 curwin->w_cursor.col = 0; | |
2269 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
2270 if (oap->end.col) | |
2271 --oap->end.col; | |
2272 } | |
2273 else if (!oap->inclusive) | |
2274 dec(&(oap->end)); | |
2275 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2276 while (LTOREQ_POS(curwin->w_cursor, oap->end)) |
7 | 2277 { |
2278 n = gchar_cursor(); | |
2279 if (n != NUL) | |
2280 { | |
2281 #ifdef FEAT_MBYTE | |
2282 if ((*mb_char2len)(c) > 1 || (*mb_char2len)(n) > 1) | |
2283 { | |
2284 /* This is slow, but it handles replacing a single-byte | |
2285 * with a multi-byte and the other way around. */ | |
4203 | 2286 if (curwin->w_cursor.lnum == oap->end.lnum) |
2287 oap->end.col += (*mb_char2len)(c) - (*mb_char2len)(n); | |
7 | 2288 n = State; |
2289 State = REPLACE; | |
2290 ins_char(c); | |
2291 State = n; | |
2292 /* Backup to the replaced character. */ | |
2293 dec_cursor(); | |
2294 } | |
2295 else | |
2296 #endif | |
2297 { | |
2298 #ifdef FEAT_VIRTUALEDIT | |
2299 if (n == TAB) | |
2300 { | |
2301 int end_vcol = 0; | |
2302 | |
2303 if (curwin->w_cursor.lnum == oap->end.lnum) | |
2304 { | |
2305 /* oap->end has to be recalculated when | |
2306 * the tab breaks */ | |
2307 end_vcol = getviscol2(oap->end.col, | |
2308 oap->end.coladd); | |
2309 } | |
2310 coladvance_force(getviscol()); | |
2311 if (curwin->w_cursor.lnum == oap->end.lnum) | |
2312 getvpos(&oap->end, end_vcol); | |
2313 } | |
2314 #endif | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2315 PCHAR(curwin->w_cursor, c); |
7 | 2316 } |
2317 } | |
2318 #ifdef FEAT_VIRTUALEDIT | |
2319 else if (virtual_op && curwin->w_cursor.lnum == oap->end.lnum) | |
2320 { | |
2321 int virtcols = oap->end.coladd; | |
2322 | |
2323 if (curwin->w_cursor.lnum == oap->start.lnum | |
2324 && oap->start.col == oap->end.col && oap->start.coladd) | |
2325 virtcols -= oap->start.coladd; | |
2326 | |
2327 /* oap->end has been trimmed so it's effectively inclusive; | |
2328 * as a result an extra +1 must be counted so we don't | |
2329 * trample the NUL byte. */ | |
2330 coladvance_force(getviscol2(oap->end.col, oap->end.coladd) + 1); | |
2331 curwin->w_cursor.col -= (virtcols + 1); | |
2332 for (; virtcols >= 0; virtcols--) | |
2333 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2334 PCHAR(curwin->w_cursor, c); |
7 | 2335 if (inc(&curwin->w_cursor) == -1) |
2336 break; | |
2337 } | |
2338 } | |
2339 #endif | |
2340 | |
2341 /* Advance to next character, stop at the end of the file. */ | |
2342 if (inc_cursor() == -1) | |
2343 break; | |
2344 } | |
2345 } | |
2346 | |
2347 curwin->w_cursor = oap->start; | |
2348 check_cursor(); | |
2349 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, 0L); | |
2350 | |
2351 /* Set "'[" and "']" marks. */ | |
2352 curbuf->b_op_start = oap->start; | |
2353 curbuf->b_op_end = oap->end; | |
2354 | |
2355 return OK; | |
2356 } | |
2357 #endif | |
2358 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
2359 static int swapchars(int op_type, pos_T *pos, int length); |
1525 | 2360 |
7 | 2361 /* |
2362 * Handle the (non-standard vi) tilde operator. Also for "gu", "gU" and "g?". | |
2363 */ | |
2364 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2365 op_tilde(oparg_T *oap) |
7 | 2366 { |
2367 pos_T pos; | |
2368 struct block_def bd; | |
1528 | 2369 int did_change = FALSE; |
7 | 2370 |
2371 if (u_save((linenr_T)(oap->start.lnum - 1), | |
2372 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
2373 return; | |
2374 | |
2375 pos = oap->start; | |
2376 if (oap->block_mode) /* Visual block mode */ | |
2377 { | |
2378 for (; pos.lnum <= oap->end.lnum; ++pos.lnum) | |
2379 { | |
1766 | 2380 int one_change; |
2381 | |
7 | 2382 block_prep(oap, &bd, pos.lnum, FALSE); |
2383 pos.col = bd.textcol; | |
1766 | 2384 one_change = swapchars(oap->op_type, &pos, bd.textlen); |
2385 did_change |= one_change; | |
1525 | 2386 |
5735 | 2387 #ifdef FEAT_NETBEANS_INTG |
2210 | 2388 if (netbeans_active() && one_change) |
7 | 2389 { |
2390 char_u *ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
2391 | |
33 | 2392 netbeans_removed(curbuf, pos.lnum, bd.textcol, |
2393 (long)bd.textlen); | |
7 | 2394 netbeans_inserted(curbuf, pos.lnum, bd.textcol, |
2210 | 2395 &ptr[bd.textcol], bd.textlen); |
7 | 2396 } |
5735 | 2397 #endif |
7 | 2398 } |
2399 if (did_change) | |
2400 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); | |
2401 } | |
2402 else /* not block mode */ | |
2403 { | |
2404 if (oap->motion_type == MLINE) | |
2405 { | |
2406 oap->start.col = 0; | |
2407 pos.col = 0; | |
2408 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
2409 if (oap->end.col) | |
2410 --oap->end.col; | |
2411 } | |
2412 else if (!oap->inclusive) | |
2413 dec(&(oap->end)); | |
2414 | |
1528 | 2415 if (pos.lnum == oap->end.lnum) |
2416 did_change = swapchars(oap->op_type, &pos, | |
2417 oap->end.col - pos.col + 1); | |
2418 else | |
2419 for (;;) | |
2420 { | |
2421 did_change |= swapchars(oap->op_type, &pos, | |
2422 pos.lnum == oap->end.lnum ? oap->end.col + 1: | |
2423 (int)STRLEN(ml_get_pos(&pos))); | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2424 if (LTOREQ_POS(oap->end, pos) || inc(&pos) == -1) |
1528 | 2425 break; |
2426 } | |
7 | 2427 if (did_change) |
2428 { | |
2429 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, | |
2430 0L); | |
2431 #ifdef FEAT_NETBEANS_INTG | |
2210 | 2432 if (netbeans_active() && did_change) |
7 | 2433 { |
2434 char_u *ptr; | |
2435 int count; | |
2436 | |
2437 pos = oap->start; | |
2438 while (pos.lnum < oap->end.lnum) | |
2439 { | |
2440 ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
835 | 2441 count = (int)STRLEN(ptr) - pos.col; |
33 | 2442 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7 | 2443 netbeans_inserted(curbuf, pos.lnum, pos.col, |
2210 | 2444 &ptr[pos.col], count); |
7 | 2445 pos.col = 0; |
2446 pos.lnum++; | |
2447 } | |
2448 ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
2449 count = oap->end.col - pos.col + 1; | |
33 | 2450 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7 | 2451 netbeans_inserted(curbuf, pos.lnum, pos.col, |
2210 | 2452 &ptr[pos.col], count); |
7 | 2453 } |
2454 #endif | |
2455 } | |
2456 } | |
2457 | |
2458 if (!did_change && oap->is_VIsual) | |
2459 /* No change: need to remove the Visual selection */ | |
2460 redraw_curbuf_later(INVERTED); | |
2461 | |
2462 /* | |
2463 * Set '[ and '] marks. | |
2464 */ | |
2465 curbuf->b_op_start = oap->start; | |
2466 curbuf->b_op_end = oap->end; | |
2467 | |
2468 if (oap->line_count > p_report) | |
2469 { | |
2470 if (oap->line_count == 1) | |
2471 MSG(_("1 line changed")); | |
2472 else | |
2473 smsg((char_u *)_("%ld lines changed"), oap->line_count); | |
2474 } | |
2475 } | |
2476 | |
2477 /* | |
1525 | 2478 * Invoke swapchar() on "length" bytes at position "pos". |
2479 * "pos" is advanced to just after the changed characters. | |
2480 * "length" is rounded up to include the whole last multi-byte character. | |
2481 * Also works correctly when the number of bytes changes. | |
2482 * Returns TRUE if some character was changed. | |
2483 */ | |
2484 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2485 swapchars(int op_type, pos_T *pos, int length) |
1525 | 2486 { |
2487 int todo; | |
2488 int did_change = 0; | |
2489 | |
2490 for (todo = length; todo > 0; --todo) | |
2491 { | |
2492 # ifdef FEAT_MBYTE | |
2493 if (has_mbyte) | |
5288
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2494 { |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2495 int len = (*mb_ptr2len)(ml_get_pos(pos)); |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2496 |
1525 | 2497 /* we're counting bytes, not characters */ |
5288
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2498 if (len > 0) |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2499 todo -= len - 1; |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2500 } |
1525 | 2501 # endif |
2502 did_change |= swapchar(op_type, pos); | |
2503 if (inc(pos) == -1) /* at end of file */ | |
2504 break; | |
2505 } | |
2506 return did_change; | |
2507 } | |
2508 | |
2509 /* | |
7 | 2510 * If op_type == OP_UPPER: make uppercase, |
2511 * if op_type == OP_LOWER: make lowercase, | |
2512 * if op_type == OP_ROT13: do rot13 encoding, | |
2513 * else swap case of character at 'pos' | |
2514 * returns TRUE when something actually changed. | |
2515 */ | |
2516 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2517 swapchar(int op_type, pos_T *pos) |
7 | 2518 { |
2519 int c; | |
2520 int nc; | |
2521 | |
2522 c = gchar_pos(pos); | |
2523 | |
2524 /* Only do rot13 encoding for ASCII characters. */ | |
2525 if (c >= 0x80 && op_type == OP_ROT13) | |
2526 return FALSE; | |
2527 | |
2528 #ifdef FEAT_MBYTE | |
1525 | 2529 if (op_type == OP_UPPER && c == 0xdf |
2530 && (enc_latin1like || STRCMP(p_enc, "iso-8859-2") == 0)) | |
493 | 2531 { |
2532 pos_T sp = curwin->w_cursor; | |
2533 | |
2534 /* Special handling of German sharp s: change to "SS". */ | |
2535 curwin->w_cursor = *pos; | |
2536 del_char(FALSE); | |
2537 ins_char('S'); | |
2538 ins_char('S'); | |
2539 curwin->w_cursor = sp; | |
2540 inc(pos); | |
2541 } | |
2542 | |
7 | 2543 if (enc_dbcs != 0 && c >= 0x100) /* No lower/uppercase letter */ |
2544 return FALSE; | |
2545 #endif | |
2546 nc = c; | |
2547 if (MB_ISLOWER(c)) | |
2548 { | |
2549 if (op_type == OP_ROT13) | |
2550 nc = ROT13(c, 'a'); | |
2551 else if (op_type != OP_LOWER) | |
2552 nc = MB_TOUPPER(c); | |
2553 } | |
2554 else if (MB_ISUPPER(c)) | |
2555 { | |
2556 if (op_type == OP_ROT13) | |
2557 nc = ROT13(c, 'A'); | |
2558 else if (op_type != OP_UPPER) | |
2559 nc = MB_TOLOWER(c); | |
2560 } | |
2561 if (nc != c) | |
2562 { | |
2563 #ifdef FEAT_MBYTE | |
2564 if (enc_utf8 && (c >= 0x80 || nc >= 0x80)) | |
2565 { | |
2566 pos_T sp = curwin->w_cursor; | |
2567 | |
2568 curwin->w_cursor = *pos; | |
2451
0b8612c2814d
Fix: changing case of a character removed combining characters.
Bram Moolenaar <bram@vim.org>
parents:
2446
diff
changeset
|
2569 /* 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
|
2570 del_bytes(utf_ptr2len(ml_get_cursor()), FALSE, FALSE); |
7 | 2571 ins_char(nc); |
2572 curwin->w_cursor = sp; | |
2573 } | |
2574 else | |
2575 #endif | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2576 PCHAR(*pos, nc); |
7 | 2577 return TRUE; |
2578 } | |
2579 return FALSE; | |
2580 } | |
2581 | |
2582 #if defined(FEAT_VISUALEXTRA) || defined(PROTO) | |
2583 /* | |
2584 * op_insert - Insert and append operators for Visual mode. | |
2585 */ | |
2586 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2587 op_insert(oparg_T *oap, long count1) |
7 | 2588 { |
2589 long ins_len, pre_textlen = 0; | |
2590 char_u *firstline, *ins_text; | |
12329
0b10cff73322
patch 8.0.1044: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12327
diff
changeset
|
2591 colnr_T ind_pre = 0, ind_post; |
7 | 2592 struct block_def bd; |
2593 int i; | |
6579 | 2594 pos_T t1; |
7 | 2595 |
2596 /* edit() changes this - record it for OP_APPEND */ | |
2597 bd.is_MAX = (curwin->w_curswant == MAXCOL); | |
2598 | |
2599 /* vis block is still marked. Get rid of it now. */ | |
2600 curwin->w_cursor.lnum = oap->start.lnum; | |
2601 update_screen(INVERTED); | |
2602 | |
2603 if (oap->block_mode) | |
2604 { | |
2605 #ifdef FEAT_VIRTUALEDIT | |
2606 /* When 'virtualedit' is used, need to insert the extra spaces before | |
2607 * doing block_prep(). When only "block" is used, virtual edit is | |
2608 * already disabled, but still need it when calling | |
2609 * coladvance_force(). */ | |
2610 if (curwin->w_cursor.coladd > 0) | |
2611 { | |
2612 int old_ve_flags = ve_flags; | |
2613 | |
2614 ve_flags = VE_ALL; | |
2615 if (u_save_cursor() == FAIL) | |
2616 return; | |
2617 coladvance_force(oap->op_type == OP_APPEND | |
2618 ? oap->end_vcol + 1 : getviscol()); | |
2619 if (oap->op_type == OP_APPEND) | |
2620 --curwin->w_cursor.col; | |
2621 ve_flags = old_ve_flags; | |
2622 } | |
2623 #endif | |
2624 /* Get the info about the block before entering the text */ | |
2625 block_prep(oap, &bd, oap->start.lnum, TRUE); | |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
2626 /* Get indent information */ |
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
2627 ind_pre = (colnr_T)getwhitecols_curline(); |
7 | 2628 firstline = ml_get(oap->start.lnum) + bd.textcol; |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
2629 |
7 | 2630 if (oap->op_type == OP_APPEND) |
2631 firstline += bd.textlen; | |
2632 pre_textlen = (long)STRLEN(firstline); | |
2633 } | |
2634 | |
2635 if (oap->op_type == OP_APPEND) | |
2636 { | |
2637 if (oap->block_mode | |
2638 #ifdef FEAT_VIRTUALEDIT | |
2639 && curwin->w_cursor.coladd == 0 | |
2640 #endif | |
2641 ) | |
2642 { | |
2643 /* Move the cursor to the character right of the block. */ | |
2644 curwin->w_set_curswant = TRUE; | |
2645 while (*ml_get_cursor() != NUL | |
2646 && (curwin->w_cursor.col < bd.textcol + bd.textlen)) | |
2647 ++curwin->w_cursor.col; | |
2648 if (bd.is_short && !bd.is_MAX) | |
2649 { | |
2650 /* First line was too short, make it longer and adjust the | |
2651 * values in "bd". */ | |
2652 if (u_save_cursor() == FAIL) | |
2653 return; | |
2654 for (i = 0; i < bd.endspaces; ++i) | |
2655 ins_char(' '); | |
2656 bd.textlen += bd.endspaces; | |
2657 } | |
2658 } | |
2659 else | |
2660 { | |
2661 curwin->w_cursor = oap->end; | |
893 | 2662 check_cursor_col(); |
7 | 2663 |
2664 /* Works just like an 'i'nsert on the next character. */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2665 if (!LINEEMPTY(curwin->w_cursor.lnum) |
7 | 2666 && oap->start_vcol != oap->end_vcol) |
2667 inc_cursor(); | |
2668 } | |
2669 } | |
2670 | |
6579 | 2671 t1 = oap->start; |
10803
065da86ca6d2
patch 8.0.0291: Visual block insertion does not insert in all lines
Christian Brabandt <cb@256bit.org>
parents:
10785
diff
changeset
|
2672 (void)edit(NUL, FALSE, (linenr_T)count1); |
7 | 2673 |
6579 | 2674 /* When a tab was inserted, and the characters in front of the tab |
2675 * have been converted to a tab as well, the column of the cursor | |
2676 * might have actually been reduced, so need to adjust here. */ | |
2677 if (t1.lnum == curbuf->b_op_start_orig.lnum | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2678 && LT_POS(curbuf->b_op_start_orig, t1)) |
6579 | 2679 oap->start = curbuf->b_op_start_orig; |
2680 | |
1477 | 2681 /* If user has moved off this line, we don't know what to do, so do |
2682 * nothing. | |
2683 * Also don't repeat the insert when Insert mode ended with CTRL-C. */ | |
2684 if (curwin->w_cursor.lnum != oap->start.lnum || got_int) | |
7 | 2685 return; |
2686 | |
2687 if (oap->block_mode) | |
2688 { | |
2689 struct block_def bd2; | |
2690 | |
12327
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2691 /* If indent kicked in, the firstline might have changed |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2692 * but only do that, if the indent actually increased. */ |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2693 ind_post = (colnr_T)getwhitecols_curline(); |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2694 if (curbuf->b_op_start.col > ind_pre && ind_post > ind_pre) |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2695 { |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2696 bd.textcol += ind_post - ind_pre; |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2697 bd.start_vcol += ind_post - ind_pre; |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2698 } |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2699 |
5471 | 2700 /* The user may have moved the cursor before inserting something, try |
2701 * to adjust the block for that. */ | |
5680 | 2702 if (oap->start.lnum == curbuf->b_op_start_orig.lnum && !bd.is_MAX) |
5471 | 2703 { |
2704 if (oap->op_type == OP_INSERT | |
5730 | 2705 && oap->start.col |
2706 #ifdef FEAT_VIRTUALEDIT | |
2707 + oap->start.coladd | |
2708 #endif | |
2709 != curbuf->b_op_start_orig.col | |
2710 #ifdef FEAT_VIRTUALEDIT | |
2711 + curbuf->b_op_start_orig.coladd | |
2712 #endif | |
2713 ) | |
5471 | 2714 { |
6579 | 2715 int t = getviscol2(curbuf->b_op_start_orig.col, |
2716 curbuf->b_op_start_orig.coladd); | |
5680 | 2717 oap->start.col = curbuf->b_op_start_orig.col; |
6579 | 2718 pre_textlen -= t - oap->start_vcol; |
2719 oap->start_vcol = t; | |
5471 | 2720 } |
2721 else if (oap->op_type == OP_APPEND | |
5730 | 2722 && oap->end.col |
2723 #ifdef FEAT_VIRTUALEDIT | |
2724 + oap->end.coladd | |
2725 #endif | |
2726 >= curbuf->b_op_start_orig.col | |
2727 #ifdef FEAT_VIRTUALEDIT | |
2728 + curbuf->b_op_start_orig.coladd | |
2729 #endif | |
2730 ) | |
5471 | 2731 { |
6579 | 2732 int t = getviscol2(curbuf->b_op_start_orig.col, |
2733 curbuf->b_op_start_orig.coladd); | |
5680 | 2734 oap->start.col = curbuf->b_op_start_orig.col; |
5471 | 2735 /* reset pre_textlen to the value of OP_INSERT */ |
2736 pre_textlen += bd.textlen; | |
6579 | 2737 pre_textlen -= t - oap->start_vcol; |
2738 oap->start_vcol = t; | |
5471 | 2739 oap->op_type = OP_INSERT; |
2740 } | |
2741 } | |
2742 | |
7 | 2743 /* |
2744 * Spaces and tabs in the indent may have changed to other spaces and | |
1392 | 2745 * tabs. Get the starting column again and correct the length. |
7 | 2746 * Don't do this when "$" used, end-of-line will have changed. |
2747 */ | |
2748 block_prep(oap, &bd2, oap->start.lnum, TRUE); | |
2749 if (!bd.is_MAX || bd2.textlen < bd.textlen) | |
2750 { | |
2751 if (oap->op_type == OP_APPEND) | |
2752 { | |
2753 pre_textlen += bd2.textlen - bd.textlen; | |
2754 if (bd2.endspaces) | |
2755 --bd2.textlen; | |
2756 } | |
2757 bd.textcol = bd2.textcol; | |
2758 bd.textlen = bd2.textlen; | |
2759 } | |
2760 | |
2761 /* | |
2762 * Subsequent calls to ml_get() flush the firstline data - take a | |
2763 * copy of the required string. | |
2764 */ | |
2765 firstline = ml_get(oap->start.lnum) + bd.textcol; | |
2766 if (oap->op_type == OP_APPEND) | |
2767 firstline += bd.textlen; | |
3421 | 2768 if (pre_textlen >= 0 |
2769 && (ins_len = (long)STRLEN(firstline) - pre_textlen) > 0) | |
7 | 2770 { |
2771 ins_text = vim_strnsave(firstline, (int)ins_len); | |
2772 if (ins_text != NULL) | |
2773 { | |
2774 /* block handled here */ | |
2775 if (u_save(oap->start.lnum, | |
2776 (linenr_T)(oap->end.lnum + 1)) == OK) | |
2777 block_insert(oap, ins_text, (oap->op_type == OP_INSERT), | |
2778 &bd); | |
2779 | |
2780 curwin->w_cursor.col = oap->start.col; | |
2781 check_cursor(); | |
2782 vim_free(ins_text); | |
2783 } | |
2784 } | |
2785 } | |
2786 } | |
2787 #endif | |
2788 | |
2789 /* | |
2790 * op_change - handle a change operation | |
2791 * | |
2792 * return TRUE if edit() returns because of a CTRL-O command | |
2793 */ | |
2794 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2795 op_change(oparg_T *oap) |
7 | 2796 { |
2797 colnr_T l; | |
2798 int retval; | |
2799 #ifdef FEAT_VISUALEXTRA | |
2800 long offset; | |
2801 linenr_T linenr; | |
1392 | 2802 long ins_len; |
2803 long pre_textlen = 0; | |
2804 long pre_indent = 0; | |
7 | 2805 char_u *firstline; |
2806 char_u *ins_text, *newp, *oldp; | |
2807 struct block_def bd; | |
2808 #endif | |
2809 | |
2810 l = oap->start.col; | |
2811 if (oap->motion_type == MLINE) | |
2812 { | |
2813 l = 0; | |
2814 #ifdef FEAT_SMARTINDENT | |
2815 if (!p_paste && curbuf->b_p_si | |
2816 # ifdef FEAT_CINDENT | |
2817 && !curbuf->b_p_cin | |
2818 # endif | |
2819 ) | |
2820 can_si = TRUE; /* It's like opening a new line, do si */ | |
2821 #endif | |
2822 } | |
2823 | |
2824 /* First delete the text in the region. In an empty buffer only need to | |
2825 * save for undo */ | |
2826 if (curbuf->b_ml.ml_flags & ML_EMPTY) | |
2827 { | |
2828 if (u_save_cursor() == FAIL) | |
2829 return FALSE; | |
2830 } | |
2831 else if (op_delete(oap) == FAIL) | |
2832 return FALSE; | |
2833 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2834 if ((l > curwin->w_cursor.col) && !LINEEMPTY(curwin->w_cursor.lnum) |
7 | 2835 && !virtual_op) |
2836 inc_cursor(); | |
2837 | |
2838 #ifdef FEAT_VISUALEXTRA | |
2839 /* check for still on same line (<CR> in inserted text meaningless) */ | |
2840 /* skip blank lines too */ | |
2841 if (oap->block_mode) | |
2842 { | |
2843 # ifdef FEAT_VIRTUALEDIT | |
2844 /* Add spaces before getting the current line length. */ | |
2845 if (virtual_op && (curwin->w_cursor.coladd > 0 | |
2846 || gchar_cursor() == NUL)) | |
2847 coladvance_force(getviscol()); | |
2848 # endif | |
1392 | 2849 firstline = ml_get(oap->start.lnum); |
2850 pre_textlen = (long)STRLEN(firstline); | |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
2851 pre_indent = (long)getwhitecols(firstline); |
7 | 2852 bd.textcol = curwin->w_cursor.col; |
2853 } | |
2854 #endif | |
2855 | |
2856 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) | |
2857 if (oap->motion_type == MLINE) | |
2858 fix_indent(); | |
2859 #endif | |
2860 | |
2861 retval = edit(NUL, FALSE, (linenr_T)1); | |
2862 | |
2863 #ifdef FEAT_VISUALEXTRA | |
2864 /* | |
39 | 2865 * In Visual block mode, handle copying the new text to all lines of the |
7 | 2866 * block. |
1477 | 2867 * Don't repeat the insert when Insert mode ended with CTRL-C. |
7 | 2868 */ |
1477 | 2869 if (oap->block_mode && oap->start.lnum != oap->end.lnum && !got_int) |
7 | 2870 { |
1392 | 2871 /* Auto-indenting may have changed the indent. If the cursor was past |
2872 * the indent, exclude that indent change from the inserted text. */ | |
7 | 2873 firstline = ml_get(oap->start.lnum); |
1403 | 2874 if (bd.textcol > (colnr_T)pre_indent) |
7 | 2875 { |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
2876 long new_indent = (long)getwhitecols(firstline); |
1392 | 2877 |
2878 pre_textlen += new_indent - pre_indent; | |
2879 bd.textcol += new_indent - pre_indent; | |
2880 } | |
2881 | |
2882 ins_len = (long)STRLEN(firstline) - pre_textlen; | |
2883 if (ins_len > 0) | |
2884 { | |
2885 /* Subsequent calls to ml_get() flush the firstline data - take a | |
2886 * copy of the inserted text. */ | |
7 | 2887 if ((ins_text = alloc_check((unsigned)(ins_len + 1))) != NULL) |
2888 { | |
419 | 2889 vim_strncpy(ins_text, firstline + bd.textcol, (size_t)ins_len); |
7 | 2890 for (linenr = oap->start.lnum + 1; linenr <= oap->end.lnum; |
2891 linenr++) | |
2892 { | |
2893 block_prep(oap, &bd, linenr, TRUE); | |
2894 if (!bd.is_short || virtual_op) | |
2895 { | |
2896 # ifdef FEAT_VIRTUALEDIT | |
2897 pos_T vpos; | |
2898 | |
2899 /* If the block starts in virtual space, count the | |
2900 * initial coladd offset as part of "startspaces" */ | |
2901 if (bd.is_short) | |
2902 { | |
1982 | 2903 vpos.lnum = linenr; |
7 | 2904 (void)getvpos(&vpos, oap->start_vcol); |
2905 } | |
2906 else | |
2907 vpos.coladd = 0; | |
2908 # endif | |
2909 oldp = ml_get(linenr); | |
2910 newp = alloc_check((unsigned)(STRLEN(oldp) | |
2911 # ifdef FEAT_VIRTUALEDIT | |
2912 + vpos.coladd | |
2913 # endif | |
2914 + ins_len + 1)); | |
2915 if (newp == NULL) | |
2916 continue; | |
2917 /* copy up to block start */ | |
2918 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
2919 offset = bd.textcol; | |
2920 # ifdef FEAT_VIRTUALEDIT | |
6929 | 2921 vim_memset(newp + offset, ' ', (size_t)vpos.coladd); |
7 | 2922 offset += vpos.coladd; |
2923 # endif | |
2924 mch_memmove(newp + offset, ins_text, (size_t)ins_len); | |
2925 offset += ins_len; | |
2926 oldp += bd.textcol; | |
1622 | 2927 STRMOVE(newp + offset, oldp); |
7 | 2928 ml_replace(linenr, newp, FALSE); |
2929 } | |
2930 } | |
2931 check_cursor(); | |
2932 | |
2933 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); | |
2934 } | |
2935 vim_free(ins_text); | |
2936 } | |
2937 } | |
2938 #endif | |
2939 | |
2940 return retval; | |
2941 } | |
2942 | |
2943 /* | |
2944 * set all the yank registers to empty (called from main()) | |
2945 */ | |
2946 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2947 init_yank(void) |
7 | 2948 { |
2949 int i; | |
2950 | |
2951 for (i = 0; i < NUM_REGISTERS; ++i) | |
2952 y_regs[i].y_array = NULL; | |
2953 } | |
2954 | |
356 | 2955 #if defined(EXITFREE) || defined(PROTO) |
2956 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2957 clear_registers(void) |
356 | 2958 { |
2959 int i; | |
2960 | |
2961 for (i = 0; i < NUM_REGISTERS; ++i) | |
2962 { | |
2963 y_current = &y_regs[i]; | |
2964 if (y_current->y_array != NULL) | |
2965 free_yank_all(); | |
2966 } | |
2967 } | |
2968 #endif | |
2969 | |
7 | 2970 /* |
2971 * Free "n" lines from the current yank register. | |
2972 * Called for normal freeing and in case of error. | |
2973 */ | |
2974 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2975 free_yank(long n) |
7 | 2976 { |
2977 if (y_current->y_array != NULL) | |
2978 { | |
2979 long i; | |
2980 | |
2981 for (i = n; --i >= 0; ) | |
2982 { | |
2983 #ifdef AMIGA /* only for very slow machines */ | |
2984 if ((i & 1023) == 1023) /* this may take a while */ | |
2985 { | |
2986 /* | |
2987 * This message should never cause a hit-return message. | |
2988 * Overwrite this message with any next message. | |
2989 */ | |
2990 ++no_wait_return; | |
2991 smsg((char_u *)_("freeing %ld lines"), i + 1); | |
2992 --no_wait_return; | |
2993 msg_didout = FALSE; | |
2994 msg_col = 0; | |
2995 } | |
2996 #endif | |
2997 vim_free(y_current->y_array[i]); | |
2998 } | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
2999 VIM_CLEAR(y_current->y_array); |
7 | 3000 #ifdef AMIGA |
3001 if (n >= 1000) | |
3002 MSG(""); | |
3003 #endif | |
3004 } | |
3005 } | |
3006 | |
3007 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3008 free_yank_all(void) |
7 | 3009 { |
3010 free_yank(y_current->y_size); | |
3011 } | |
3012 | |
3013 /* | |
3014 * Yank the text between "oap->start" and "oap->end" into a yank register. | |
3015 * If we are to append (uppercase register), we first yank into a new yank | |
3016 * register and then concatenate the old and the new one (so we keep the old | |
3017 * one in case of out-of-memory). | |
3018 * | |
5245
8c6615a30951
updated for version 7.4a.047
Bram Moolenaar <bram@vim.org>
parents:
5182
diff
changeset
|
3019 * Return FAIL for failure, OK otherwise. |
7 | 3020 */ |
3021 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3022 op_yank(oparg_T *oap, int deleting, int mess) |
7 | 3023 { |
3024 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
|
3025 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
|
3026 yankreg_T newreg; /* new yank register when appending */ |
7 | 3027 char_u **new_ptr; |
3028 linenr_T lnum; /* current line number */ | |
3029 long j; | |
3030 int yanktype = oap->motion_type; | |
3031 long yanklines = oap->line_count; | |
3032 linenr_T yankendlnum = oap->end.lnum; | |
3033 char_u *p; | |
3034 char_u *pnew; | |
3035 struct block_def bd; | |
2658 | 3036 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
2654 | 3037 int did_star = FALSE; |
2658 | 3038 #endif |
7 | 3039 |
3040 /* check for read-only register */ | |
3041 if (oap->regname != 0 && !valid_yank_reg(oap->regname, TRUE)) | |
3042 { | |
3043 beep_flush(); | |
3044 return FAIL; | |
3045 } | |
3046 if (oap->regname == '_') /* black hole: nothing to do */ | |
3047 return OK; | |
3048 | |
3049 #ifdef FEAT_CLIPBOARD | |
3050 if (!clip_star.available && oap->regname == '*') | |
3051 oap->regname = 0; | |
3052 else if (!clip_plus.available && oap->regname == '+') | |
3053 oap->regname = 0; | |
3054 #endif | |
3055 | |
3056 if (!deleting) /* op_delete() already set y_current */ | |
3057 get_yank_register(oap->regname, TRUE); | |
3058 | |
3059 curr = y_current; | |
3060 /* append to existing contents */ | |
3061 if (y_append && y_current->y_array != NULL) | |
3062 y_current = &newreg; | |
3063 else | |
3064 free_yank_all(); /* free previously yanked lines */ | |
3065 | |
593 | 3066 /* |
3067 * If the cursor was in column 1 before and after the movement, and the | |
3068 * operator is not inclusive, the yank is always linewise. | |
3069 */ | |
7 | 3070 if ( oap->motion_type == MCHAR |
3071 && oap->start.col == 0 | |
3072 && !oap->inclusive | |
3073 && (!oap->is_VIsual || *p_sel == 'o') | |
50 | 3074 && !oap->block_mode |
7 | 3075 && oap->end.col == 0 |
3076 && yanklines > 1) | |
3077 { | |
3078 yanktype = MLINE; | |
3079 --yankendlnum; | |
3080 --yanklines; | |
3081 } | |
3082 | |
3083 y_current->y_size = yanklines; | |
3084 y_current->y_type = yanktype; /* set the yank register type */ | |
3085 y_current->y_width = 0; | |
3086 y_current->y_array = (char_u **)lalloc_clear((long_u)(sizeof(char_u *) * | |
3087 yanklines), TRUE); | |
3088 if (y_current->y_array == NULL) | |
3089 { | |
3090 y_current = curr; | |
3091 return FAIL; | |
3092 } | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3093 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3094 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
|
3095 #endif |
7 | 3096 |
3097 y_idx = 0; | |
3098 lnum = oap->start.lnum; | |
3099 | |
3100 if (oap->block_mode) | |
3101 { | |
3102 /* Visual block mode */ | |
3103 y_current->y_type = MBLOCK; /* set the yank register type */ | |
3104 y_current->y_width = oap->end_vcol - oap->start_vcol; | |
3105 | |
3106 if (curwin->w_curswant == MAXCOL && y_current->y_width > 0) | |
3107 y_current->y_width--; | |
3108 } | |
3109 | |
3110 for ( ; lnum <= yankendlnum; lnum++, y_idx++) | |
3111 { | |
3112 switch (y_current->y_type) | |
3113 { | |
3114 case MBLOCK: | |
3115 block_prep(oap, &bd, lnum, FALSE); | |
3116 if (yank_copy_line(&bd, y_idx) == FAIL) | |
3117 goto fail; | |
3118 break; | |
3119 | |
3120 case MLINE: | |
3121 if ((y_current->y_array[y_idx] = | |
3122 vim_strsave(ml_get(lnum))) == NULL) | |
3123 goto fail; | |
3124 break; | |
3125 | |
3126 case MCHAR: | |
3127 { | |
3128 colnr_T startcol = 0, endcol = MAXCOL; | |
3129 #ifdef FEAT_VIRTUALEDIT | |
3130 int is_oneChar = FALSE; | |
3131 colnr_T cs, ce; | |
3132 #endif | |
3133 p = ml_get(lnum); | |
3134 bd.startspaces = 0; | |
3135 bd.endspaces = 0; | |
3136 | |
3137 if (lnum == oap->start.lnum) | |
3138 { | |
3139 startcol = oap->start.col; | |
3140 #ifdef FEAT_VIRTUALEDIT | |
3141 if (virtual_op) | |
3142 { | |
3143 getvcol(curwin, &oap->start, &cs, NULL, &ce); | |
3144 if (ce != cs && oap->start.coladd > 0) | |
3145 { | |
3146 /* Part of a tab selected -- but don't | |
3147 * double-count it. */ | |
3148 bd.startspaces = (ce - cs + 1) | |
3149 - oap->start.coladd; | |
3150 startcol++; | |
3151 } | |
3152 } | |
3153 #endif | |
3154 } | |
3155 | |
3156 if (lnum == oap->end.lnum) | |
3157 { | |
3158 endcol = oap->end.col; | |
3159 #ifdef FEAT_VIRTUALEDIT | |
3160 if (virtual_op) | |
3161 { | |
3162 getvcol(curwin, &oap->end, &cs, NULL, &ce); | |
3163 if (p[endcol] == NUL || (cs + oap->end.coladd < ce | |
3164 # ifdef FEAT_MBYTE | |
3165 /* Don't add space for double-wide | |
3166 * char; endcol will be on last byte | |
3167 * of multi-byte char. */ | |
3168 && (*mb_head_off)(p, p + endcol) == 0 | |
3169 # endif | |
3170 )) | |
3171 { | |
3172 if (oap->start.lnum == oap->end.lnum | |
3173 && oap->start.col == oap->end.col) | |
3174 { | |
3175 /* Special case: inside a single char */ | |
3176 is_oneChar = TRUE; | |
3177 bd.startspaces = oap->end.coladd | |
3178 - oap->start.coladd + oap->inclusive; | |
3179 endcol = startcol; | |
3180 } | |
3181 else | |
3182 { | |
3183 bd.endspaces = oap->end.coladd | |
3184 + oap->inclusive; | |
3185 endcol -= oap->inclusive; | |
3186 } | |
3187 } | |
3188 } | |
3189 #endif | |
3190 } | |
3510 | 3191 if (endcol == MAXCOL) |
3192 endcol = (colnr_T)STRLEN(p); | |
7 | 3193 if (startcol > endcol |
3194 #ifdef FEAT_VIRTUALEDIT | |
3195 || is_oneChar | |
3196 #endif | |
3197 ) | |
3198 bd.textlen = 0; | |
3199 else | |
3200 { | |
3201 bd.textlen = endcol - startcol + oap->inclusive; | |
3202 } | |
3203 bd.textstart = p + startcol; | |
3204 if (yank_copy_line(&bd, y_idx) == FAIL) | |
3205 goto fail; | |
3206 break; | |
3207 } | |
3208 /* NOTREACHED */ | |
3209 } | |
3210 } | |
3211 | |
3212 if (curr != y_current) /* append the new block to the old block */ | |
3213 { | |
3214 new_ptr = (char_u **)lalloc((long_u)(sizeof(char_u *) * | |
3215 (curr->y_size + y_current->y_size)), TRUE); | |
3216 if (new_ptr == NULL) | |
3217 goto fail; | |
3218 for (j = 0; j < curr->y_size; ++j) | |
3219 new_ptr[j] = curr->y_array[j]; | |
3220 vim_free(curr->y_array); | |
3221 curr->y_array = new_ptr; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3222 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3223 curr->y_time_set = vim_time(); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3224 #endif |
7 | 3225 |
3226 if (yanktype == MLINE) /* MLINE overrides MCHAR and MBLOCK */ | |
3227 curr->y_type = MLINE; | |
3228 | |
164 | 3229 /* Concatenate the last line of the old block with the first line of |
3230 * the new block, unless being Vi compatible. */ | |
3231 if (curr->y_type == MCHAR && vim_strchr(p_cpo, CPO_REGAPPEND) == NULL) | |
7 | 3232 { |
3233 pnew = lalloc((long_u)(STRLEN(curr->y_array[curr->y_size - 1]) | |
3234 + STRLEN(y_current->y_array[0]) + 1), TRUE); | |
3235 if (pnew == NULL) | |
3236 { | |
3237 y_idx = y_current->y_size - 1; | |
3238 goto fail; | |
3239 } | |
3240 STRCPY(pnew, curr->y_array[--j]); | |
3241 STRCAT(pnew, y_current->y_array[0]); | |
3242 vim_free(curr->y_array[j]); | |
3243 vim_free(y_current->y_array[0]); | |
3244 curr->y_array[j++] = pnew; | |
3245 y_idx = 1; | |
3246 } | |
3247 else | |
3248 y_idx = 0; | |
3249 while (y_idx < y_current->y_size) | |
3250 curr->y_array[j++] = y_current->y_array[y_idx++]; | |
3251 curr->y_size = j; | |
3252 vim_free(y_current->y_array); | |
3253 y_current = curr; | |
3254 } | |
5981 | 3255 if (curwin->w_p_rnu) |
3256 redraw_later(SOME_VALID); /* cursor moved to start */ | |
7 | 3257 if (mess) /* Display message about yank? */ |
3258 { | |
3259 if (yanktype == MCHAR | |
3260 && !oap->block_mode | |
3261 && yanklines == 1) | |
3262 yanklines = 0; | |
3263 /* Some versions of Vi use ">=" here, some don't... */ | |
3264 if (yanklines > p_report) | |
3265 { | |
11682
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3266 char namebuf[100]; |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3267 |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3268 if (oap->regname == NUL) |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3269 *namebuf = NUL; |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3270 else |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3271 vim_snprintf(namebuf, sizeof(namebuf), |
11688
570f00932da8
patch 8.0.0727: message about what register to yank into is not translated
Christian Brabandt <cb@256bit.org>
parents:
11682
diff
changeset
|
3272 _(" into \"%c"), oap->regname); |
11682
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3273 |
7 | 3274 /* redisplay now, so message is not deleted */ |
3275 update_topline_redraw(); | |
3276 if (yanklines == 1) | |
205 | 3277 { |
3278 if (oap->block_mode) | |
11682
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3279 smsg((char_u *)_("block of 1 line yanked%s"), namebuf); |
205 | 3280 else |
11682
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3281 smsg((char_u *)_("1 line yanked%s"), namebuf); |
205 | 3282 } |
3283 else if (oap->block_mode) | |
11682
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3284 smsg((char_u *)_("block of %ld lines yanked%s"), |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3285 yanklines, namebuf); |
7 | 3286 else |
11682
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3287 smsg((char_u *)_("%ld lines yanked%s"), yanklines, |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3288 namebuf); |
7 | 3289 } |
3290 } | |
3291 | |
3292 /* | |
3293 * Set "'[" and "']" marks. | |
3294 */ | |
3295 curbuf->b_op_start = oap->start; | |
3296 curbuf->b_op_end = oap->end; | |
5735 | 3297 if (yanktype == MLINE && !oap->block_mode) |
36 | 3298 { |
3299 curbuf->b_op_start.col = 0; | |
3300 curbuf->b_op_end.col = MAXCOL; | |
3301 } | |
7 | 3302 |
3303 #ifdef FEAT_CLIPBOARD | |
3304 /* | |
3305 * If we were yanking to the '*' register, send result to clipboard. | |
3306 * If no register was specified, and "unnamed" in 'clipboard', make a copy | |
3307 * to the '*' register. | |
3308 */ | |
3309 if (clip_star.available | |
3310 && (curr == &(y_regs[STAR_REGISTER]) | |
2654 | 3311 || (!deleting && oap->regname == 0 |
6116 | 3312 && ((clip_unnamed | clip_unnamed_saved) & CLIP_UNNAMED)))) |
7 | 3313 { |
3314 if (curr != &(y_regs[STAR_REGISTER])) | |
3315 /* Copy the text from register 0 to the clipboard register. */ | |
3316 copy_yank_reg(&(y_regs[STAR_REGISTER])); | |
3317 | |
3318 clip_own_selection(&clip_star); | |
3319 clip_gen_set_selection(&clip_star); | |
2658 | 3320 # ifdef FEAT_X11 |
2654 | 3321 did_star = TRUE; |
2658 | 3322 # endif |
7 | 3323 } |
3324 | |
3325 # ifdef FEAT_X11 | |
3326 /* | |
3327 * If we were yanking to the '+' register, send result to selection. | |
3328 * Also copy to the '*' register, in case auto-select is off. | |
3329 */ | |
2654 | 3330 if (clip_plus.available |
3331 && (curr == &(y_regs[PLUS_REGISTER]) | |
3332 || (!deleting && oap->regname == 0 | |
6116 | 3333 && ((clip_unnamed | clip_unnamed_saved) & |
3334 CLIP_UNNAMED_PLUS)))) | |
7 | 3335 { |
2654 | 3336 if (curr != &(y_regs[PLUS_REGISTER])) |
3337 /* Copy the text from register 0 to the clipboard register. */ | |
3338 copy_yank_reg(&(y_regs[PLUS_REGISTER])); | |
3339 | |
7 | 3340 clip_own_selection(&clip_plus); |
3341 clip_gen_set_selection(&clip_plus); | |
12642
d1cbe8cb05d0
patch 8.0.1199: when 'clipboard' is "autoselectplus" star register is set
Christian Brabandt <cb@256bit.org>
parents:
12329
diff
changeset
|
3342 if (!clip_isautosel_star() && !clip_isautosel_plus() |
d1cbe8cb05d0
patch 8.0.1199: when 'clipboard' is "autoselectplus" star register is set
Christian Brabandt <cb@256bit.org>
parents:
12329
diff
changeset
|
3343 && !did_star && curr == &(y_regs[PLUS_REGISTER])) |
7 | 3344 { |
3345 copy_yank_reg(&(y_regs[STAR_REGISTER])); | |
3346 clip_own_selection(&clip_star); | |
3347 clip_gen_set_selection(&clip_star); | |
3348 } | |
3349 } | |
3350 # endif | |
3351 #endif | |
3352 | |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
3353 #ifdef FEAT_AUTOCMD |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
3354 if (!deleting && has_textyankpost()) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
3355 yank_do_autocmd(oap, y_current); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
3356 #endif |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
3357 |
7 | 3358 return OK; |
3359 | |
3360 fail: /* free the allocated lines */ | |
3361 free_yank(y_idx + 1); | |
3362 y_current = curr; | |
3363 return FAIL; | |
3364 } | |
3365 | |
3366 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3367 yank_copy_line(struct block_def *bd, long y_idx) |
7 | 3368 { |
3369 char_u *pnew; | |
3370 | |
3371 if ((pnew = alloc(bd->startspaces + bd->endspaces + bd->textlen + 1)) | |
3372 == NULL) | |
3373 return FAIL; | |
3374 y_current->y_array[y_idx] = pnew; | |
6929 | 3375 vim_memset(pnew, ' ', (size_t)bd->startspaces); |
7 | 3376 pnew += bd->startspaces; |
3377 mch_memmove(pnew, bd->textstart, (size_t)bd->textlen); | |
3378 pnew += bd->textlen; | |
6929 | 3379 vim_memset(pnew, ' ', (size_t)bd->endspaces); |
7 | 3380 pnew += bd->endspaces; |
3381 *pnew = NUL; | |
3382 return OK; | |
3383 } | |
3384 | |
3385 #ifdef FEAT_CLIPBOARD | |
3386 /* | |
3387 * Make a copy of the y_current register to register "reg". | |
3388 */ | |
3389 static void | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3390 copy_yank_reg(yankreg_T *reg) |
7 | 3391 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3392 yankreg_T *curr = y_current; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3393 long j; |
7 | 3394 |
3395 y_current = reg; | |
3396 free_yank_all(); | |
3397 *y_current = *curr; | |
3398 y_current->y_array = (char_u **)lalloc_clear( | |
3399 (long_u)(sizeof(char_u *) * y_current->y_size), TRUE); | |
3400 if (y_current->y_array == NULL) | |
3401 y_current->y_size = 0; | |
3402 else | |
3403 for (j = 0; j < y_current->y_size; ++j) | |
3404 if ((y_current->y_array[j] = vim_strsave(curr->y_array[j])) == NULL) | |
3405 { | |
3406 free_yank(j); | |
3407 y_current->y_size = 0; | |
3408 break; | |
3409 } | |
3410 y_current = curr; | |
3411 } | |
3412 #endif | |
3413 | |
3414 /* | |
140 | 3415 * Put contents of register "regname" into the text. |
3416 * Caller must check "regname" to be valid! | |
3417 * "flags": PUT_FIXINDENT make indent look nice | |
3418 * PUT_CURSEND leave cursor after end of new text | |
3419 * PUT_LINE force linewise put (":put") | |
7 | 3420 */ |
3421 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3422 do_put( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3423 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3424 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
|
3425 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3426 int flags) |
7 | 3427 { |
3428 char_u *ptr; | |
3429 char_u *newp, *oldp; | |
3430 int yanklen; | |
3431 int totlen = 0; /* init for gcc */ | |
3432 linenr_T lnum; | |
3433 colnr_T col; | |
3434 long i; /* index in y_array[] */ | |
3435 int y_type; | |
3436 long y_size; | |
3437 int oldlen; | |
3438 long y_width = 0; | |
3439 colnr_T vcol; | |
3440 int delcount; | |
3441 int incr = 0; | |
3442 long j; | |
3443 struct block_def bd; | |
3444 char_u **y_array = NULL; | |
3445 long nr_lines = 0; | |
3446 pos_T new_cursor; | |
3447 int indent; | |
3448 int orig_indent = 0; /* init for gcc */ | |
3449 int indent_diff = 0; /* init for gcc */ | |
3450 int first_indent = TRUE; | |
3451 int lendiff = 0; | |
3452 pos_T old_pos; | |
3453 char_u *insert_string = NULL; | |
3454 int allocated = FALSE; | |
3455 long cnt; | |
3456 | |
3457 #ifdef FEAT_CLIPBOARD | |
3458 /* Adjust register name for "unnamed" in 'clipboard'. */ | |
3459 adjust_clip_reg(®name); | |
3460 (void)may_get_selection(regname); | |
3461 #endif | |
3462 | |
3463 if (flags & PUT_FIXINDENT) | |
3464 orig_indent = get_indent(); | |
3465 | |
3466 curbuf->b_op_start = curwin->w_cursor; /* default for '[ mark */ | |
3467 curbuf->b_op_end = curwin->w_cursor; /* default for '] mark */ | |
3468 | |
3469 /* | |
3470 * Using inserted text works differently, because the register includes | |
3471 * special characters (newlines, etc.). | |
3472 */ | |
3473 if (regname == '.') | |
3474 { | |
10494
1e700d72561d
commit https://github.com/vim/vim/commit/f8eb9c51e5bbd10e59c9b1247f8f6c7f5b77ccd0
Christian Brabandt <cb@256bit.org>
parents:
10486
diff
changeset
|
3475 if (VIsual_active) |
1e700d72561d
commit https://github.com/vim/vim/commit/f8eb9c51e5bbd10e59c9b1247f8f6c7f5b77ccd0
Christian Brabandt <cb@256bit.org>
parents:
10486
diff
changeset
|
3476 stuffcharReadbuff(VIsual_mode); |
7 | 3477 (void)stuff_inserted((dir == FORWARD ? (count == -1 ? 'o' : 'a') : |
3478 (count == -1 ? 'O' : 'i')), count, FALSE); | |
3479 /* Putting the text is done later, so can't really move the cursor to | |
3480 * the next character. Use "l" to simulate it. */ | |
3481 if ((flags & PUT_CURSEND) && gchar_cursor() != NUL) | |
3482 stuffcharReadbuff('l'); | |
3483 return; | |
3484 } | |
3485 | |
3486 /* | |
3487 * For special registers '%' (file name), '#' (alternate file name) and | |
3488 * ':' (last command line), etc. we have to create a fake yank register. | |
3489 */ | |
3490 if (get_spec_reg(regname, &insert_string, &allocated, TRUE)) | |
3491 { | |
3492 if (insert_string == NULL) | |
3493 return; | |
3494 } | |
3495 | |
4005 | 3496 #ifdef FEAT_AUTOCMD |
3497 /* Autocommands may be executed when saving lines for undo, which may make | |
3498 * y_array invalid. Start undo now to avoid that. */ | |
3499 u_save(curwin->w_cursor.lnum, curwin->w_cursor.lnum + 1); | |
3500 #endif | |
3501 | |
7 | 3502 if (insert_string != NULL) |
3503 { | |
3504 y_type = MCHAR; | |
3505 #ifdef FEAT_EVAL | |
3506 if (regname == '=') | |
3507 { | |
3508 /* For the = register we need to split the string at NL | |
3093 | 3509 * characters. |
3510 * Loop twice: count the number of lines and save them. */ | |
7 | 3511 for (;;) |
3512 { | |
3513 y_size = 0; | |
3514 ptr = insert_string; | |
3515 while (ptr != NULL) | |
3516 { | |
3517 if (y_array != NULL) | |
3518 y_array[y_size] = ptr; | |
3519 ++y_size; | |
3520 ptr = vim_strchr(ptr, '\n'); | |
3521 if (ptr != NULL) | |
3522 { | |
3523 if (y_array != NULL) | |
3524 *ptr = NUL; | |
3525 ++ptr; | |
3093 | 3526 /* A trailing '\n' makes the register linewise. */ |
7 | 3527 if (*ptr == NUL) |
3528 { | |
3529 y_type = MLINE; | |
3530 break; | |
3531 } | |
3532 } | |
3533 } | |
3534 if (y_array != NULL) | |
3535 break; | |
3536 y_array = (char_u **)alloc((unsigned) | |
3537 (y_size * sizeof(char_u *))); | |
3538 if (y_array == NULL) | |
3539 goto end; | |
3540 } | |
3541 } | |
3542 else | |
3543 #endif | |
3544 { | |
3545 y_size = 1; /* use fake one-line yank register */ | |
3546 y_array = &insert_string; | |
3547 } | |
3548 } | |
3549 else | |
3550 { | |
3551 get_yank_register(regname, FALSE); | |
3552 | |
3553 y_type = y_current->y_type; | |
3554 y_width = y_current->y_width; | |
3555 y_size = y_current->y_size; | |
3556 y_array = y_current->y_array; | |
3557 } | |
3558 | |
3559 if (y_type == MLINE) | |
3560 { | |
3561 if (flags & PUT_LINE_SPLIT) | |
3562 { | |
6845 | 3563 char_u *p; |
3564 | |
7 | 3565 /* "p" or "P" in Visual mode: split the lines to put the text in |
3566 * between. */ | |
3567 if (u_save_cursor() == FAIL) | |
3568 goto end; | |
6845 | 3569 p = ml_get_cursor(); |
3570 if (dir == FORWARD && *p != NUL) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
3571 MB_PTR_ADV(p); |
6845 | 3572 ptr = vim_strsave(p); |
7 | 3573 if (ptr == NULL) |
3574 goto end; | |
3575 ml_append(curwin->w_cursor.lnum, ptr, (colnr_T)0, FALSE); | |
3576 vim_free(ptr); | |
3577 | |
6845 | 3578 oldp = ml_get_curline(); |
3579 p = oldp + curwin->w_cursor.col; | |
3580 if (dir == FORWARD && *p != NUL) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
3581 MB_PTR_ADV(p); |
6845 | 3582 ptr = vim_strnsave(oldp, p - oldp); |
7 | 3583 if (ptr == NULL) |
3584 goto end; | |
3585 ml_replace(curwin->w_cursor.lnum, ptr, FALSE); | |
3586 ++nr_lines; | |
3587 dir = FORWARD; | |
3588 } | |
3589 if (flags & PUT_LINE_FORWARD) | |
3590 { | |
3591 /* Must be "p" for a Visual block, put lines below the block. */ | |
692 | 3592 curwin->w_cursor = curbuf->b_visual.vi_end; |
7 | 3593 dir = FORWARD; |
3594 } | |
3595 curbuf->b_op_start = curwin->w_cursor; /* default for '[ mark */ | |
3596 curbuf->b_op_end = curwin->w_cursor; /* default for '] mark */ | |
3597 } | |
3598 | |
3599 if (flags & PUT_LINE) /* :put command or "p" in Visual line mode. */ | |
3600 y_type = MLINE; | |
3601 | |
3602 if (y_size == 0 || y_array == NULL) | |
3603 { | |
3604 EMSG2(_("E353: Nothing in register %s"), | |
3605 regname == 0 ? (char_u *)"\"" : transchar(regname)); | |
3606 goto end; | |
3607 } | |
3608 | |
3609 if (y_type == MBLOCK) | |
3610 { | |
3611 lnum = curwin->w_cursor.lnum + y_size + 1; | |
3612 if (lnum > curbuf->b_ml.ml_line_count) | |
3613 lnum = curbuf->b_ml.ml_line_count + 1; | |
3614 if (u_save(curwin->w_cursor.lnum - 1, lnum) == FAIL) | |
3615 goto end; | |
3616 } | |
5735 | 3617 else if (y_type == MLINE) |
7 | 3618 { |
3619 lnum = curwin->w_cursor.lnum; | |
3620 #ifdef FEAT_FOLDING | |
3621 /* Correct line number for closed fold. Don't move the cursor yet, | |
3622 * u_save() uses it. */ | |
3623 if (dir == BACKWARD) | |
3624 (void)hasFolding(lnum, &lnum, NULL); | |
3625 else | |
3626 (void)hasFolding(lnum, NULL, &lnum); | |
3627 #endif | |
3628 if (dir == FORWARD) | |
3629 ++lnum; | |
5053
35b6fc57a286
updated for version 7.3.1270
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3630 /* 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
|
3631 * it in the saved lines. */ |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
3632 if ((BUFEMPTY() ? u_save(0, 2) : u_save(lnum - 1, lnum)) == FAIL) |
7 | 3633 goto end; |
3634 #ifdef FEAT_FOLDING | |
3635 if (dir == FORWARD) | |
3636 curwin->w_cursor.lnum = lnum - 1; | |
3637 else | |
3638 curwin->w_cursor.lnum = lnum; | |
3639 curbuf->b_op_start = curwin->w_cursor; /* for mark_adjust() */ | |
3640 #endif | |
3641 } | |
3642 else if (u_save_cursor() == FAIL) | |
3643 goto end; | |
3644 | |
3645 yanklen = (int)STRLEN(y_array[0]); | |
3646 | |
3647 #ifdef FEAT_VIRTUALEDIT | |
3648 if (ve_flags == VE_ALL && y_type == MCHAR) | |
3649 { | |
3650 if (gchar_cursor() == TAB) | |
3651 { | |
3652 /* Don't need to insert spaces when "p" on the last position of a | |
3653 * tab or "P" on the first position. */ | |
3654 if (dir == FORWARD | |
3655 ? (int)curwin->w_cursor.coladd < curbuf->b_p_ts - 1 | |
3656 : curwin->w_cursor.coladd > 0) | |
3657 coladvance_force(getviscol()); | |
3658 else | |
3659 curwin->w_cursor.coladd = 0; | |
3660 } | |
3661 else if (curwin->w_cursor.coladd > 0 || gchar_cursor() == NUL) | |
3662 coladvance_force(getviscol() + (dir == FORWARD)); | |
3663 } | |
3664 #endif | |
3665 | |
3666 lnum = curwin->w_cursor.lnum; | |
3667 col = curwin->w_cursor.col; | |
3668 | |
3669 /* | |
3670 * Block mode | |
3671 */ | |
3672 if (y_type == MBLOCK) | |
3673 { | |
10664
94db9c08e206
patch 8.0.0222: blockwise put on multi-byte character misplaced
Christian Brabandt <cb@256bit.org>
parents:
10494
diff
changeset
|
3674 int c = gchar_cursor(); |
7 | 3675 colnr_T endcol2 = 0; |
3676 | |
3677 if (dir == FORWARD && c != NUL) | |
3678 { | |
3679 #ifdef FEAT_VIRTUALEDIT | |
3680 if (ve_flags == VE_ALL) | |
3681 getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2); | |
3682 else | |
3683 #endif | |
3684 getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col); | |
3685 | |
3686 #ifdef FEAT_MBYTE | |
3687 if (has_mbyte) | |
3688 /* move to start of next multi-byte character */ | |
474 | 3689 curwin->w_cursor.col += (*mb_ptr2len)(ml_get_cursor()); |
7 | 3690 else |
3691 #endif | |
3692 #ifdef FEAT_VIRTUALEDIT | |
3693 if (c != TAB || ve_flags != VE_ALL) | |
3694 #endif | |
3695 ++curwin->w_cursor.col; | |
3696 ++col; | |
3697 } | |
3698 else | |
3699 getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2); | |
3700 | |
3701 #ifdef FEAT_VIRTUALEDIT | |
3702 col += curwin->w_cursor.coladd; | |
1304 | 3703 if (ve_flags == VE_ALL |
3704 && (curwin->w_cursor.coladd > 0 | |
3705 || endcol2 == curwin->w_cursor.col)) | |
7 | 3706 { |
3707 if (dir == FORWARD && c == NUL) | |
3708 ++col; | |
3709 if (dir != FORWARD && c != NUL) | |
3710 ++curwin->w_cursor.col; | |
3711 if (c == TAB) | |
3712 { | |
3713 if (dir == BACKWARD && curwin->w_cursor.col) | |
3714 curwin->w_cursor.col--; | |
3715 if (dir == FORWARD && col - 1 == endcol2) | |
3716 curwin->w_cursor.col++; | |
3717 } | |
3718 } | |
3719 curwin->w_cursor.coladd = 0; | |
3720 #endif | |
699 | 3721 bd.textcol = 0; |
7 | 3722 for (i = 0; i < y_size; ++i) |
3723 { | |
3724 int spaces; | |
3725 char shortline; | |
3726 | |
3727 bd.startspaces = 0; | |
3728 bd.endspaces = 0; | |
3729 vcol = 0; | |
3730 delcount = 0; | |
3731 | |
3732 /* add a new line */ | |
3733 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
3734 { | |
3735 if (ml_append(curbuf->b_ml.ml_line_count, (char_u *)"", | |
3736 (colnr_T)1, FALSE) == FAIL) | |
3737 break; | |
3738 ++nr_lines; | |
3739 } | |
3740 /* get the old line and advance to the position to insert at */ | |
3741 oldp = ml_get_curline(); | |
3742 oldlen = (int)STRLEN(oldp); | |
3743 for (ptr = oldp; vcol < col && *ptr; ) | |
3744 { | |
3745 /* Count a tab for what it's worth (if list mode not on) */ | |
5995 | 3746 incr = lbr_chartabsize_adv(oldp, &ptr, (colnr_T)vcol); |
7 | 3747 vcol += incr; |
3748 } | |
3749 bd.textcol = (colnr_T)(ptr - oldp); | |
3750 | |
3751 shortline = (vcol < col) || (vcol == col && !*ptr) ; | |
3752 | |
3753 if (vcol < col) /* line too short, padd with spaces */ | |
3754 bd.startspaces = col - vcol; | |
3755 else if (vcol > col) | |
3756 { | |
3757 bd.endspaces = vcol - col; | |
3758 bd.startspaces = incr - bd.endspaces; | |
3759 --bd.textcol; | |
3760 delcount = 1; | |
3761 #ifdef FEAT_MBYTE | |
3762 if (has_mbyte) | |
3763 bd.textcol -= (*mb_head_off)(oldp, oldp + bd.textcol); | |
3764 #endif | |
3765 if (oldp[bd.textcol] != TAB) | |
3766 { | |
3767 /* Only a Tab can be split into spaces. Other | |
3768 * characters will have to be moved to after the | |
3769 * block, causing misalignment. */ | |
3770 delcount = 0; | |
3771 bd.endspaces = 0; | |
3772 } | |
3773 } | |
3774 | |
3775 yanklen = (int)STRLEN(y_array[i]); | |
3776 | |
3777 /* calculate number of spaces required to fill right side of block*/ | |
3778 spaces = y_width + 1; | |
3779 for (j = 0; j < yanklen; j++) | |
5995 | 3780 spaces -= lbr_chartabsize(NULL, &y_array[i][j], 0); |
7 | 3781 if (spaces < 0) |
3782 spaces = 0; | |
3783 | |
3784 /* insert the new text */ | |
3785 totlen = count * (yanklen + spaces) + bd.startspaces + bd.endspaces; | |
3786 newp = alloc_check((unsigned)totlen + oldlen + 1); | |
3787 if (newp == NULL) | |
3788 break; | |
3789 /* copy part up to cursor to new line */ | |
3790 ptr = newp; | |
3791 mch_memmove(ptr, oldp, (size_t)bd.textcol); | |
3792 ptr += bd.textcol; | |
3793 /* may insert some spaces before the new text */ | |
6929 | 3794 vim_memset(ptr, ' ', (size_t)bd.startspaces); |
7 | 3795 ptr += bd.startspaces; |
3796 /* insert the new text */ | |
3797 for (j = 0; j < count; ++j) | |
3798 { | |
3799 mch_memmove(ptr, y_array[i], (size_t)yanklen); | |
3800 ptr += yanklen; | |
3801 | |
3802 /* insert block's trailing spaces only if there's text behind */ | |
3803 if ((j < count - 1 || !shortline) && spaces) | |
3804 { | |
6929 | 3805 vim_memset(ptr, ' ', (size_t)spaces); |
7 | 3806 ptr += spaces; |
3807 } | |
3808 } | |
3809 /* may insert some spaces after the new text */ | |
6929 | 3810 vim_memset(ptr, ' ', (size_t)bd.endspaces); |
7 | 3811 ptr += bd.endspaces; |
3812 /* move the text after the cursor to the end of the line. */ | |
3813 mch_memmove(ptr, oldp + bd.textcol + delcount, | |
3814 (size_t)(oldlen - bd.textcol - delcount + 1)); | |
3815 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
3816 | |
3817 ++curwin->w_cursor.lnum; | |
3818 if (i == 0) | |
3819 curwin->w_cursor.col += bd.startspaces; | |
3820 } | |
3821 | |
3822 changed_lines(lnum, 0, curwin->w_cursor.lnum, nr_lines); | |
3823 | |
3824 /* Set '[ mark. */ | |
3825 curbuf->b_op_start = curwin->w_cursor; | |
3826 curbuf->b_op_start.lnum = lnum; | |
3827 | |
3828 /* adjust '] mark */ | |
3829 curbuf->b_op_end.lnum = curwin->w_cursor.lnum - 1; | |
3830 curbuf->b_op_end.col = bd.textcol + totlen - 1; | |
237 | 3831 # ifdef FEAT_VIRTUALEDIT |
7 | 3832 curbuf->b_op_end.coladd = 0; |
237 | 3833 # endif |
7 | 3834 if (flags & PUT_CURSEND) |
3835 { | |
916 | 3836 colnr_T len; |
3837 | |
7 | 3838 curwin->w_cursor = curbuf->b_op_end; |
3839 curwin->w_cursor.col++; | |
916 | 3840 |
3841 /* in Insert mode we might be after the NUL, correct for that */ | |
3842 len = (colnr_T)STRLEN(ml_get_curline()); | |
3843 if (curwin->w_cursor.col > len) | |
3844 curwin->w_cursor.col = len; | |
7 | 3845 } |
3846 else | |
3847 curwin->w_cursor.lnum = lnum; | |
3848 } | |
3849 else | |
3850 { | |
3851 /* | |
3852 * Character or Line mode | |
3853 */ | |
3854 if (y_type == MCHAR) | |
3855 { | |
3856 /* if type is MCHAR, FORWARD is the same as BACKWARD on the next | |
3857 * char */ | |
3858 if (dir == FORWARD && gchar_cursor() != NUL) | |
3859 { | |
3860 #ifdef FEAT_MBYTE | |
3861 if (has_mbyte) | |
3862 { | |
474 | 3863 int bytelen = (*mb_ptr2len)(ml_get_cursor()); |
7 | 3864 |
3865 /* put it on the next of the multi-byte character. */ | |
3866 col += bytelen; | |
3867 if (yanklen) | |
3868 { | |
3869 curwin->w_cursor.col += bytelen; | |
3870 curbuf->b_op_end.col += bytelen; | |
3871 } | |
3872 } | |
3873 else | |
3874 #endif | |
3875 { | |
3876 ++col; | |
3877 if (yanklen) | |
3878 { | |
3879 ++curwin->w_cursor.col; | |
3880 ++curbuf->b_op_end.col; | |
3881 } | |
3882 } | |
3883 } | |
3884 curbuf->b_op_start = curwin->w_cursor; | |
3885 } | |
3886 /* | |
3887 * Line mode: BACKWARD is the same as FORWARD on the previous line | |
3888 */ | |
3889 else if (dir == BACKWARD) | |
3890 --lnum; | |
699 | 3891 new_cursor = curwin->w_cursor; |
7 | 3892 |
3893 /* | |
3894 * simple case: insert into current line | |
3895 */ | |
3896 if (y_type == MCHAR && y_size == 1) | |
3897 { | |
10692
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
3898 linenr_T end_lnum = 0; /* init for gcc */ |
10688
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3899 |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3900 if (VIsual_active) |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3901 { |
10692
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
3902 end_lnum = curbuf->b_visual.vi_end.lnum; |
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
3903 if (end_lnum < curbuf->b_visual.vi_start.lnum) |
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
3904 end_lnum = curbuf->b_visual.vi_start.lnum; |
10688
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3905 } |
10670
bce3eccea39a
patch 8.0.0225: put in Visual block mode terminates early
Christian Brabandt <cb@256bit.org>
parents:
10664
diff
changeset
|
3906 |
5365 | 3907 do { |
3908 totlen = count * yanklen; | |
3909 if (totlen > 0) | |
7 | 3910 { |
5365 | 3911 oldp = ml_get(lnum); |
10688
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3912 if (VIsual_active && col > (int)STRLEN(oldp)) |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3913 { |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3914 lnum++; |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3915 continue; |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3916 } |
5365 | 3917 newp = alloc_check((unsigned)(STRLEN(oldp) + totlen + 1)); |
3918 if (newp == NULL) | |
3919 goto end; /* alloc() gave an error message */ | |
3920 mch_memmove(newp, oldp, (size_t)col); | |
3921 ptr = newp + col; | |
3922 for (i = 0; i < count; ++i) | |
3923 { | |
3924 mch_memmove(ptr, y_array[0], (size_t)yanklen); | |
3925 ptr += yanklen; | |
3926 } | |
3927 STRMOVE(ptr, oldp + col); | |
3928 ml_replace(lnum, newp, FALSE); | |
3929 /* Place cursor on last putted char. */ | |
3930 if (lnum == curwin->w_cursor.lnum) | |
5496 | 3931 { |
3932 /* make sure curwin->w_virtcol is updated */ | |
3933 changed_cline_bef_curs(); | |
5365 | 3934 curwin->w_cursor.col += (colnr_T)(totlen - 1); |
5496 | 3935 } |
7 | 3936 } |
5365 | 3937 if (VIsual_active) |
3938 lnum++; | |
10692
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
3939 } while (VIsual_active && lnum <= end_lnum); |
5365 | 3940 |
6379 | 3941 if (VIsual_active) /* reset lnum to the last visual line */ |
3942 lnum--; | |
3943 | |
7 | 3944 curbuf->b_op_end = curwin->w_cursor; |
3945 /* For "CTRL-O p" in Insert mode, put cursor after last char */ | |
3946 if (totlen && (restart_edit != 0 || (flags & PUT_CURSEND))) | |
3947 ++curwin->w_cursor.col; | |
3948 changed_bytes(lnum, col); | |
3949 } | |
3950 else | |
3951 { | |
3952 /* | |
3953 * Insert at least one line. When y_type is MCHAR, break the first | |
3954 * line in two. | |
3955 */ | |
3956 for (cnt = 1; cnt <= count; ++cnt) | |
3957 { | |
3958 i = 0; | |
3959 if (y_type == MCHAR) | |
3960 { | |
3961 /* | |
3962 * Split the current line in two at the insert position. | |
3963 * First insert y_array[size - 1] in front of second line. | |
3964 * Then append y_array[0] to first line. | |
3965 */ | |
3966 lnum = new_cursor.lnum; | |
3967 ptr = ml_get(lnum) + col; | |
3968 totlen = (int)STRLEN(y_array[y_size - 1]); | |
3969 newp = alloc_check((unsigned)(STRLEN(ptr) + totlen + 1)); | |
3970 if (newp == NULL) | |
3971 goto error; | |
3972 STRCPY(newp, y_array[y_size - 1]); | |
3973 STRCAT(newp, ptr); | |
3974 /* insert second line */ | |
3975 ml_append(lnum, newp, (colnr_T)0, FALSE); | |
3976 vim_free(newp); | |
3977 | |
3978 oldp = ml_get(lnum); | |
3979 newp = alloc_check((unsigned)(col + yanklen + 1)); | |
3980 if (newp == NULL) | |
3981 goto error; | |
3982 /* copy first part of line */ | |
3983 mch_memmove(newp, oldp, (size_t)col); | |
3984 /* append to first line */ | |
3985 mch_memmove(newp + col, y_array[0], (size_t)(yanklen + 1)); | |
3986 ml_replace(lnum, newp, FALSE); | |
3987 | |
3988 curwin->w_cursor.lnum = lnum; | |
3989 i = 1; | |
3990 } | |
3991 | |
3992 for (; i < y_size; ++i) | |
3993 { | |
3994 if ((y_type != MCHAR || i < y_size - 1) | |
3995 && ml_append(lnum, y_array[i], (colnr_T)0, FALSE) | |
3996 == FAIL) | |
3997 goto error; | |
3998 lnum++; | |
3999 ++nr_lines; | |
4000 if (flags & PUT_FIXINDENT) | |
4001 { | |
4002 old_pos = curwin->w_cursor; | |
4003 curwin->w_cursor.lnum = lnum; | |
4004 ptr = ml_get(lnum); | |
4005 if (cnt == count && i == y_size - 1) | |
4006 lendiff = (int)STRLEN(ptr); | |
4007 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) | |
4008 if (*ptr == '#' && preprocs_left()) | |
4009 indent = 0; /* Leave # lines at start */ | |
4010 else | |
4011 #endif | |
4012 if (*ptr == NUL) | |
4013 indent = 0; /* Ignore empty lines */ | |
4014 else if (first_indent) | |
4015 { | |
4016 indent_diff = orig_indent - get_indent(); | |
4017 indent = orig_indent; | |
4018 first_indent = FALSE; | |
4019 } | |
4020 else if ((indent = get_indent() + indent_diff) < 0) | |
4021 indent = 0; | |
4022 (void)set_indent(indent, 0); | |
4023 curwin->w_cursor = old_pos; | |
4024 /* remember how many chars were removed */ | |
4025 if (cnt == count && i == y_size - 1) | |
4026 lendiff -= (int)STRLEN(ml_get(lnum)); | |
4027 } | |
4028 } | |
4029 } | |
4030 | |
4031 error: | |
4032 /* Adjust marks. */ | |
4033 if (y_type == MLINE) | |
4034 { | |
4035 curbuf->b_op_start.col = 0; | |
4036 if (dir == FORWARD) | |
4037 curbuf->b_op_start.lnum++; | |
4038 } | |
9225
b0b2bd8e5217
commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents:
8989
diff
changeset
|
4039 /* Skip mark_adjust when adding lines after the last one, there |
11065
f5bd684e47a1
patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents:
10827
diff
changeset
|
4040 * can't be marks there. But still needed in diff mode. */ |
9225
b0b2bd8e5217
commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents:
8989
diff
changeset
|
4041 if (curbuf->b_op_start.lnum + (y_type == MCHAR) - 1 + nr_lines |
11065
f5bd684e47a1
patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents:
10827
diff
changeset
|
4042 < curbuf->b_ml.ml_line_count |
f5bd684e47a1
patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents:
10827
diff
changeset
|
4043 #ifdef FEAT_DIFF |
f5bd684e47a1
patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents:
10827
diff
changeset
|
4044 || curwin->w_p_diff |
f5bd684e47a1
patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents:
10827
diff
changeset
|
4045 #endif |
f5bd684e47a1
patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents:
10827
diff
changeset
|
4046 ) |
9225
b0b2bd8e5217
commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents:
8989
diff
changeset
|
4047 mark_adjust(curbuf->b_op_start.lnum + (y_type == MCHAR), |
7 | 4048 (linenr_T)MAXLNUM, nr_lines, 0L); |
4049 | |
4050 /* note changed text for displaying and folding */ | |
4051 if (y_type == MCHAR) | |
4052 changed_lines(curwin->w_cursor.lnum, col, | |
4053 curwin->w_cursor.lnum + 1, nr_lines); | |
4054 else | |
4055 changed_lines(curbuf->b_op_start.lnum, 0, | |
4056 curbuf->b_op_start.lnum, nr_lines); | |
4057 | |
4058 /* put '] mark at last inserted character */ | |
4059 curbuf->b_op_end.lnum = lnum; | |
4060 /* correct length for change in indent */ | |
4061 col = (colnr_T)STRLEN(y_array[y_size - 1]) - lendiff; | |
4062 if (col > 1) | |
4063 curbuf->b_op_end.col = col - 1; | |
4064 else | |
4065 curbuf->b_op_end.col = 0; | |
4066 | |
168 | 4067 if (flags & PUT_CURSLINE) |
4068 { | |
237 | 4069 /* ":put": put cursor on last inserted line */ |
168 | 4070 curwin->w_cursor.lnum = lnum; |
4071 beginline(BL_WHITE | BL_FIX); | |
4072 } | |
4073 else if (flags & PUT_CURSEND) | |
7 | 4074 { |
4075 /* put cursor after inserted text */ | |
4076 if (y_type == MLINE) | |
4077 { | |
4078 if (lnum >= curbuf->b_ml.ml_line_count) | |
4079 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4080 else | |
4081 curwin->w_cursor.lnum = lnum + 1; | |
4082 curwin->w_cursor.col = 0; | |
4083 } | |
4084 else | |
4085 { | |
4086 curwin->w_cursor.lnum = lnum; | |
4087 curwin->w_cursor.col = col; | |
4088 } | |
4089 } | |
4090 else if (y_type == MLINE) | |
4091 { | |
168 | 4092 /* put cursor on first non-blank in first inserted line */ |
7 | 4093 curwin->w_cursor.col = 0; |
4094 if (dir == FORWARD) | |
4095 ++curwin->w_cursor.lnum; | |
4096 beginline(BL_WHITE | BL_FIX); | |
4097 } | |
4098 else /* put cursor on first inserted character */ | |
4099 curwin->w_cursor = new_cursor; | |
4100 } | |
4101 } | |
4102 | |
4103 msgmore(nr_lines); | |
4104 curwin->w_set_curswant = TRUE; | |
4105 | |
4106 end: | |
4107 if (allocated) | |
4108 vim_free(insert_string); | |
840 | 4109 if (regname == '=') |
4110 vim_free(y_array); | |
4111 | |
5380 | 4112 VIsual_active = FALSE; |
4113 | |
140 | 4114 /* If the cursor is past the end of the line put it at the end. */ |
844 | 4115 adjust_cursor_eol(); |
4116 } | |
4117 | |
4118 /* | |
4119 * When the cursor is on the NUL past the end of the line and it should not be | |
4120 * there move it left. | |
4121 */ | |
4122 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4123 adjust_cursor_eol(void) |
844 | 4124 { |
4125 if (curwin->w_cursor.col > 0 | |
4126 && gchar_cursor() == NUL | |
773 | 4127 #ifdef FEAT_VIRTUALEDIT |
4128 && (ve_flags & VE_ONEMORE) == 0 | |
4129 #endif | |
7 | 4130 && !(restart_edit || (State & INSERT))) |
4131 { | |
557 | 4132 /* Put the cursor on the last character in the line. */ |
555 | 4133 dec_cursor(); |
844 | 4134 |
7 | 4135 #ifdef FEAT_VIRTUALEDIT |
4136 if (ve_flags == VE_ALL) | |
557 | 4137 { |
4138 colnr_T scol, ecol; | |
4139 | |
4140 /* Coladd is set to the width of the last character. */ | |
4141 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); | |
4142 curwin->w_cursor.coladd = ecol - scol + 1; | |
4143 } | |
7 | 4144 #endif |
4145 } | |
4146 } | |
4147 | |
4148 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) || defined(PROTO) | |
4149 /* | |
4150 * Return TRUE if lines starting with '#' should be left aligned. | |
4151 */ | |
4152 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4153 preprocs_left(void) |
7 | 4154 { |
4155 return | |
4156 # ifdef FEAT_SMARTINDENT | |
4157 # ifdef FEAT_CINDENT | |
4158 (curbuf->b_p_si && !curbuf->b_p_cin) || | |
4159 # else | |
4160 curbuf->b_p_si | |
4161 # endif | |
4162 # endif | |
4163 # ifdef FEAT_CINDENT | |
5438 | 4164 (curbuf->b_p_cin && in_cinkeys('#', ' ', TRUE) |
4165 && curbuf->b_ind_hash_comment == 0) | |
7 | 4166 # endif |
4167 ; | |
4168 } | |
4169 #endif | |
4170 | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4171 /* |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4172 * 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
|
4173 */ |
7 | 4174 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4175 get_register_name(int num) |
7 | 4176 { |
4177 if (num == -1) | |
4178 return '"'; | |
4179 else if (num < 10) | |
4180 return num + '0'; | |
4181 else if (num == DELETION_REGISTER) | |
4182 return '-'; | |
4183 #ifdef FEAT_CLIPBOARD | |
4184 else if (num == STAR_REGISTER) | |
4185 return '*'; | |
4186 else if (num == PLUS_REGISTER) | |
4187 return '+'; | |
4188 #endif | |
4189 else | |
4190 { | |
4191 #ifdef EBCDIC | |
4192 int i; | |
4193 | |
4194 /* EBCDIC is really braindead ... */ | |
4195 i = 'a' + (num - 10); | |
4196 if (i > 'i') | |
4197 i += 7; | |
4198 if (i > 'r') | |
4199 i += 8; | |
4200 return i; | |
4201 #else | |
4202 return num + 'a' - 10; | |
4203 #endif | |
4204 } | |
4205 } | |
4206 | |
4207 /* | |
4208 * ":dis" and ":registers": Display the contents of the yank registers. | |
4209 */ | |
4210 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4211 ex_display(exarg_T *eap) |
7 | 4212 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4213 int i, n; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4214 long j; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4215 char_u *p; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4216 yankreg_T *yb; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4217 int name; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4218 int attr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4219 char_u *arg = eap->arg; |
22 | 4220 #ifdef FEAT_MBYTE |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4221 int clen; |
22 | 4222 #else |
4223 # define clen 1 | |
4224 #endif | |
7 | 4225 |
4226 if (arg != NULL && *arg == NUL) | |
4227 arg = NULL; | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11131
diff
changeset
|
4228 attr = HL_ATTR(HLF_8); |
7 | 4229 |
4230 /* Highlight title */ | |
4231 MSG_PUTS_TITLE(_("\n--- Registers ---")); | |
4232 for (i = -1; i < NUM_REGISTERS && !got_int; ++i) | |
4233 { | |
4234 name = get_register_name(i); | |
2644 | 4235 if (arg != NULL && vim_strchr(arg, name) == NULL |
4236 #ifdef ONE_CLIPBOARD | |
4237 /* Star register and plus register contain the same thing. */ | |
4238 && (name != '*' || vim_strchr(arg, '+') == NULL) | |
4239 #endif | |
4240 ) | |
7 | 4241 continue; /* did not ask for this register */ |
4242 | |
4243 #ifdef FEAT_CLIPBOARD | |
4244 /* Adjust register name for "unnamed" in 'clipboard'. | |
4245 * When it's a clipboard register, fill it with the current contents | |
4246 * of the clipboard. */ | |
4247 adjust_clip_reg(&name); | |
4248 (void)may_get_selection(name); | |
4249 #endif | |
4250 | |
4251 if (i == -1) | |
4252 { | |
4253 if (y_previous != NULL) | |
4254 yb = y_previous; | |
4255 else | |
4256 yb = &(y_regs[0]); | |
4257 } | |
4258 else | |
4259 yb = &(y_regs[i]); | |
2000 | 4260 |
4261 #ifdef FEAT_EVAL | |
4262 if (name == MB_TOLOWER(redir_reg) | |
4263 || (redir_reg == '"' && yb == y_previous)) | |
4264 continue; /* do not list register being written to, the | |
4265 * pointer can be freed */ | |
4266 #endif | |
4267 | |
7 | 4268 if (yb->y_array != NULL) |
4269 { | |
4270 msg_putchar('\n'); | |
4271 msg_putchar('"'); | |
4272 msg_putchar(name); | |
4273 MSG_PUTS(" "); | |
4274 | |
4275 n = (int)Columns - 6; | |
4276 for (j = 0; j < yb->y_size && n > 1; ++j) | |
4277 { | |
4278 if (j) | |
4279 { | |
4280 MSG_PUTS_ATTR("^J", attr); | |
4281 n -= 2; | |
4282 } | |
4283 for (p = yb->y_array[j]; *p && (n -= ptr2cells(p)) >= 0; ++p) | |
4284 { | |
4285 #ifdef FEAT_MBYTE | |
474 | 4286 clen = (*mb_ptr2len)(p); |
22 | 4287 #endif |
4288 msg_outtrans_len(p, clen); | |
4289 #ifdef FEAT_MBYTE | |
4290 p += clen - 1; | |
7 | 4291 #endif |
4292 } | |
4293 } | |
4294 if (n > 1 && yb->y_type == MLINE) | |
4295 MSG_PUTS_ATTR("^J", attr); | |
4296 out_flush(); /* show one line at a time */ | |
4297 } | |
4298 ui_breakcheck(); | |
4299 } | |
4300 | |
4301 /* | |
4302 * display last inserted text | |
4303 */ | |
4304 if ((p = get_last_insert()) != NULL | |
4305 && (arg == NULL || vim_strchr(arg, '.') != NULL) && !got_int) | |
4306 { | |
4307 MSG_PUTS("\n\". "); | |
4308 dis_msg(p, TRUE); | |
4309 } | |
4310 | |
4311 /* | |
4312 * display last command line | |
4313 */ | |
4314 if (last_cmdline != NULL && (arg == NULL || vim_strchr(arg, ':') != NULL) | |
4315 && !got_int) | |
4316 { | |
4317 MSG_PUTS("\n\": "); | |
4318 dis_msg(last_cmdline, FALSE); | |
4319 } | |
4320 | |
4321 /* | |
4322 * display current file name | |
4323 */ | |
4324 if (curbuf->b_fname != NULL | |
4325 && (arg == NULL || vim_strchr(arg, '%') != NULL) && !got_int) | |
4326 { | |
4327 MSG_PUTS("\n\"% "); | |
4328 dis_msg(curbuf->b_fname, FALSE); | |
4329 } | |
4330 | |
4331 /* | |
4332 * display alternate file name | |
4333 */ | |
4334 if ((arg == NULL || vim_strchr(arg, '%') != NULL) && !got_int) | |
4335 { | |
4336 char_u *fname; | |
4337 linenr_T dummy; | |
4338 | |
4339 if (buflist_name_nr(0, &fname, &dummy) != FAIL) | |
4340 { | |
4341 MSG_PUTS("\n\"# "); | |
4342 dis_msg(fname, FALSE); | |
4343 } | |
4344 } | |
4345 | |
4346 /* | |
4347 * display last search pattern | |
4348 */ | |
4349 if (last_search_pat() != NULL | |
4350 && (arg == NULL || vim_strchr(arg, '/') != NULL) && !got_int) | |
4351 { | |
4352 MSG_PUTS("\n\"/ "); | |
4353 dis_msg(last_search_pat(), FALSE); | |
4354 } | |
4355 | |
4356 #ifdef FEAT_EVAL | |
4357 /* | |
4358 * display last used expression | |
4359 */ | |
4360 if (expr_line != NULL && (arg == NULL || vim_strchr(arg, '=') != NULL) | |
4361 && !got_int) | |
4362 { | |
4363 MSG_PUTS("\n\"= "); | |
4364 dis_msg(expr_line, FALSE); | |
4365 } | |
4366 #endif | |
4367 } | |
4368 | |
4369 /* | |
4370 * display a string for do_dis() | |
4371 * truncate at end of screen line | |
4372 */ | |
4373 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4374 dis_msg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4375 char_u *p, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4376 int skip_esc) /* if TRUE, ignore trailing ESC */ |
7 | 4377 { |
4378 int n; | |
4379 #ifdef FEAT_MBYTE | |
4380 int l; | |
4381 #endif | |
4382 | |
4383 n = (int)Columns - 6; | |
4384 while (*p != NUL | |
4385 && !(*p == ESC && skip_esc && *(p + 1) == NUL) | |
4386 && (n -= ptr2cells(p)) >= 0) | |
4387 { | |
4388 #ifdef FEAT_MBYTE | |
474 | 4389 if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) |
7 | 4390 { |
4391 msg_outtrans_len(p, l); | |
4392 p += l; | |
4393 } | |
4394 else | |
4395 #endif | |
4396 msg_outtrans_len(p++, 1); | |
4397 } | |
4398 ui_breakcheck(); | |
4399 } | |
4400 | |
3562 | 4401 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4402 /* | |
4403 * If "process" is TRUE and the line begins with a comment leader (possibly | |
4404 * after some white space), return a pointer to the text after it. Put a boolean | |
4405 * value indicating whether the line ends with an unclosed comment in | |
4406 * "is_comment". | |
4407 * line - line to be processed, | |
4408 * process - if FALSE, will only check whether the line ends with an unclosed | |
3584 | 4409 * comment, |
3562 | 4410 * include_space - whether to also skip space following the comment leader, |
4411 * is_comment - will indicate whether the current line ends with an unclosed | |
3584 | 4412 * comment. |
3562 | 4413 */ |
11131
8d9ecf09183a
patch 8.0.0453: adding fold marker creates new comment
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4414 char_u * |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4415 skip_comment( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4416 char_u *line, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4417 int process, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4418 int include_space, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4419 int *is_comment) |
3562 | 4420 { |
4421 char_u *comment_flags = NULL; | |
4422 int lead_len; | |
4423 int leader_offset = get_last_leader_offset(line, &comment_flags); | |
4424 | |
4425 *is_comment = FALSE; | |
4426 if (leader_offset != -1) | |
4427 { | |
4428 /* Let's check whether the line ends with an unclosed comment. | |
4429 * If the last comment leader has COM_END in flags, there's no comment. | |
4430 */ | |
4431 while (*comment_flags) | |
4432 { | |
4433 if (*comment_flags == COM_END | |
4434 || *comment_flags == ':') | |
4435 break; | |
4436 ++comment_flags; | |
4437 } | |
4438 if (*comment_flags != COM_END) | |
4439 *is_comment = TRUE; | |
4440 } | |
4441 | |
4442 if (process == FALSE) | |
4443 return line; | |
4444 | |
4445 lead_len = get_leader_len(line, &comment_flags, FALSE, include_space); | |
4446 | |
4447 if (lead_len == 0) | |
4448 return line; | |
4449 | |
4450 /* Find: | |
4451 * - COM_END, | |
4452 * - colon, | |
4453 * whichever comes first. | |
4454 */ | |
4455 while (*comment_flags) | |
4456 { | |
3580 | 4457 if (*comment_flags == COM_END |
3562 | 4458 || *comment_flags == ':') |
4459 { | |
4460 break; | |
4461 } | |
4462 ++comment_flags; | |
4463 } | |
4464 | |
4465 /* If we found a colon, it means that we are not processing a line | |
3580 | 4466 * starting with a closing part of a three-part comment. That's good, |
4467 * because we don't want to remove those as this would be annoying. | |
3562 | 4468 */ |
4469 if (*comment_flags == ':' || *comment_flags == NUL) | |
4470 line += lead_len; | |
4471 | |
4472 return line; | |
4473 } | |
4474 #endif | |
4475 | |
7 | 4476 /* |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4477 * 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
|
4478 * When "save_undo" is TRUE save lines for undo first. |
5848 | 4479 * Set "use_formatoptions" to FALSE when e.g. processing backspace and comment |
4480 * leaders should not be removed. | |
4481 * When setmark is TRUE, sets the '[ and '] mark, else, the caller is expected | |
4482 * to set those marks. | |
7 | 4483 * |
1217 | 4484 * return FAIL for failure, OK otherwise |
7 | 4485 */ |
4486 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4487 do_join( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4488 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4489 int insert_space, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4490 int save_undo, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4491 int use_formatoptions UNUSED, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4492 int setmark) |
7 | 4493 { |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4494 char_u *curr = NULL; |
2597 | 4495 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
|
4496 char_u *cend; |
7 | 4497 char_u *newp; |
2597 | 4498 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
|
4499 int endcurr1 = NUL; |
3e4574a4b627
Fix a few compiler warnings.
Bram Moolenaar <bram@vim.org>
parents:
2298
diff
changeset
|
4500 int endcurr2 = NUL; |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4501 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
|
4502 int sumsize = 0; /* size of the long new line */ |
7 | 4503 linenr_T t; |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4504 colnr_T col = 0; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4505 int ret = OK; |
3562 | 4506 #if defined(FEAT_COMMENTS) || defined(PROTO) |
3574 | 4507 int *comments = NULL; |
3562 | 4508 int remove_comments = (use_formatoptions == TRUE) |
4509 && has_format_option(FO_REMOVE_COMS); | |
4510 int prev_was_comment; | |
4511 #endif | |
4512 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4513 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4514 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
|
4515 (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
|
4516 return FAIL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4517 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4518 /* 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
|
4519 * 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
|
4520 * 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
|
4521 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
|
4522 if (spaces == NULL) |
7 | 4523 return FAIL; |
3562 | 4524 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4525 if (remove_comments) | |
4526 { | |
4527 comments = (int *)lalloc_clear((long_u)count * sizeof(int), TRUE); | |
4528 if (comments == NULL) | |
4529 { | |
4530 vim_free(spaces); | |
4531 return FAIL; | |
4532 } | |
4533 } | |
4534 #endif | |
7 | 4535 |
4536 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4537 * 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
|
4538 * and setup the array of space strings lengths |
7 | 4539 */ |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4540 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
|
4541 { |
2597 | 4542 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t)); |
5848 | 4543 if (t == 0 && setmark) |
5664 | 4544 { |
4545 /* Set the '[ mark. */ | |
4546 curwin->w_buffer->b_op_start.lnum = curwin->w_cursor.lnum; | |
4547 curwin->w_buffer->b_op_start.col = (colnr_T)STRLEN(curr); | |
4548 } | |
3562 | 4549 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4550 if (remove_comments) | |
4551 { | |
4552 /* We don't want to remove the comment leader if the | |
4553 * previous line is not a comment. */ | |
4554 if (t > 0 && prev_was_comment) | |
4555 { | |
4556 | |
4557 char_u *new_curr = skip_comment(curr, TRUE, insert_space, | |
4558 &prev_was_comment); | |
3576 | 4559 comments[t] = (int)(new_curr - curr); |
3562 | 4560 curr = new_curr; |
4561 } | |
4562 else | |
4563 curr = skip_comment(curr, FALSE, insert_space, | |
4564 &prev_was_comment); | |
4565 } | |
4566 #endif | |
4567 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4568 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
|
4569 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4570 curr = skipwhite(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4571 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
|
4572 #ifdef FEAT_MBYTE |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4573 && (!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
|
4574 || (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
|
4575 && (!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
|
4576 || 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
|
4577 #endif |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4578 ) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4579 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4580 /* 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
|
4581 if (endcurr1 == ' ') |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4582 endcurr1 = endcurr2; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4583 else |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4584 ++spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4585 /* 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
|
4586 if ( p_js |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4587 && (endcurr1 == '.' |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4588 || (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
|
4589 && (endcurr1 == '?' || endcurr1 == '!')))) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4590 ++spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4591 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4592 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4593 currsize = (int)STRLEN(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4594 sumsize += currsize + spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4595 endcurr1 = endcurr2 = NUL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4596 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
|
4597 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4598 #ifdef FEAT_MBYTE |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4599 if (has_mbyte) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4600 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4601 cend = curr + currsize; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4602 MB_PTR_BACK(curr, cend); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4603 endcurr1 = (*mb_ptr2char)(cend); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4604 if (cend > curr) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4605 { |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4606 MB_PTR_BACK(curr, cend); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4607 endcurr2 = (*mb_ptr2char)(cend); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4608 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4609 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4610 else |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4611 #endif |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4612 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4613 endcurr1 = *(curr + currsize - 1); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4614 if (currsize > 1) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4615 endcurr2 = *(curr + currsize - 2); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4616 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4617 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4618 line_breakcheck(); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4619 if (got_int) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4620 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4621 ret = FAIL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4622 goto theend; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4623 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4624 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4625 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4626 /* 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
|
4627 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
|
4628 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4629 /* 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
|
4630 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
|
4631 cend = newp + sumsize; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4632 *cend = 0; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4633 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4634 /* |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4635 * 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
|
4636 * |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4637 * 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
|
4638 * 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
|
4639 * 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
|
4640 */ |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4641 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
|
4642 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4643 cend -= currsize; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4644 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
|
4645 if (spaces[t] > 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4646 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4647 cend -= spaces[t]; |
6929 | 4648 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
|
4649 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4650 mark_col_adjust(curwin->w_cursor.lnum + t, (colnr_T)0, (linenr_T)-t, |
2597 | 4651 (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
|
4652 if (t == 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4653 break; |
2597 | 4654 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t - 1)); |
3562 | 4655 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4656 if (remove_comments) | |
4657 curr += comments[t - 1]; | |
4658 #endif | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4659 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
|
4660 curr = skipwhite(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4661 currsize = (int)STRLEN(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4662 } |
7 | 4663 ml_replace(curwin->w_cursor.lnum, newp, FALSE); |
4664 | |
5848 | 4665 if (setmark) |
4666 { | |
4667 /* Set the '] mark. */ | |
4668 curwin->w_buffer->b_op_end.lnum = curwin->w_cursor.lnum; | |
4669 curwin->w_buffer->b_op_end.col = (colnr_T)STRLEN(newp); | |
4670 } | |
5664 | 4671 |
7 | 4672 /* Only report the change in the first line here, del_lines() will report |
4673 * the deleted line. */ | |
4674 changed_lines(curwin->w_cursor.lnum, currsize, | |
4675 curwin->w_cursor.lnum + 1, 0L); | |
4676 | |
4677 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4678 * Delete following lines. To do this we move the cursor there |
7 | 4679 * briefly, and then move it back. After del_lines() the cursor may |
4680 * have moved up (last line deleted), so the current lnum is kept in t. | |
4681 */ | |
4682 t = curwin->w_cursor.lnum; | |
4683 ++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
|
4684 del_lines(count - 1, FALSE); |
7 | 4685 curwin->w_cursor.lnum = t; |
4686 | |
4687 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4688 * Set the cursor column: |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4689 * 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
|
4690 * vim: use the column of the last join |
7 | 4691 */ |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4692 curwin->w_cursor.col = |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4693 (vim_strchr(p_cpo, CPO_JOINCOL) != NULL ? currsize : col); |
7 | 4694 check_cursor_col(); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4695 |
7 | 4696 #ifdef FEAT_VIRTUALEDIT |
4697 curwin->w_cursor.coladd = 0; | |
4698 #endif | |
4699 curwin->w_set_curswant = TRUE; | |
4700 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4701 theend: |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4702 vim_free(spaces); |
3562 | 4703 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4704 if (remove_comments) | |
4705 vim_free(comments); | |
4706 #endif | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4707 return ret; |
7 | 4708 } |
4709 | |
4710 #ifdef FEAT_COMMENTS | |
4711 /* | |
4712 * Return TRUE if the two comment leaders given are the same. "lnum" is | |
4713 * the first line. White-space is ignored. Note that the whole of | |
4714 * 'leader1' must match 'leader2_len' characters from 'leader2' -- webb | |
4715 */ | |
4716 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4717 same_leader( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4718 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4719 int leader1_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4720 char_u *leader1_flags, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4721 int leader2_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4722 char_u *leader2_flags) |
7 | 4723 { |
4724 int idx1 = 0, idx2 = 0; | |
4725 char_u *p; | |
4726 char_u *line1; | |
4727 char_u *line2; | |
4728 | |
4729 if (leader1_len == 0) | |
4730 return (leader2_len == 0); | |
4731 | |
4732 /* | |
4733 * If first leader has 'f' flag, the lines can be joined only if the | |
4734 * second line does not have a leader. | |
4735 * If first leader has 'e' flag, the lines can never be joined. | |
4736 * If fist leader has 's' flag, the lines can only be joined if there is | |
4737 * some text after it and the second line has the 'm' flag. | |
4738 */ | |
4739 if (leader1_flags != NULL) | |
4740 { | |
4741 for (p = leader1_flags; *p && *p != ':'; ++p) | |
4742 { | |
4743 if (*p == COM_FIRST) | |
4744 return (leader2_len == 0); | |
4745 if (*p == COM_END) | |
4746 return FALSE; | |
4747 if (*p == COM_START) | |
4748 { | |
4749 if (*(ml_get(lnum) + leader1_len) == NUL) | |
4750 return FALSE; | |
4751 if (leader2_flags == NULL || leader2_len == 0) | |
4752 return FALSE; | |
4753 for (p = leader2_flags; *p && *p != ':'; ++p) | |
4754 if (*p == COM_MIDDLE) | |
4755 return TRUE; | |
4756 return FALSE; | |
4757 } | |
4758 } | |
4759 } | |
4760 | |
4761 /* | |
4762 * Get current line and next line, compare the leaders. | |
4763 * The first line has to be saved, only one line can be locked at a time. | |
4764 */ | |
4765 line1 = vim_strsave(ml_get(lnum)); | |
4766 if (line1 != NULL) | |
4767 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4768 for (idx1 = 0; VIM_ISWHITE(line1[idx1]); ++idx1) |
7 | 4769 ; |
4770 line2 = ml_get(lnum + 1); | |
4771 for (idx2 = 0; idx2 < leader2_len; ++idx2) | |
4772 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4773 if (!VIM_ISWHITE(line2[idx2])) |
7 | 4774 { |
4775 if (line1[idx1++] != line2[idx2]) | |
4776 break; | |
4777 } | |
4778 else | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4779 while (VIM_ISWHITE(line1[idx1])) |
7 | 4780 ++idx1; |
4781 } | |
4782 vim_free(line1); | |
4783 } | |
4784 return (idx2 == leader2_len && idx1 == leader1_len); | |
4785 } | |
4786 #endif | |
4787 | |
4788 /* | |
3252 | 4789 * Implementation of the format operator 'gq'. |
7 | 4790 */ |
4791 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4792 op_format( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4793 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4794 int keep_cursor) /* keep cursor on same text char */ |
7 | 4795 { |
4796 long old_line_count = curbuf->b_ml.ml_line_count; | |
4797 | |
4798 /* Place the cursor where the "gq" or "gw" command was given, so that "u" | |
4799 * can put it back there. */ | |
4800 curwin->w_cursor = oap->cursor_start; | |
4801 | |
4802 if (u_save((linenr_T)(oap->start.lnum - 1), | |
4803 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
4804 return; | |
4805 curwin->w_cursor = oap->start; | |
4806 | |
4807 if (oap->is_VIsual) | |
4808 /* When there is no change: need to remove the Visual selection */ | |
4809 redraw_curbuf_later(INVERTED); | |
4810 | |
4811 /* Set '[ mark at the start of the formatted area */ | |
4812 curbuf->b_op_start = oap->start; | |
4813 | |
4814 /* For "gw" remember the cursor position and put it back below (adjusted | |
4815 * for joined and split lines). */ | |
4816 if (keep_cursor) | |
4817 saved_cursor = oap->cursor_start; | |
4818 | |
1563 | 4819 format_lines(oap->line_count, keep_cursor); |
7 | 4820 |
4821 /* | |
4822 * Leave the cursor at the first non-blank of the last formatted line. | |
4823 * If the cursor was moved one line back (e.g. with "Q}") go to the next | |
4824 * line, so "." will do the next lines. | |
4825 */ | |
4826 if (oap->end_adjusted && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
4827 ++curwin->w_cursor.lnum; | |
4828 beginline(BL_WHITE | BL_FIX); | |
4829 old_line_count = curbuf->b_ml.ml_line_count - old_line_count; | |
4830 msgmore(old_line_count); | |
4831 | |
4832 /* put '] mark on the end of the formatted area */ | |
4833 curbuf->b_op_end = curwin->w_cursor; | |
4834 | |
4835 if (keep_cursor) | |
4836 { | |
4837 curwin->w_cursor = saved_cursor; | |
4838 saved_cursor.lnum = 0; | |
4839 } | |
4840 | |
4841 if (oap->is_VIsual) | |
4842 { | |
4843 win_T *wp; | |
4844 | |
4845 FOR_ALL_WINDOWS(wp) | |
4846 { | |
4847 if (wp->w_old_cursor_lnum != 0) | |
4848 { | |
4849 /* When lines have been inserted or deleted, adjust the end of | |
4850 * the Visual area to be redrawn. */ | |
4851 if (wp->w_old_cursor_lnum > wp->w_old_visual_lnum) | |
4852 wp->w_old_cursor_lnum += old_line_count; | |
4853 else | |
4854 wp->w_old_visual_lnum += old_line_count; | |
4855 } | |
4856 } | |
4857 } | |
4858 } | |
4859 | |
667 | 4860 #if defined(FEAT_EVAL) || defined(PROTO) |
4861 /* | |
4862 * Implementation of the format operator 'gq' for when using 'formatexpr'. | |
4863 */ | |
4864 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4865 op_formatexpr(oparg_T *oap) |
667 | 4866 { |
4867 if (oap->is_VIsual) | |
4868 /* When there is no change: need to remove the Visual selection */ | |
4869 redraw_curbuf_later(INVERTED); | |
4870 | |
2298
a3562a127cf6
When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
4871 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
|
4872 /* 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
|
4873 * internal formatting. */ |
a3562a127cf6
When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
4874 op_format(oap, FALSE); |
667 | 4875 } |
4876 | |
4877 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4878 fex_format( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4879 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4880 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4881 int c) /* character to be inserted */ |
667 | 4882 { |
681 | 4883 int use_sandbox = was_set_insecurely((char_u *)"formatexpr", |
4884 OPT_LOCAL); | |
667 | 4885 int r; |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4886 char_u *fex; |
667 | 4887 |
4888 /* | |
4889 * Set v:lnum to the first line number and v:count to the number of lines. | |
844 | 4890 * Set v:char to the character to be inserted (can be NUL). |
667 | 4891 */ |
4892 set_vim_var_nr(VV_LNUM, lnum); | |
4893 set_vim_var_nr(VV_COUNT, count); | |
1969 | 4894 set_vim_var_char(c); |
844 | 4895 |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4896 /* Make a copy, the option could be changed while calling it. */ |
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4897 fex = vim_strsave(curbuf->b_p_fex); |
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4898 if (fex == NULL) |
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4899 return 0; |
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4900 |
667 | 4901 /* |
4902 * Evaluate the function. | |
4903 */ | |
4904 if (use_sandbox) | |
4905 ++sandbox; | |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4906 r = (int)eval_to_number(fex); |
667 | 4907 if (use_sandbox) |
4908 --sandbox; | |
844 | 4909 |
4910 set_vim_var_string(VV_CHAR, NULL, -1); | |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4911 vim_free(fex); |
844 | 4912 |
667 | 4913 return r; |
4914 } | |
4915 #endif | |
4916 | |
7 | 4917 /* |
4918 * Format "line_count" lines, starting at the cursor position. | |
4919 * When "line_count" is negative, format until the end of the paragraph. | |
4920 * Lines after the cursor line are saved for undo, caller must have saved the | |
4921 * first line. | |
4922 */ | |
4923 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4924 format_lines( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4925 linenr_T line_count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4926 int avoid_fex) /* don't use 'formatexpr' */ |
7 | 4927 { |
4928 int max_len; | |
4929 int is_not_par; /* current line not part of parag. */ | |
4930 int next_is_not_par; /* next line not part of paragraph */ | |
4931 int is_end_par; /* at end of paragraph */ | |
4932 int prev_is_end_par = FALSE;/* prev. line not part of parag. */ | |
4933 int next_is_start_par = FALSE; | |
4934 #ifdef FEAT_COMMENTS | |
4935 int leader_len = 0; /* leader len of current line */ | |
4936 int next_leader_len; /* leader len of next line */ | |
4937 char_u *leader_flags = NULL; /* flags for leader of current line */ | |
4938 char_u *next_leader_flags; /* flags for leader of next line */ | |
4939 int do_comments; /* format comments */ | |
3584 | 4940 int do_comments_list = 0; /* format comments with 'n' or '2' */ |
7 | 4941 #endif |
4942 int advance = TRUE; | |
3584 | 4943 int second_indent = -1; /* indent for second line (comment |
4944 * aware) */ | |
7 | 4945 int do_second_indent; |
4946 int do_number_indent; | |
4947 int do_trail_white; | |
4948 int first_par_line = TRUE; | |
4949 int smd_save; | |
4950 long count; | |
4951 int need_set_indent = TRUE; /* set indent of next paragraph */ | |
4952 int force_format = FALSE; | |
4953 int old_State = State; | |
4954 | |
4955 /* length of a line to force formatting: 3 * 'tw' */ | |
4956 max_len = comp_textwidth(TRUE) * 3; | |
4957 | |
4958 /* check for 'q', '2' and '1' in 'formatoptions' */ | |
4959 #ifdef FEAT_COMMENTS | |
4960 do_comments = has_format_option(FO_Q_COMS); | |
4961 #endif | |
4962 do_second_indent = has_format_option(FO_Q_SECOND); | |
4963 do_number_indent = has_format_option(FO_Q_NUMBER); | |
4964 do_trail_white = has_format_option(FO_WHITE_PAR); | |
4965 | |
4966 /* | |
4967 * Get info about the previous and current line. | |
4968 */ | |
4969 if (curwin->w_cursor.lnum > 1) | |
4970 is_not_par = fmt_check_par(curwin->w_cursor.lnum - 1 | |
4971 #ifdef FEAT_COMMENTS | |
4972 , &leader_len, &leader_flags, do_comments | |
4973 #endif | |
4974 ); | |
4975 else | |
4976 is_not_par = TRUE; | |
4977 next_is_not_par = fmt_check_par(curwin->w_cursor.lnum | |
4978 #ifdef FEAT_COMMENTS | |
4979 , &next_leader_len, &next_leader_flags, do_comments | |
4980 #endif | |
4981 ); | |
4982 is_end_par = (is_not_par || next_is_not_par); | |
4983 if (!is_end_par && do_trail_white) | |
4984 is_end_par = !ends_in_white(curwin->w_cursor.lnum - 1); | |
4985 | |
4986 curwin->w_cursor.lnum--; | |
4987 for (count = line_count; count != 0 && !got_int; --count) | |
4988 { | |
4989 /* | |
4990 * Advance to next paragraph. | |
4991 */ | |
4992 if (advance) | |
4993 { | |
4994 curwin->w_cursor.lnum++; | |
4995 prev_is_end_par = is_end_par; | |
4996 is_not_par = next_is_not_par; | |
4997 #ifdef FEAT_COMMENTS | |
4998 leader_len = next_leader_len; | |
4999 leader_flags = next_leader_flags; | |
5000 #endif | |
5001 } | |
5002 | |
5003 /* | |
5004 * The last line to be formatted. | |
5005 */ | |
5006 if (count == 1 || curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) | |
5007 { | |
5008 next_is_not_par = TRUE; | |
5009 #ifdef FEAT_COMMENTS | |
5010 next_leader_len = 0; | |
5011 next_leader_flags = NULL; | |
5012 #endif | |
5013 } | |
5014 else | |
5015 { | |
5016 next_is_not_par = fmt_check_par(curwin->w_cursor.lnum + 1 | |
5017 #ifdef FEAT_COMMENTS | |
5018 , &next_leader_len, &next_leader_flags, do_comments | |
5019 #endif | |
5020 ); | |
5021 if (do_number_indent) | |
5022 next_is_start_par = | |
5023 (get_number_indent(curwin->w_cursor.lnum + 1) > 0); | |
5024 } | |
5025 advance = TRUE; | |
5026 is_end_par = (is_not_par || next_is_not_par || next_is_start_par); | |
5027 if (!is_end_par && do_trail_white) | |
5028 is_end_par = !ends_in_white(curwin->w_cursor.lnum); | |
5029 | |
5030 /* | |
5031 * Skip lines that are not in a paragraph. | |
5032 */ | |
5033 if (is_not_par) | |
5034 { | |
5035 if (line_count < 0) | |
5036 break; | |
5037 } | |
5038 else | |
5039 { | |
5040 /* | |
5041 * For the first line of a paragraph, check indent of second line. | |
5042 * Don't do this for comments and empty lines. | |
5043 */ | |
5044 if (first_par_line | |
5045 && (do_second_indent || do_number_indent) | |
5046 && prev_is_end_par | |
3584 | 5047 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) |
5048 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
5049 if (do_second_indent && !LINEEMPTY(curwin->w_cursor.lnum + 1)) |
3584 | 5050 { |
5051 #ifdef FEAT_COMMENTS | |
5052 if (leader_len == 0 && next_leader_len == 0) | |
5053 { | |
5054 /* no comment found */ | |
5055 #endif | |
5056 second_indent = | |
5057 get_indent_lnum(curwin->w_cursor.lnum + 1); | |
7 | 5058 #ifdef FEAT_COMMENTS |
3584 | 5059 } |
5060 else | |
5061 { | |
5062 second_indent = next_leader_len; | |
5063 do_comments_list = 1; | |
5064 } | |
5065 #endif | |
5066 } | |
7 | 5067 else if (do_number_indent) |
3584 | 5068 { |
5069 #ifdef FEAT_COMMENTS | |
5070 if (leader_len == 0 && next_leader_len == 0) | |
5071 { | |
5072 /* no comment found */ | |
5073 #endif | |
5074 second_indent = | |
5075 get_number_indent(curwin->w_cursor.lnum); | |
5076 #ifdef FEAT_COMMENTS | |
5077 } | |
5078 else | |
5079 { | |
5080 /* get_number_indent() is now "comment aware"... */ | |
5081 second_indent = | |
5082 get_number_indent(curwin->w_cursor.lnum); | |
5083 do_comments_list = 1; | |
5084 } | |
5085 #endif | |
5086 } | |
7 | 5087 } |
5088 | |
5089 /* | |
5090 * When the comment leader changes, it's the end of the paragraph. | |
5091 */ | |
5092 if (curwin->w_cursor.lnum >= curbuf->b_ml.ml_line_count | |
5093 #ifdef FEAT_COMMENTS | |
5094 || !same_leader(curwin->w_cursor.lnum, | |
5095 leader_len, leader_flags, | |
5096 next_leader_len, next_leader_flags) | |
5097 #endif | |
5098 ) | |
5099 is_end_par = TRUE; | |
5100 | |
5101 /* | |
5102 * If we have got to the end of a paragraph, or the line is | |
5103 * getting long, format it. | |
5104 */ | |
5105 if (is_end_par || force_format) | |
5106 { | |
5107 if (need_set_indent) | |
5108 /* replace indent in first line with minimal number of | |
5109 * tabs and spaces, according to current options */ | |
5110 (void)set_indent(get_indent(), SIN_CHANGED); | |
5111 | |
5112 /* put cursor on last non-space */ | |
5113 State = NORMAL; /* don't go past end-of-line */ | |
5114 coladvance((colnr_T)MAXCOL); | |
5115 while (curwin->w_cursor.col && vim_isspace(gchar_cursor())) | |
5116 dec_cursor(); | |
5117 | |
5118 /* do the formatting, without 'showmode' */ | |
5119 State = INSERT; /* for open_line() */ | |
5120 smd_save = p_smd; | |
5121 p_smd = FALSE; | |
5122 insertchar(NUL, INSCHAR_FORMAT | |
5123 #ifdef FEAT_COMMENTS | |
5124 + (do_comments ? INSCHAR_DO_COM : 0) | |
3584 | 5125 + (do_comments && do_comments_list |
5126 ? INSCHAR_COM_LIST : 0) | |
7 | 5127 #endif |
1563 | 5128 + (avoid_fex ? INSCHAR_NO_FEX : 0), second_indent); |
7 | 5129 State = old_State; |
5130 p_smd = smd_save; | |
5131 second_indent = -1; | |
5132 /* at end of par.: need to set indent of next par. */ | |
5133 need_set_indent = is_end_par; | |
5134 if (is_end_par) | |
5135 { | |
5136 /* When called with a negative line count, break at the | |
5137 * end of the paragraph. */ | |
5138 if (line_count < 0) | |
5139 break; | |
5140 first_par_line = TRUE; | |
5141 } | |
5142 force_format = FALSE; | |
5143 } | |
5144 | |
5145 /* | |
5146 * When still in same paragraph, join the lines together. But | |
5403 | 5147 * first delete the leader from the second line. |
7 | 5148 */ |
5149 if (!is_end_par) | |
5150 { | |
5151 advance = FALSE; | |
5152 curwin->w_cursor.lnum++; | |
5153 curwin->w_cursor.col = 0; | |
5154 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
|
5155 break; |
7 | 5156 #ifdef FEAT_COMMENTS |
5157 if (next_leader_len > 0) | |
5403 | 5158 { |
5159 (void)del_bytes((long)next_leader_len, FALSE, FALSE); | |
7 | 5160 mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L, |
5161 (long)-next_leader_len); | |
5403 | 5162 } else |
5163 #endif | |
5164 if (second_indent > 0) /* the "leader" for FO_Q_SECOND */ | |
5165 { | |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
5166 int indent = getwhitecols_curline(); |
5403 | 5167 |
5168 if (indent > 0) | |
5169 { | |
5170 (void)del_bytes(indent, FALSE, FALSE); | |
5171 mark_col_adjust(curwin->w_cursor.lnum, | |
5172 (colnr_T)0, 0L, (long)-indent); | |
5415 | 5173 } |
5403 | 5174 } |
7 | 5175 curwin->w_cursor.lnum--; |
5848 | 5176 if (do_join(2, TRUE, FALSE, FALSE, FALSE) == FAIL) |
7 | 5177 { |
5178 beep_flush(); | |
5179 break; | |
5180 } | |
5181 first_par_line = FALSE; | |
5182 /* If the line is getting long, format it next time */ | |
5183 if (STRLEN(ml_get_curline()) > (size_t)max_len) | |
5184 force_format = TRUE; | |
5185 else | |
5186 force_format = FALSE; | |
5187 } | |
5188 } | |
5189 line_breakcheck(); | |
5190 } | |
5191 } | |
5192 | |
5193 /* | |
5194 * Return TRUE if line "lnum" ends in a white character. | |
5195 */ | |
5196 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5197 ends_in_white(linenr_T lnum) |
7 | 5198 { |
5199 char_u *s = ml_get(lnum); | |
5200 size_t l; | |
5201 | |
5202 if (*s == NUL) | |
5203 return FALSE; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5204 /* Don't use STRLEN() inside VIM_ISWHITE(), SAS/C complains: "macro |
7 | 5205 * invocation may call function multiple times". */ |
5206 l = STRLEN(s) - 1; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5207 return VIM_ISWHITE(s[l]); |
7 | 5208 } |
5209 | |
5210 /* | |
5211 * Blank lines, and lines containing only the comment leader, are left | |
5212 * untouched by the formatting. The function returns TRUE in this | |
5213 * case. It also returns TRUE when a line starts with the end of a comment | |
5214 * ('e' in comment flags), so that this line is skipped, and not joined to the | |
5215 * previous line. A new paragraph starts after a blank line, or when the | |
5216 * comment leader changes -- webb. | |
5217 */ | |
5218 #ifdef FEAT_COMMENTS | |
5219 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5220 fmt_check_par( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5221 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5222 int *leader_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5223 char_u **leader_flags, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5224 int do_comments) |
7 | 5225 { |
5226 char_u *flags = NULL; /* init for GCC */ | |
5227 char_u *ptr; | |
5228 | |
5229 ptr = ml_get(lnum); | |
5230 if (do_comments) | |
3562 | 5231 *leader_len = get_leader_len(ptr, leader_flags, FALSE, TRUE); |
7 | 5232 else |
5233 *leader_len = 0; | |
5234 | |
5235 if (*leader_len > 0) | |
5236 { | |
5237 /* | |
5238 * Search for 'e' flag in comment leader flags. | |
5239 */ | |
5240 flags = *leader_flags; | |
5241 while (*flags && *flags != ':' && *flags != COM_END) | |
5242 ++flags; | |
5243 } | |
5244 | |
5245 return (*skipwhite(ptr + *leader_len) == NUL | |
5246 || (*leader_len > 0 && *flags == COM_END) | |
5247 || startPS(lnum, NUL, FALSE)); | |
5248 } | |
5249 #else | |
5250 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5251 fmt_check_par(linenr_T lnum) |
7 | 5252 { |
5253 return (*skipwhite(ml_get(lnum)) == NUL || startPS(lnum, NUL, FALSE)); | |
5254 } | |
5255 #endif | |
5256 | |
5257 /* | |
5258 * Return TRUE when a paragraph starts in line "lnum". Return FALSE when the | |
5259 * previous line is in the same paragraph. Used for auto-formatting. | |
5260 */ | |
5261 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5262 paragraph_start(linenr_T lnum) |
7 | 5263 { |
5264 char_u *p; | |
5265 #ifdef FEAT_COMMENTS | |
5266 int leader_len = 0; /* leader len of current line */ | |
5267 char_u *leader_flags = NULL; /* flags for leader of current line */ | |
5268 int next_leader_len; /* leader len of next line */ | |
5269 char_u *next_leader_flags; /* flags for leader of next line */ | |
5270 int do_comments; /* format comments */ | |
5271 #endif | |
5272 | |
5273 if (lnum <= 1) | |
5274 return TRUE; /* start of the file */ | |
5275 | |
5276 p = ml_get(lnum - 1); | |
5277 if (*p == NUL) | |
5278 return TRUE; /* after empty line */ | |
5279 | |
5280 #ifdef FEAT_COMMENTS | |
5281 do_comments = has_format_option(FO_Q_COMS); | |
5282 #endif | |
5283 if (fmt_check_par(lnum - 1 | |
5284 #ifdef FEAT_COMMENTS | |
5285 , &leader_len, &leader_flags, do_comments | |
5286 #endif | |
5287 )) | |
5288 return TRUE; /* after non-paragraph line */ | |
5289 | |
5290 if (fmt_check_par(lnum | |
5291 #ifdef FEAT_COMMENTS | |
5292 , &next_leader_len, &next_leader_flags, do_comments | |
5293 #endif | |
5294 )) | |
5295 return TRUE; /* "lnum" is not a paragraph line */ | |
5296 | |
5297 if (has_format_option(FO_WHITE_PAR) && !ends_in_white(lnum - 1)) | |
5298 return TRUE; /* missing trailing space in previous line. */ | |
5299 | |
5300 if (has_format_option(FO_Q_NUMBER) && (get_number_indent(lnum) > 0)) | |
5301 return TRUE; /* numbered item starts in "lnum". */ | |
5302 | |
5303 #ifdef FEAT_COMMENTS | |
5304 if (!same_leader(lnum - 1, leader_len, leader_flags, | |
5305 next_leader_len, next_leader_flags)) | |
5306 return TRUE; /* change of comment leader. */ | |
5307 #endif | |
5308 | |
5309 return FALSE; | |
5310 } | |
5311 | |
5312 /* | |
5313 * prepare a few things for block mode yank/delete/tilde | |
5314 * | |
5315 * for delete: | |
5316 * - textlen includes the first/last char to be (partly) deleted | |
5317 * - start/endspaces is the number of columns that are taken by the | |
5318 * first/last deleted char minus the number of columns that have to be | |
1839 | 5319 * deleted. |
5320 * for yank and tilde: | |
7 | 5321 * - textlen includes the first/last char to be wholly yanked |
5322 * - start/endspaces is the number of columns of the first/last yanked char | |
5323 * that are to be yanked. | |
5324 */ | |
5325 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5326 block_prep( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5327 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5328 struct block_def *bdp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5329 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5330 int is_del) |
7 | 5331 { |
5332 int incr = 0; | |
5333 char_u *pend; | |
5334 char_u *pstart; | |
5335 char_u *line; | |
5336 char_u *prev_pstart; | |
5337 char_u *prev_pend; | |
5338 | |
5339 bdp->startspaces = 0; | |
5340 bdp->endspaces = 0; | |
5341 bdp->textlen = 0; | |
5342 bdp->start_vcol = 0; | |
5343 bdp->end_vcol = 0; | |
5344 #ifdef FEAT_VISUALEXTRA | |
5345 bdp->is_short = FALSE; | |
5346 bdp->is_oneChar = FALSE; | |
5347 bdp->pre_whitesp = 0; | |
5348 bdp->pre_whitesp_c = 0; | |
5349 bdp->end_char_vcols = 0; | |
5350 #endif | |
5351 bdp->start_char_vcols = 0; | |
5352 | |
5353 line = ml_get(lnum); | |
5354 pstart = line; | |
5355 prev_pstart = line; | |
5356 while (bdp->start_vcol < oap->start_vcol && *pstart) | |
5357 { | |
5358 /* Count a tab for what it's worth (if list mode not on) */ | |
5995 | 5359 incr = lbr_chartabsize(line, pstart, (colnr_T)bdp->start_vcol); |
7 | 5360 bdp->start_vcol += incr; |
5361 #ifdef FEAT_VISUALEXTRA | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5362 if (VIM_ISWHITE(*pstart)) |
7 | 5363 { |
5364 bdp->pre_whitesp += incr; | |
5365 bdp->pre_whitesp_c++; | |
5366 } | |
5367 else | |
5368 { | |
5369 bdp->pre_whitesp = 0; | |
5370 bdp->pre_whitesp_c = 0; | |
5371 } | |
5372 #endif | |
5373 prev_pstart = pstart; | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
5374 MB_PTR_ADV(pstart); |
7 | 5375 } |
5376 bdp->start_char_vcols = incr; | |
5377 if (bdp->start_vcol < oap->start_vcol) /* line too short */ | |
5378 { | |
5379 bdp->end_vcol = bdp->start_vcol; | |
5380 #ifdef FEAT_VISUALEXTRA | |
5381 bdp->is_short = TRUE; | |
5382 #endif | |
5383 if (!is_del || oap->op_type == OP_APPEND) | |
5384 bdp->endspaces = oap->end_vcol - oap->start_vcol + 1; | |
5385 } | |
5386 else | |
5387 { | |
5388 /* notice: this converts partly selected Multibyte characters to | |
5389 * spaces, too. */ | |
5390 bdp->startspaces = bdp->start_vcol - oap->start_vcol; | |
5391 if (is_del && bdp->startspaces) | |
5392 bdp->startspaces = bdp->start_char_vcols - bdp->startspaces; | |
5393 pend = pstart; | |
5394 bdp->end_vcol = bdp->start_vcol; | |
5395 if (bdp->end_vcol > oap->end_vcol) /* it's all in one character */ | |
5396 { | |
5397 #ifdef FEAT_VISUALEXTRA | |
5398 bdp->is_oneChar = TRUE; | |
5399 #endif | |
5400 if (oap->op_type == OP_INSERT) | |
5401 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces; | |
5402 else if (oap->op_type == OP_APPEND) | |
5403 { | |
5404 bdp->startspaces += oap->end_vcol - oap->start_vcol + 1; | |
5405 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces; | |
5406 } | |
5407 else | |
5408 { | |
5409 bdp->startspaces = oap->end_vcol - oap->start_vcol + 1; | |
5410 if (is_del && oap->op_type != OP_LSHIFT) | |
5411 { | |
5412 /* just putting the sum of those two into | |
5413 * bdp->startspaces doesn't work for Visual replace, | |
5414 * so we have to split the tab in two */ | |
5415 bdp->startspaces = bdp->start_char_vcols | |
5416 - (bdp->start_vcol - oap->start_vcol); | |
5417 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; | |
5418 } | |
5419 } | |
5420 } | |
5421 else | |
5422 { | |
5423 prev_pend = pend; | |
5424 while (bdp->end_vcol <= oap->end_vcol && *pend != NUL) | |
5425 { | |
5426 /* Count a tab for what it's worth (if list mode not on) */ | |
5427 prev_pend = pend; | |
6535 | 5428 incr = lbr_chartabsize_adv(line, &pend, (colnr_T)bdp->end_vcol); |
7 | 5429 bdp->end_vcol += incr; |
5430 } | |
5431 if (bdp->end_vcol <= oap->end_vcol | |
5432 && (!is_del | |
5433 || oap->op_type == OP_APPEND | |
5434 || oap->op_type == OP_REPLACE)) /* line too short */ | |
5435 { | |
5436 #ifdef FEAT_VISUALEXTRA | |
5437 bdp->is_short = TRUE; | |
5438 #endif | |
5439 /* Alternative: include spaces to fill up the block. | |
5440 * Disadvantage: can lead to trailing spaces when the line is | |
5441 * short where the text is put */ | |
5442 /* if (!is_del || oap->op_type == OP_APPEND) */ | |
5443 if (oap->op_type == OP_APPEND || virtual_op) | |
5444 bdp->endspaces = oap->end_vcol - bdp->end_vcol | |
593 | 5445 + oap->inclusive; |
7 | 5446 else |
5447 bdp->endspaces = 0; /* replace doesn't add characters */ | |
5448 } | |
5449 else if (bdp->end_vcol > oap->end_vcol) | |
5450 { | |
5451 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; | |
5452 if (!is_del && bdp->endspaces) | |
5453 { | |
5454 bdp->endspaces = incr - bdp->endspaces; | |
5455 if (pend != pstart) | |
5456 pend = prev_pend; | |
5457 } | |
5458 } | |
5459 } | |
5460 #ifdef FEAT_VISUALEXTRA | |
5461 bdp->end_char_vcols = incr; | |
5462 #endif | |
5463 if (is_del && bdp->startspaces) | |
5464 pstart = prev_pstart; | |
5465 bdp->textlen = (int)(pend - pstart); | |
5466 } | |
5467 bdp->textcol = (colnr_T) (pstart - line); | |
5468 bdp->textstart = pstart; | |
5469 } | |
5470 | |
5471 /* | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5472 * Handle the add/subtract operator. |
7 | 5473 */ |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5474 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5475 op_addsub( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5476 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5477 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
|
5478 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
|
5479 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5480 pos_T pos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5481 struct block_def bd; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5482 int change_cnt = 0; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5483 linenr_T amount = Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5484 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5485 if (!VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5486 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5487 pos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5488 if (u_save_cursor() == FAIL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5489 return; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5490 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
|
5491 if (change_cnt) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5492 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
|
5493 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5494 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5495 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5496 int one_change; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5497 int length; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5498 pos_T startpos; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5499 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5500 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
|
5501 (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
|
5502 return; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5503 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5504 pos = oap->start; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5505 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
|
5506 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5507 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
|
5508 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5509 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
|
5510 pos.col = bd.textcol; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5511 length = bd.textlen; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5512 } |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5513 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
|
5514 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5515 curwin->w_cursor.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5516 pos.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5517 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
|
5518 } |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5519 else /* oap->motion_type == MCHAR */ |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5520 { |
12996
973a0037f4c3
patch 8.0.1374: CTRL-A does not work with an empty line
Christian Brabandt <cb@256bit.org>
parents:
12642
diff
changeset
|
5521 if (pos.lnum == oap->start.lnum && !oap->inclusive) |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5522 dec(&(oap->end)); |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5523 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
|
5524 pos.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5525 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
|
5526 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5527 pos.col += oap->start.col; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5528 length -= oap->start.col; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5529 } |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5530 if (pos.lnum == oap->end.lnum) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5531 { |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5532 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
|
5533 if (oap->end.col >= length) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5534 oap->end.col = length - 1; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5535 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
|
5536 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5537 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5538 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
|
5539 if (one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5540 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5541 /* 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
|
5542 if (change_cnt == 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5543 startpos = curbuf->b_op_start; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5544 ++change_cnt; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5545 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5546 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5547 #ifdef FEAT_NETBEANS_INTG |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5548 if (netbeans_active() && one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5549 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5550 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
|
5551 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5552 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
|
5553 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
|
5554 &ptr[pos.col], length); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5555 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5556 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5557 if (g_cmd && one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5558 amount += Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5559 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5560 if (change_cnt) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5561 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
|
5562 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5563 if (!change_cnt && oap->is_VIsual) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5564 /* 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
|
5565 redraw_curbuf_later(INVERTED); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5566 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5567 /* 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
|
5568 * position from do_addsub(). */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5569 if (change_cnt > 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5570 curbuf->b_op_start = startpos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5571 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5572 if (change_cnt > p_report) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5573 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5574 if (change_cnt == 1) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5575 MSG(_("1 line changed")); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5576 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5577 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
|
5578 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5579 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5580 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5581 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5582 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5583 * 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
|
5584 * 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
|
5585 * |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5586 * 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
|
5587 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5588 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5589 do_addsub( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5590 int op_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5591 pos_T *pos, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5592 int length, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5593 linenr_T Prenum1) |
7 | 5594 { |
5595 int col; | |
5596 char_u *buf1; | |
5597 char_u buf2[NUMBUFLEN]; | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5598 int pre; /* 'X'/'x': hex; '0': octal; 'B'/'b': bin */ |
7 | 5599 static int hexupper = FALSE; /* 0xABC */ |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5600 uvarnumber_T n; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5601 uvarnumber_T oldn; |
7 | 5602 char_u *ptr; |
5603 int c; | |
5604 int todel; | |
5605 int dohex; | |
5606 int dooct; | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5607 int dobin; |
7 | 5608 int doalp; |
5609 int firstdigit; | |
5610 int subtract; | |
6868 | 5611 int negative = FALSE; |
6891 | 5612 int was_positive = TRUE; |
6868 | 5613 int visual = VIsual_active; |
6921 | 5614 int did_change = FALSE; |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5615 pos_T save_cursor = curwin->w_cursor; |
6927 | 5616 int maxlen = 0; |
7570
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5617 pos_T startpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5618 pos_T endpos; |
7 | 5619 |
5620 dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); /* "heX" */ | |
5621 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
|
5622 dobin = (vim_strchr(curbuf->b_p_nf, 'b') != NULL); /* "Bin" */ |
7 | 5623 doalp = (vim_strchr(curbuf->b_p_nf, 'p') != NULL); /* "alPha" */ |
5624 | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5625 curwin->w_cursor = *pos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5626 ptr = ml_get(pos->lnum); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5627 col = pos->col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5628 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5629 if (*ptr == NUL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5630 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5631 |
7 | 5632 /* |
5633 * First check if we are on a hexadecimal number, after the "0x". | |
5634 */ | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5635 if (!VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5636 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5637 if (dobin) |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5638 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
|
5639 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5640 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5641 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5642 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5643 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
|
5644 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5645 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5646 |
6868 | 5647 if (dohex) |
5648 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
|
5649 { |
6868 | 5650 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5651 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5652 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5653 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
|
5654 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5655 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5656 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5657 if ( dobin |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5658 && dohex |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5659 && ! ((col > 0 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5660 && (ptr[col] == 'X' |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5661 || ptr[col] == 'x') |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5662 && ptr[col - 1] == '0' |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5663 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5664 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5665 !(*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
|
5666 #endif |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5667 && vim_isxdigit(ptr[col + 1])))) |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5668 { |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5669 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5670 /* 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
|
5671 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5672 col = pos->col; |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5673 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5674 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
|
5675 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5676 col--; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5677 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5678 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5679 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
|
5680 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5681 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5682 } |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5683 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5684 if (( dohex |
6868 | 5685 && col > 0 |
5686 && (ptr[col] == 'X' | |
5687 || ptr[col] == 'x') | |
5688 && ptr[col - 1] == '0' | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5689 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5690 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5691 !(*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
|
5692 #endif |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5693 && vim_isxdigit(ptr[col + 1])) || |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5694 ( dobin |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5695 && col > 0 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5696 && (ptr[col] == 'B' |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5697 || ptr[col] == 'b') |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5698 && ptr[col - 1] == '0' |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5699 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5700 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5701 !(*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
|
5702 #endif |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5703 && vim_isbdigit(ptr[col + 1]))) |
6868 | 5704 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5705 /* Found hexadecimal or binary number, move to its start. */ |
7 | 5706 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5707 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5708 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5709 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
|
5710 #endif |
6868 | 5711 } |
5712 else | |
7 | 5713 { |
6868 | 5714 /* |
5715 * Search forward and then backward to find the start of number. | |
5716 */ | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5717 col = pos->col; |
6868 | 5718 |
5719 while (ptr[col] != NUL | |
5720 && !vim_isdigit(ptr[col]) | |
5721 && !(doalp && ASCII_ISALPHA(ptr[col]))) | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5722 col += MB_PTR2LEN(ptr + col); |
6868 | 5723 |
5724 while (col > 0 | |
5725 && vim_isdigit(ptr[col - 1]) | |
5726 && !(doalp && ASCII_ISALPHA(ptr[col]))) | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5727 { |
6868 | 5728 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5729 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5730 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5731 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
|
5732 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5733 } |
6868 | 5734 } |
5735 } | |
5736 | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5737 if (visual) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5738 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5739 while (ptr[col] != NUL && length > 0 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5740 && !vim_isdigit(ptr[col]) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5741 && !(doalp && ASCII_ISALPHA(ptr[col]))) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5742 { |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5743 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
|
5744 |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5745 col += mb_len; |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5746 length -= mb_len; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5747 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5748 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5749 if (length == 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5750 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5751 |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5752 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
|
5753 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5754 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5755 !(*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
|
5756 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5757 ) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5758 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5759 negative = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5760 was_positive = FALSE; |
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 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5763 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5764 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5765 * 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
|
5766 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5767 firstdigit = ptr[col]; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5768 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
|
5769 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5770 beep_flush(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5771 goto theend; |
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 if (doalp && ASCII_ISALPHA(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5775 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5776 /* decrement or increment alphabetic character */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5777 if (op_type == OP_NR_SUB) |
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 if (CharOrd(firstdigit) < Prenum1) |
6927 | 5780 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5781 if (isupper(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5782 firstdigit = 'A'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5783 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5784 firstdigit = 'a'; |
6927 | 5785 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5786 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5787 #ifdef EBCDIC |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5788 firstdigit = EBCDIC_CHAR_ADD(firstdigit, -Prenum1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5789 #else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5790 firstdigit -= Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5791 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5792 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5793 else |
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 if (26 - CharOrd(firstdigit) - 1 < Prenum1) |
6927 | 5796 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5797 if (isupper(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5798 firstdigit = 'Z'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5799 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5800 firstdigit = 'z'; |
6927 | 5801 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5802 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5803 #ifdef EBCDIC |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5804 firstdigit = EBCDIC_CHAR_ADD(firstdigit, Prenum1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5805 #else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5806 firstdigit += Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5807 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5808 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5809 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5810 if (!did_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5811 startpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5812 did_change = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5813 (void)del_char(FALSE); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5814 ins_char(firstdigit); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5815 endpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5816 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5817 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5818 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5819 { |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5820 if (col > 0 && ptr[col - 1] == '-' |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5821 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5822 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5823 !(*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
|
5824 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5825 && !visual) |
7574
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 /* negative number */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5828 --col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5829 negative = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5830 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5831 /* get the number value (unsigned) */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5832 if (visual && VIsual_mode != 'V') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5833 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
|
5834 ? (int)STRLEN(ptr) - col |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5835 : length); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5836 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5837 vim_str2nr(ptr + col, &pre, &length, |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5838 0 + (dobin ? STR2NR_BIN : 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5839 + (dooct ? STR2NR_OCT : 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5840 + (dohex ? STR2NR_HEX : 0), |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5841 NULL, &n, maxlen); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5842 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5843 /* 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
|
5844 if (pre && negative) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5845 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5846 ++col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5847 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5848 negative = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5849 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5850 /* add or subtract */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5851 subtract = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5852 if (op_type == OP_NR_SUB) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5853 subtract ^= TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5854 if (negative) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5855 subtract ^= TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5856 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5857 oldn = n; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5858 if (subtract) |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5859 n -= (uvarnumber_T)Prenum1; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5860 else |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5861 n += (uvarnumber_T)Prenum1; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5862 /* handle wraparound for decimal numbers */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5863 if (!pre) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5864 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5865 if (subtract) |
6927 | 5866 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5867 if (n > oldn) |
6868 | 5868 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5869 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
|
5870 negative ^= TRUE; |
6868 | 5871 } |
7 | 5872 } |
5873 else | |
6868 | 5874 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5875 /* add */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5876 if (n < oldn) |
6868 | 5877 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5878 n = (n ^ (uvarnumber_T)-1); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5879 negative ^= TRUE; |
6868 | 5880 } |
6927 | 5881 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5882 if (n == 0) |
6868 | 5883 negative = FALSE; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5884 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5885 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5886 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
|
5887 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5888 /* need to remove the '-' */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5889 col--; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5890 length++; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5891 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5892 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5893 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5894 * Delete the old number. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5895 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5896 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5897 if (!did_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5898 startpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5899 did_change = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5900 todel = length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5901 c = gchar_cursor(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5902 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5903 * 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
|
5904 * 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
|
5905 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5906 if (c == '-') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5907 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5908 while (todel-- > 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5909 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5910 if (c < 0x100 && isalpha(c)) |
6868 | 5911 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5912 if (isupper(c)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5913 hexupper = TRUE; |
6868 | 5914 else |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5915 hexupper = FALSE; |
6891 | 5916 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5917 /* 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
|
5918 (void)del_char(FALSE); |
6868 | 5919 c = gchar_cursor(); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5920 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5921 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5922 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5923 * Prepare the leading characters in buf1[]. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5924 * 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
|
5925 * Allocate a bit too much. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5926 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5927 buf1 = alloc((unsigned)length + NUMBUFLEN); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5928 if (buf1 == NULL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5929 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5930 ptr = buf1; |
8989
e600e696c0a1
commit https://github.com/vim/vim/commit/dc633cf82758f67f656cda7fa8ccc30414ee53f8
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
5931 if (negative && (!visual || was_positive)) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5932 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5933 *ptr++ = '-'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5934 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5935 if (pre) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5936 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5937 *ptr++ = '0'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5938 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5939 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5940 if (pre == 'b' || pre == 'B' || |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5941 pre == 'x' || pre == 'X') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5942 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5943 *ptr++ = pre; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5944 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5945 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5946 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5947 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5948 * Put the number characters in buf2[]. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5949 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5950 if (pre == 'b' || pre == 'B') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5951 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5952 int i; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5953 int bit = 0; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5954 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
|
5955 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5956 /* leading zeros */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5957 for (bit = bits; bit > 0; bit--) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5958 if ((n >> (bit - 1)) & 0x1) break; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5959 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5960 for (i = 0; bit > 0; bit--) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5961 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
|
5962 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5963 buf2[i] = '\0'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5964 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5965 else if (pre == 0) |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5966 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
|
5967 else if (pre == '0') |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5968 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
|
5969 else if (pre && hexupper) |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5970 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
|
5971 else |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5972 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
|
5973 length -= (int)STRLEN(buf2); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5974 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5975 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5976 * 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
|
5977 * 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
|
5978 * Don't do this when |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5979 * 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
|
5980 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5981 if (firstdigit == '0' && !(dooct && pre == 0)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5982 while (length-- > 0) |
6868 | 5983 *ptr++ = '0'; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5984 *ptr = NUL; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5985 STRCAT(buf1, buf2); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5986 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
|
5987 vim_free(buf1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5988 endpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5989 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
|
5990 --curwin->w_cursor.col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5991 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5992 |
7570
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5993 if (did_change) |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5994 { |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5995 /* set the '[ and '] marks */ |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5996 curbuf->b_op_start = startpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5997 curbuf->b_op_end = endpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5998 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
|
5999 --curbuf->b_op_end.col; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
6000 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6001 |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
6002 theend: |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
6003 if (visual) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
6004 curwin->w_cursor = save_cursor; |
8690
6a1becf4f282
commit https://github.com/vim/vim/commit/8e08125d3a9afd0b16cd84454ae9ddad0abaaab0
Christian Brabandt <cb@256bit.org>
parents:
8399
diff
changeset
|
6005 else if (did_change) |
6a1becf4f282
commit https://github.com/vim/vim/commit/8e08125d3a9afd0b16cd84454ae9ddad0abaaab0
Christian Brabandt <cb@256bit.org>
parents:
8399
diff
changeset
|
6006 curwin->w_set_curswant = TRUE; |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
6007 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6008 return did_change; |
7 | 6009 } |
6010 | |
6011 #ifdef FEAT_VIMINFO | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6012 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6013 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
|
6014 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6015 #define REG_PREVIOUS 1 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6016 #define REG_EXEC 2 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6017 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6018 /* |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6019 * 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
|
6020 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6021 void |
9282
9f97a6290c63
commit https://github.com/vim/vim/commit/cf089463492fab53b2a5d81517829d22f882f82e
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
6022 prepare_viminfo_registers(void) |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6023 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6024 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
|
6025 * (int)sizeof(yankreg_T)); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6026 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6027 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6028 void |
9282
9f97a6290c63
commit https://github.com/vim/vim/commit/cf089463492fab53b2a5d81517829d22f882f82e
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
6029 finish_viminfo_registers(void) |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6030 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6031 int i; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6032 int j; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6033 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6034 if (y_read_regs != NULL) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6035 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6036 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
|
6037 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
|
6038 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6039 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
|
6040 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
|
6041 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
|
6042 } |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
6043 VIM_CLEAR(y_read_regs); |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6044 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6045 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6046 |
7 | 6047 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6048 read_viminfo_register(vir_T *virp, int force) |
7 | 6049 { |
6050 int eof; | |
6051 int do_it = TRUE; | |
6052 int size; | |
6053 int limit; | |
6054 int i; | |
6055 int set_prev = FALSE; | |
6056 char_u *str; | |
6057 char_u **array = NULL; | |
6508 | 6058 int new_type = MCHAR; /* init to shut up compiler */ |
6059 colnr_T new_width = 0; /* init to shut up compiler */ | |
7 | 6060 |
6061 /* We only get here (hopefully) if line[0] == '"' */ | |
6062 str = virp->vir_line + 1; | |
1893 | 6063 |
6064 /* If the line starts with "" this is the y_previous register. */ | |
7 | 6065 if (*str == '"') |
6066 { | |
6067 set_prev = TRUE; | |
6068 str++; | |
6069 } | |
1893 | 6070 |
7 | 6071 if (!ASCII_ISALNUM(*str) && *str != '-') |
6072 { | |
6073 if (viminfo_error("E577: ", _("Illegal register name"), virp->vir_line)) | |
6074 return TRUE; /* too many errors, pretend end-of-file */ | |
6075 do_it = FALSE; | |
6076 } | |
6077 get_yank_register(*str++, FALSE); | |
6078 if (!force && y_current->y_array != NULL) | |
6079 do_it = FALSE; | |
1893 | 6080 |
6081 if (*str == '@') | |
6082 { | |
6083 /* "x@: register x used for @@ */ | |
6084 if (force || execreg_lastc == NUL) | |
6085 execreg_lastc = str[-1]; | |
6086 } | |
6087 | |
7 | 6088 size = 0; |
6089 limit = 100; /* Optimized for registers containing <= 100 lines */ | |
6090 if (do_it) | |
6091 { | |
6462 | 6092 /* |
6093 * Build the new register in array[]. | |
6094 * y_array is kept as-is until done. | |
6095 * The "do_it" flag is reset when something is wrong, in which case | |
6096 * array[] needs to be freed. | |
6097 */ | |
7 | 6098 if (set_prev) |
6099 y_previous = y_current; | |
6462 | 6100 array = (char_u **)alloc((unsigned)(limit * sizeof(char_u *))); |
1893 | 6101 str = skipwhite(skiptowhite(str)); |
7 | 6102 if (STRNCMP(str, "CHAR", 4) == 0) |
6462 | 6103 new_type = MCHAR; |
7 | 6104 else if (STRNCMP(str, "BLOCK", 5) == 0) |
6462 | 6105 new_type = MBLOCK; |
7 | 6106 else |
6462 | 6107 new_type = MLINE; |
7 | 6108 /* get the block width; if it's missing we get a zero, which is OK */ |
6109 str = skipwhite(skiptowhite(str)); | |
6462 | 6110 new_width = getdigits(&str); |
7 | 6111 } |
6112 | |
6113 while (!(eof = viminfo_readline(virp)) | |
6114 && (virp->vir_line[0] == TAB || virp->vir_line[0] == '<')) | |
6115 { | |
6116 if (do_it) | |
6117 { | |
6462 | 6118 if (size == limit) |
7 | 6119 { |
6462 | 6120 char_u **new_array = (char_u **) |
7 | 6121 alloc((unsigned)(limit * 2 * sizeof(char_u *))); |
6462 | 6122 |
6123 if (new_array == NULL) | |
6124 { | |
6125 do_it = FALSE; | |
6126 break; | |
6127 } | |
7 | 6128 for (i = 0; i < limit; i++) |
6462 | 6129 new_array[i] = array[i]; |
7 | 6130 vim_free(array); |
6462 | 6131 array = new_array; |
7 | 6132 limit *= 2; |
6133 } | |
6134 str = viminfo_readstring(virp, 1, TRUE); | |
6135 if (str != NULL) | |
6136 array[size++] = str; | |
6137 else | |
6462 | 6138 /* error, don't store the result */ |
7 | 6139 do_it = FALSE; |
6140 } | |
6141 } | |
6508 | 6142 |
7 | 6143 if (do_it) |
6144 { | |
6462 | 6145 /* free y_array[] */ |
6146 for (i = 0; i < y_current->y_size; i++) | |
6147 vim_free(y_current->y_array[i]); | |
6148 vim_free(y_current->y_array); | |
6149 | |
6150 y_current->y_type = new_type; | |
6151 y_current->y_width = new_width; | |
6152 y_current->y_size = size; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6153 y_current->y_time_set = 0; |
7 | 6154 if (size == 0) |
6155 { | |
6156 y_current->y_array = NULL; | |
6157 } | |
6462 | 6158 else |
7 | 6159 { |
6462 | 6160 /* Move the lines from array[] to y_array[]. */ |
7 | 6161 y_current->y_array = |
6162 (char_u **)alloc((unsigned)(size * sizeof(char_u *))); | |
6163 for (i = 0; i < size; i++) | |
6462 | 6164 { |
6165 if (y_current->y_array == NULL) | |
6166 vim_free(array[i]); | |
6167 else | |
6168 y_current->y_array[i] = array[i]; | |
6169 } | |
7 | 6170 } |
6462 | 6171 } |
6172 else | |
6173 { | |
6174 /* Free array[] if it was filled. */ | |
6175 for (i = 0; i < size; i++) | |
6176 vim_free(array[i]); | |
6177 } | |
6178 vim_free(array); | |
6179 | |
7 | 6180 return eof; |
6181 } | |
6182 | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6183 /* |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6184 * 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
|
6185 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6186 void |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6187 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
|
6188 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6189 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
|
6190 int flags; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6191 int name; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6192 int type; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6193 int linecount; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6194 int width; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6195 time_t timestamp; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6196 yankreg_T *y_ptr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6197 int i; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6198 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6199 /* Check the format: |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6200 * |{bartype},{flags},{name},{type}, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6201 * {linecount},{width},{timestamp},"line1","line2" |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6202 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6203 if (values->ga_len < 6 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6204 || vp[0].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6205 || vp[1].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6206 || vp[2].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6207 || vp[3].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6208 || vp[4].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6209 || vp[5].bv_type != BVAL_NR) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6210 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6211 flags = vp[0].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6212 name = vp[1].bv_nr; |
9307
eb52a2670c96
commit https://github.com/vim/vim/commit/67e3720a9ddd8a9d2e8344358c28fa1f4196db0d
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
6213 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
|
6214 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6215 type = vp[2].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6216 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
|
6217 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6218 linecount = vp[3].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6219 if (values->ga_len < 6 + linecount) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6220 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6221 width = vp[4].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6222 if (width < 0) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6223 return; |
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 if (y_read_regs != NULL) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6226 /* 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
|
6227 * 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
|
6228 y_ptr = &y_read_regs[name]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6229 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6230 y_ptr = &y_regs[name]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6231 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6232 /* 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
|
6233 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
|
6234 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
|
6235 && (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
|
6236 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6237 |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
6238 if (y_ptr->y_array != NULL) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
6239 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
|
6240 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
|
6241 vim_free(y_ptr->y_array); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6242 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6243 if (y_read_regs == NULL) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6244 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6245 if (flags & REG_PREVIOUS) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6246 y_previous = y_ptr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6247 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
|
6248 execreg_lastc = get_register_name(name); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6249 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6250 y_ptr->y_type = type; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6251 y_ptr->y_width = width; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6252 y_ptr->y_size = linecount; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6253 y_ptr->y_time_set = timestamp; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6254 if (linecount == 0) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6255 y_ptr->y_array = NULL; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6256 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6257 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6258 y_ptr->y_array = |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6259 (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
|
6260 for (i = 0; i < linecount; i++) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6261 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6262 if (vp[i + 6].bv_allocated) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6263 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6264 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
|
6265 vp[i + 6].bv_string = NULL; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6266 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6267 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6268 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
|
6269 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6270 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6271 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6272 |
7 | 6273 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6274 write_viminfo_registers(FILE *fp) |
7 | 6275 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6276 int i, j; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6277 char_u *type; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6278 char_u c; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6279 int num_lines; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6280 int max_num_lines; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6281 int max_kbyte; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6282 long len; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6283 yankreg_T *y_ptr; |
7 | 6284 |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
6285 fputs(_("\n# Registers:\n"), fp); |
7 | 6286 |
6287 /* Get '<' value, use old '"' value if '<' is not found. */ | |
6288 max_num_lines = get_viminfo_parameter('<'); | |
6289 if (max_num_lines < 0) | |
6290 max_num_lines = get_viminfo_parameter('"'); | |
6291 if (max_num_lines == 0) | |
6292 return; | |
6293 max_kbyte = get_viminfo_parameter('s'); | |
6294 if (max_kbyte == 0) | |
6295 return; | |
1893 | 6296 |
7 | 6297 for (i = 0; i < NUM_REGISTERS; i++) |
6298 { | |
6299 #ifdef FEAT_CLIPBOARD | |
6300 /* Skip '*'/'+' register, we don't want them back next time */ | |
6301 if (i == STAR_REGISTER || i == PLUS_REGISTER) | |
6302 continue; | |
6303 #endif | |
6304 #ifdef FEAT_DND | |
6305 /* Neither do we want the '~' register */ | |
6306 if (i == TILDE_REGISTER) | |
6307 continue; | |
6308 #endif | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6309 /* 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
|
6310 * viminfo if it's newer. */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6311 if (y_read_regs != NULL |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6312 && 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
|
6313 && (y_regs[i].y_array == NULL || |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6314 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
|
6315 y_ptr = &y_read_regs[i]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6316 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
|
6317 continue; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6318 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6319 y_ptr = &y_regs[i]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6320 |
55 | 6321 /* Skip empty registers. */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6322 num_lines = y_ptr->y_size; |
55 | 6323 if (num_lines == 0 |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6324 || (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
|
6325 && *y_ptr->y_array[0] == NUL)) |
55 | 6326 continue; |
6327 | |
7 | 6328 if (max_kbyte > 0) |
6329 { | |
6330 /* Skip register if there is more text than the maximum size. */ | |
6331 len = 0; | |
6332 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
|
6333 len += (long)STRLEN(y_ptr->y_array[j]) + 1L; |
7 | 6334 if (len > (long)max_kbyte * 1024L) |
6335 continue; | |
6336 } | |
6337 | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6338 switch (y_ptr->y_type) |
7 | 6339 { |
6340 case MLINE: | |
6341 type = (char_u *)"LINE"; | |
6342 break; | |
6343 case MCHAR: | |
6344 type = (char_u *)"CHAR"; | |
6345 break; | |
6346 case MBLOCK: | |
6347 type = (char_u *)"BLOCK"; | |
6348 break; | |
6349 default: | |
6350 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
|
6351 y_ptr->y_type); |
7 | 6352 emsg(IObuff); |
6353 type = (char_u *)"LINE"; | |
6354 break; | |
6355 } | |
6356 if (y_previous == &y_regs[i]) | |
6357 fprintf(fp, "\""); | |
6358 c = get_register_name(i); | |
1893 | 6359 fprintf(fp, "\"%c", c); |
6360 if (c == execreg_lastc) | |
6361 fprintf(fp, "@"); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6362 fprintf(fp, "\t%s\t%d\n", type, (int)y_ptr->y_width); |
7 | 6363 |
6364 /* If max_num_lines < 0, then we save ALL the lines in the register */ | |
6365 if (max_num_lines > 0 && num_lines > max_num_lines) | |
6366 num_lines = max_num_lines; | |
6367 for (j = 0; j < num_lines; j++) | |
6368 { | |
6369 putc('\t', fp); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6370 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
|
6371 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6372 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6373 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6374 int flags = 0; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6375 int remaining; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6376 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6377 /* 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
|
6378 * |{bartype},{flags},{name},{type}, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6379 * {linecount},{width},{timestamp},"line1","line2" |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6380 * flags: REG_PREVIOUS - register is y_previous |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
6381 * REG_EXEC - used for @@ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6382 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6383 if (y_previous == &y_regs[i]) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6384 flags |= REG_PREVIOUS; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6385 if (c == execreg_lastc) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6386 flags |= REG_EXEC; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6387 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
|
6388 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
|
6389 (long)y_ptr->y_time_set); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6390 /* 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
|
6391 remaining = LSIZE - 71; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6392 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
|
6393 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6394 putc(',', fp); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6395 --remaining; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6396 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
|
6397 remaining); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6398 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6399 putc('\n', fp); |
7 | 6400 } |
6401 } | |
6402 } | |
6403 #endif /* FEAT_VIMINFO */ | |
6404 | |
6405 #if defined(FEAT_CLIPBOARD) || defined(PROTO) | |
6406 /* | |
6407 * SELECTION / PRIMARY ('*') | |
6408 * | |
6409 * Text selection stuff that uses the GUI selection register '*'. When using a | |
6410 * GUI this may be text from another window, otherwise it is the last text we | |
6411 * had highlighted with VIsual mode. With mouse support, clicking the middle | |
6412 * button performs the paste, otherwise you will need to do <"*p>. " | |
6413 * If not under X, it is synonymous with the clipboard register '+'. | |
6414 * | |
6415 * X CLIPBOARD ('+') | |
6416 * | |
6417 * Text selection stuff that uses the GUI clipboard register '+'. | |
6418 * Under X, this matches the standard cut/paste buffer CLIPBOARD selection. | |
6419 * It will be used for unnamed cut/pasting is 'clipboard' contains "unnamed", | |
6420 * otherwise you will need to do <"+p>. " | |
6421 * If not under X, it is synonymous with the selection register '*'. | |
6422 */ | |
6423 | |
6424 /* | |
6425 * Routine to export any final X selection we had to the environment | |
11065
f5bd684e47a1
patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents:
10827
diff
changeset
|
6426 * so that the text is still available after Vim has exited. X selections |
7 | 6427 * only exist while the owning application exists, so we write to the |
6428 * permanent (while X runs) store CUT_BUFFER0. | |
6429 * Dump the CLIPBOARD selection if we own it (it's logically the more | |
6430 * 'permanent' of the two), otherwise the PRIMARY one. | |
6431 * For now, use a hard-coded sanity limit of 1Mb of data. | |
6432 */ | |
9834
80ace3687eec
commit https://github.com/vim/vim/commit/a6b7a08ae04a3cd4d9c45c906bb7a197e2135179
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
6433 #if (defined(FEAT_X11) && defined(FEAT_CLIPBOARD)) || defined(PROTO) |
7 | 6434 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6435 x11_export_final_selection(void) |
7 | 6436 { |
6437 Display *dpy; | |
6438 char_u *str = NULL; | |
6439 long_u len = 0; | |
6440 int motion_type = -1; | |
6441 | |
6442 # ifdef FEAT_GUI | |
6443 if (gui.in_use) | |
6444 dpy = X_DISPLAY; | |
6445 else | |
6446 # endif | |
6447 # ifdef FEAT_XCLIPBOARD | |
6448 dpy = xterm_dpy; | |
6449 # else | |
6450 return; | |
6451 # endif | |
6452 | |
6453 /* Get selection to export */ | |
6454 if (clip_plus.owned) | |
6455 motion_type = clip_convert_selection(&str, &len, &clip_plus); | |
6456 else if (clip_star.owned) | |
6457 motion_type = clip_convert_selection(&str, &len, &clip_star); | |
6458 | |
6459 /* Check it's OK */ | |
6460 if (dpy != NULL && str != NULL && motion_type >= 0 | |
6461 && len < 1024*1024 && len > 0) | |
6462 { | |
1924 | 6463 #ifdef FEAT_MBYTE |
4201 | 6464 int ok = TRUE; |
6465 | |
1924 | 6466 /* The CUT_BUFFER0 is supposed to always contain latin1. Convert from |
6467 * 'enc' when it is a multi-byte encoding. When 'enc' is an 8-bit | |
6468 * encoding conversion usually doesn't work, so keep the text as-is. | |
6469 */ | |
6470 if (has_mbyte) | |
6471 { | |
6472 vimconv_T vc; | |
6473 | |
6474 vc.vc_type = CONV_NONE; | |
6475 if (convert_setup(&vc, p_enc, (char_u *)"latin1") == OK) | |
6476 { | |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2007
diff
changeset
|
6477 int intlen = len; |
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2007
diff
changeset
|
6478 char_u *conv_str; |
2007 | 6479 |
4201 | 6480 vc.vc_fail = TRUE; |
2007 | 6481 conv_str = string_convert(&vc, str, &intlen); |
6482 len = intlen; | |
1924 | 6483 if (conv_str != NULL) |
6484 { | |
6485 vim_free(str); | |
6486 str = conv_str; | |
6487 } | |
4201 | 6488 else |
6489 { | |
6490 ok = FALSE; | |
6491 } | |
1924 | 6492 convert_setup(&vc, NULL, NULL); |
6493 } | |
4201 | 6494 else |
6495 { | |
6496 ok = FALSE; | |
6497 } | |
1924 | 6498 } |
4201 | 6499 |
6500 /* Do not store the string if conversion failed. Better to use any | |
6501 * other selection than garbled text. */ | |
6502 if (ok) | |
6503 #endif | |
6504 { | |
6505 XStoreBuffer(dpy, (char *)str, (int)len, 0); | |
6506 XFlush(dpy); | |
6507 } | |
7 | 6508 } |
6509 | |
6510 vim_free(str); | |
6511 } | |
6512 #endif | |
6513 | |
6514 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6515 clip_free_selection(VimClipboard *cbd) |
7 | 6516 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6517 yankreg_T *y_ptr = y_current; |
7 | 6518 |
6519 if (cbd == &clip_plus) | |
6520 y_current = &y_regs[PLUS_REGISTER]; | |
6521 else | |
6522 y_current = &y_regs[STAR_REGISTER]; | |
6523 free_yank_all(); | |
6524 y_current->y_size = 0; | |
6525 y_current = y_ptr; | |
6526 } | |
6527 | |
6528 /* | |
6529 * Get the selected text and put it in the gui selection register '*' or '+'. | |
6530 */ | |
6531 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6532 clip_get_selection(VimClipboard *cbd) |
7 | 6533 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6534 yankreg_T *old_y_previous, *old_y_current; |
7 | 6535 pos_T old_cursor; |
6536 pos_T old_visual; | |
6537 int old_visual_mode; | |
6538 colnr_T old_curswant; | |
6539 int old_set_curswant; | |
6540 pos_T old_op_start, old_op_end; | |
6541 oparg_T oa; | |
6542 cmdarg_T ca; | |
6543 | |
6544 if (cbd->owned) | |
6545 { | |
6546 if ((cbd == &clip_plus && y_regs[PLUS_REGISTER].y_array != NULL) | |
6547 || (cbd == &clip_star && y_regs[STAR_REGISTER].y_array != NULL)) | |
6548 return; | |
6549 | |
6550 /* Get the text between clip_star.start & clip_star.end */ | |
6551 old_y_previous = y_previous; | |
6552 old_y_current = y_current; | |
6553 old_cursor = curwin->w_cursor; | |
6554 old_curswant = curwin->w_curswant; | |
6555 old_set_curswant = curwin->w_set_curswant; | |
6556 old_op_start = curbuf->b_op_start; | |
6557 old_op_end = curbuf->b_op_end; | |
6558 old_visual = VIsual; | |
6559 old_visual_mode = VIsual_mode; | |
6560 clear_oparg(&oa); | |
6561 oa.regname = (cbd == &clip_plus ? '+' : '*'); | |
6562 oa.op_type = OP_YANK; | |
6563 vim_memset(&ca, 0, sizeof(ca)); | |
6564 ca.oap = &oa; | |
6565 ca.cmdchar = 'y'; | |
6566 ca.count1 = 1; | |
6567 ca.retval = CA_NO_ADJ_OP_END; | |
6568 do_pending_operator(&ca, 0, TRUE); | |
6569 y_previous = old_y_previous; | |
6570 y_current = old_y_current; | |
6571 curwin->w_cursor = old_cursor; | |
688 | 6572 changed_cline_bef_curs(); /* need to update w_virtcol et al */ |
7 | 6573 curwin->w_curswant = old_curswant; |
6574 curwin->w_set_curswant = old_set_curswant; | |
6575 curbuf->b_op_start = old_op_start; | |
6576 curbuf->b_op_end = old_op_end; | |
6577 VIsual = old_visual; | |
6578 VIsual_mode = old_visual_mode; | |
6579 } | |
11273
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
6580 else if (!is_clipboard_needs_update()) |
7 | 6581 { |
6582 clip_free_selection(cbd); | |
6583 | |
6584 /* Try to get selected text from another window */ | |
6585 clip_gen_request_selection(cbd); | |
6586 } | |
6587 } | |
6588 | |
2896 | 6589 /* |
6590 * Convert from the GUI selection string into the '*'/'+' register. | |
6591 */ | |
7 | 6592 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6593 clip_yank_selection( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6594 int type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6595 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6596 long len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6597 VimClipboard *cbd) |
7 | 6598 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6599 yankreg_T *y_ptr; |
7 | 6600 |
6601 if (cbd == &clip_plus) | |
6602 y_ptr = &y_regs[PLUS_REGISTER]; | |
6603 else | |
6604 y_ptr = &y_regs[STAR_REGISTER]; | |
6605 | |
6606 clip_free_selection(cbd); | |
6607 | |
5798 | 6608 str_to_reg(y_ptr, type, str, len, 0L, FALSE); |
7 | 6609 } |
6610 | |
6611 /* | |
6612 * Convert the '*'/'+' register into a GUI selection string returned in *str | |
6613 * with length *len. | |
6614 * Returns the motion type, or -1 for failure. | |
6615 */ | |
6616 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6617 clip_convert_selection(char_u **str, long_u *len, VimClipboard *cbd) |
7 | 6618 { |
6619 char_u *p; | |
6620 int lnum; | |
6621 int i, j; | |
6622 int_u eolsize; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6623 yankreg_T *y_ptr; |
7 | 6624 |
6625 if (cbd == &clip_plus) | |
6626 y_ptr = &y_regs[PLUS_REGISTER]; | |
6627 else | |
6628 y_ptr = &y_regs[STAR_REGISTER]; | |
6629 | |
6630 #ifdef USE_CRNL | |
6631 eolsize = 2; | |
6632 #else | |
6633 eolsize = 1; | |
6634 #endif | |
6635 | |
6636 *str = NULL; | |
6637 *len = 0; | |
6638 if (y_ptr->y_array == NULL) | |
6639 return -1; | |
6640 | |
6641 for (i = 0; i < y_ptr->y_size; i++) | |
6642 *len += (long_u)STRLEN(y_ptr->y_array[i]) + eolsize; | |
6643 | |
6644 /* | |
6645 * Don't want newline character at end of last line if we're in MCHAR mode. | |
6646 */ | |
6647 if (y_ptr->y_type == MCHAR && *len >= eolsize) | |
6648 *len -= eolsize; | |
6649 | |
6650 p = *str = lalloc(*len + 1, TRUE); /* add one to avoid zero */ | |
6651 if (p == NULL) | |
6652 return -1; | |
6653 lnum = 0; | |
6654 for (i = 0, j = 0; i < (int)*len; i++, j++) | |
6655 { | |
6656 if (y_ptr->y_array[lnum][j] == '\n') | |
6657 p[i] = NUL; | |
6658 else if (y_ptr->y_array[lnum][j] == NUL) | |
6659 { | |
6660 #ifdef USE_CRNL | |
6661 p[i++] = '\r'; | |
6662 #endif | |
6663 #ifdef USE_CR | |
6664 p[i] = '\r'; | |
6665 #else | |
6666 p[i] = '\n'; | |
6667 #endif | |
6668 lnum++; | |
6669 j = -1; | |
6670 } | |
6671 else | |
6672 p[i] = y_ptr->y_array[lnum][j]; | |
6673 } | |
6674 return y_ptr->y_type; | |
6675 } | |
6676 | |
6677 | |
6678 /* | |
6679 * If we have written to a clipboard register, send the text to the clipboard. | |
6680 */ | |
6681 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6682 may_set_selection(void) |
7 | 6683 { |
6684 if (y_current == &(y_regs[STAR_REGISTER]) && clip_star.available) | |
6685 { | |
6686 clip_own_selection(&clip_star); | |
6687 clip_gen_set_selection(&clip_star); | |
6688 } | |
6689 else if (y_current == &(y_regs[PLUS_REGISTER]) && clip_plus.available) | |
6690 { | |
6691 clip_own_selection(&clip_plus); | |
6692 clip_gen_set_selection(&clip_plus); | |
6693 } | |
6694 } | |
6695 | |
6696 #endif /* FEAT_CLIPBOARD || PROTO */ | |
6697 | |
6698 | |
6699 #if defined(FEAT_DND) || defined(PROTO) | |
6700 /* | |
6701 * Replace the contents of the '~' register with str. | |
6702 */ | |
6703 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6704 dnd_yank_drag_data(char_u *str, long len) |
7 | 6705 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6706 yankreg_T *curr; |
7 | 6707 |
6708 curr = y_current; | |
6709 y_current = &y_regs[TILDE_REGISTER]; | |
6710 free_yank_all(); | |
5798 | 6711 str_to_reg(y_current, MCHAR, str, len, 0L, FALSE); |
7 | 6712 y_current = curr; |
6713 } | |
6714 #endif | |
6715 | |
6716 | |
6717 #if defined(FEAT_EVAL) || defined(PROTO) | |
6718 /* | |
6719 * Return the type of a register. | |
6720 * Used for getregtype() | |
6721 * Returns MAUTO for error. | |
6722 */ | |
6723 char_u | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6724 get_reg_type(int regname, long *reglen) |
7 | 6725 { |
6726 switch (regname) | |
6727 { | |
6728 case '%': /* file name */ | |
6729 case '#': /* alternate file name */ | |
6730 case '=': /* expression */ | |
6731 case ':': /* last command line */ | |
6732 case '/': /* last search-pattern */ | |
6733 case '.': /* last inserted text */ | |
6734 #ifdef FEAT_SEARCHPATH | |
6735 case Ctrl_F: /* Filename under cursor */ | |
6736 case Ctrl_P: /* Path under cursor, expand via "path" */ | |
6737 #endif | |
6738 case Ctrl_W: /* word under cursor */ | |
6739 case Ctrl_A: /* WORD (mnemonic All) under cursor */ | |
6740 case '_': /* black hole: always empty */ | |
6741 return MCHAR; | |
6742 } | |
6743 | |
6744 #ifdef FEAT_CLIPBOARD | |
6745 regname = may_get_selection(regname); | |
6746 #endif | |
6747 | |
5596 | 6748 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
|
6749 return MAUTO; |
5596 | 6750 |
7 | 6751 get_yank_register(regname, FALSE); |
6752 | |
6753 if (y_current->y_array != NULL) | |
6754 { | |
6755 if (reglen != NULL && y_current->y_type == MBLOCK) | |
6756 *reglen = y_current->y_width; | |
6757 return y_current->y_type; | |
6758 } | |
6759 return MAUTO; | |
6760 } | |
6761 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
6762 static char_u *getreg_wrap_one_line(char_u *s, int flags); |
5796 | 6763 |
6764 /* | |
6765 * When "flags" has GREG_LIST return a list with text "s". | |
6766 * Otherwise just return "s". | |
6767 */ | |
6768 static char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6769 getreg_wrap_one_line(char_u *s, int flags) |
5796 | 6770 { |
6771 if (flags & GREG_LIST) | |
6772 { | |
6773 list_T *list = list_alloc(); | |
6774 | |
6775 if (list != NULL) | |
6776 { | |
6777 if (list_append_string(list, NULL, -1) == FAIL) | |
6778 { | |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8690
diff
changeset
|
6779 list_free(list); |
5796 | 6780 return NULL; |
6781 } | |
6782 list->lv_first->li_tv.vval.v_string = s; | |
6783 } | |
6784 return (char_u *)list; | |
6785 } | |
6786 return s; | |
6787 } | |
6788 | |
7 | 6789 /* |
6790 * Return the contents of a register as a single allocated string. | |
6791 * Used for "@r" in expressions and for getreg(). | |
6792 * Returns NULL for error. | |
5796 | 6793 * Flags: |
6794 * GREG_NO_EXPR Do not allow expression register | |
6795 * GREG_EXPR_SRC For the expression register: return expression itself, | |
6796 * not the result of its evaluation. | |
6797 * GREG_LIST Return a list of lines in place of a single string. | |
7 | 6798 */ |
6799 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6800 get_reg_contents(int regname, int flags) |
7 | 6801 { |
6802 long i; | |
6803 char_u *retval; | |
6804 int allocated; | |
6805 long len; | |
6806 | |
6807 /* Don't allow using an expression register inside an expression */ | |
6808 if (regname == '=') | |
6809 { | |
5796 | 6810 if (flags & GREG_NO_EXPR) |
6811 return NULL; | |
6812 if (flags & GREG_EXPR_SRC) | |
6813 return getreg_wrap_one_line(get_expr_line_src(), flags); | |
6814 return getreg_wrap_one_line(get_expr_line(), flags); | |
7 | 6815 } |
6816 | |
6817 if (regname == '@') /* "@@" is used for unnamed register */ | |
6818 regname = '"'; | |
6819 | |
6820 /* check for valid regname */ | |
6821 if (regname != NUL && !valid_yank_reg(regname, FALSE)) | |
6822 return NULL; | |
6823 | |
6824 #ifdef FEAT_CLIPBOARD | |
6825 regname = may_get_selection(regname); | |
6826 #endif | |
6827 | |
6828 if (get_spec_reg(regname, &retval, &allocated, FALSE)) | |
6829 { | |
6830 if (retval == NULL) | |
6831 return NULL; | |
5796 | 6832 if (allocated) |
6833 return getreg_wrap_one_line(retval, flags); | |
6834 return getreg_wrap_one_line(vim_strsave(retval), flags); | |
7 | 6835 } |
6836 | |
6837 get_yank_register(regname, FALSE); | |
6838 if (y_current->y_array == NULL) | |
6839 return NULL; | |
6840 | |
5796 | 6841 if (flags & GREG_LIST) |
6842 { | |
6843 list_T *list = list_alloc(); | |
6844 int error = FALSE; | |
6845 | |
6846 if (list == NULL) | |
6847 return NULL; | |
6848 for (i = 0; i < y_current->y_size; ++i) | |
6849 if (list_append_string(list, y_current->y_array[i], -1) == FAIL) | |
6850 error = TRUE; | |
6851 if (error) | |
6852 { | |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8690
diff
changeset
|
6853 list_free(list); |
5796 | 6854 return NULL; |
6855 } | |
6856 return (char_u *)list; | |
6857 } | |
6858 | |
7 | 6859 /* |
6860 * Compute length of resulting string. | |
6861 */ | |
6862 len = 0; | |
6863 for (i = 0; i < y_current->y_size; ++i) | |
6864 { | |
6865 len += (long)STRLEN(y_current->y_array[i]); | |
6866 /* | |
6867 * Insert a newline between lines and after last line if | |
6868 * y_type is MLINE. | |
6869 */ | |
6870 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | |
6871 ++len; | |
6872 } | |
6873 | |
6874 retval = lalloc(len + 1, TRUE); | |
6875 | |
6876 /* | |
6877 * Copy the lines of the yank register into the string. | |
6878 */ | |
6879 if (retval != NULL) | |
6880 { | |
6881 len = 0; | |
6882 for (i = 0; i < y_current->y_size; ++i) | |
6883 { | |
6884 STRCPY(retval + len, y_current->y_array[i]); | |
6885 len += (long)STRLEN(retval + len); | |
6886 | |
6887 /* | |
6888 * Insert a NL between lines and after the last line if y_type is | |
6889 * MLINE. | |
6890 */ | |
6891 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | |
6892 retval[len++] = '\n'; | |
6893 } | |
6894 retval[len] = NUL; | |
6895 } | |
6896 | |
6897 return retval; | |
6898 } | |
6899 | |
5798 | 6900 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6901 init_write_reg( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6902 int name, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6903 yankreg_T **old_y_previous, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6904 yankreg_T **old_y_current, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6905 int must_append, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6906 int *yank_type UNUSED) |
5798 | 6907 { |
6908 if (!valid_yank_reg(name, TRUE)) /* check for valid reg name */ | |
6909 { | |
6910 emsg_invreg(name); | |
6911 return FAIL; | |
6912 } | |
6913 | |
6914 /* Don't want to change the current (unnamed) register */ | |
6915 *old_y_previous = y_previous; | |
6916 *old_y_current = y_current; | |
6917 | |
6918 get_yank_register(name, TRUE); | |
6919 if (!y_append && !must_append) | |
6920 free_yank_all(); | |
6921 return OK; | |
6922 } | |
6923 | |
6924 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6925 finish_write_reg( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6926 int name, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6927 yankreg_T *old_y_previous, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6928 yankreg_T *old_y_current) |
5798 | 6929 { |
6930 # ifdef FEAT_CLIPBOARD | |
6931 /* Send text of clipboard register to the clipboard. */ | |
6932 may_set_selection(); | |
6933 # endif | |
6934 | |
6935 /* ':let @" = "val"' should change the meaning of the "" register */ | |
6936 if (name != '"') | |
6937 y_previous = old_y_previous; | |
6938 y_current = old_y_current; | |
6939 } | |
6940 | |
7 | 6941 /* |
6942 * Store string "str" in register "name". | |
6943 * "maxlen" is the maximum number of bytes to use, -1 for all bytes. | |
6944 * If "must_append" is TRUE, always append to the register. Otherwise append | |
6945 * if "name" is an uppercase letter. | |
6946 * Note: "maxlen" and "must_append" don't work for the "/" register. | |
6947 * Careful: 'str' is modified, you may have to use a copy! | |
6948 * If "str" ends in '\n' or '\r', use linewise, otherwise use characterwise. | |
6949 */ | |
6950 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6951 write_reg_contents( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6952 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6953 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6954 int maxlen, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6955 int must_append) |
7 | 6956 { |
6957 write_reg_contents_ex(name, str, maxlen, must_append, MAUTO, 0L); | |
6958 } | |
6959 | |
6960 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6961 write_reg_contents_lst( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6962 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6963 char_u **strings, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6964 int maxlen UNUSED, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6965 int must_append, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6966 int yank_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6967 long block_len) |
5798 | 6968 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6969 yankreg_T *old_y_previous, *old_y_current; |
5798 | 6970 |
6971 if (name == '/' | |
6972 #ifdef FEAT_EVAL | |
6973 || name == '=' | |
6974 #endif | |
6975 ) | |
6976 { | |
6977 char_u *s; | |
6978 | |
6979 if (strings[0] == NULL) | |
6980 s = (char_u *)""; | |
6981 else if (strings[1] != NULL) | |
6982 { | |
6983 EMSG(_("E883: search pattern and expression register may not " | |
6984 "contain two or more lines")); | |
6985 return; | |
6986 } | |
6987 else | |
6988 s = strings[0]; | |
6989 write_reg_contents_ex(name, s, -1, must_append, yank_type, block_len); | |
6990 return; | |
6991 } | |
6992 | |
6993 if (name == '_') /* black hole: nothing to do */ | |
6994 return; | |
6995 | |
6996 if (init_write_reg(name, &old_y_previous, &old_y_current, must_append, | |
6997 &yank_type) == FAIL) | |
6998 return; | |
6999 | |
7000 str_to_reg(y_current, yank_type, (char_u *) strings, -1, block_len, TRUE); | |
7001 | |
7002 finish_write_reg(name, old_y_previous, old_y_current); | |
7003 } | |
7004 | |
7005 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7006 write_reg_contents_ex( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7007 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7008 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7009 int maxlen, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7010 int must_append, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7011 int yank_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7012 long block_len) |
7 | 7013 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7014 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
|
7015 long len; |
7 | 7016 |
336 | 7017 if (maxlen >= 0) |
7018 len = maxlen; | |
7019 else | |
7020 len = (long)STRLEN(str); | |
7021 | |
7 | 7022 /* Special case: '/' search pattern */ |
7023 if (name == '/') | |
7024 { | |
7025 set_last_search_pat(str, RE_SEARCH, TRUE, TRUE); | |
7026 return; | |
7027 } | |
7028 | |
6557 | 7029 if (name == '#') |
7030 { | |
7031 buf_T *buf; | |
7032 | |
7033 if (VIM_ISDIGIT(*str)) | |
7034 { | |
7035 int num = atoi((char *)str); | |
7036 | |
7037 buf = buflist_findnr(num); | |
7038 if (buf == NULL) | |
7039 EMSGN(_(e_nobufnr), (long)num); | |
7040 } | |
7041 else | |
7042 buf = buflist_findnr(buflist_findpat(str, str + STRLEN(str), | |
7043 TRUE, FALSE, FALSE)); | |
7044 if (buf == NULL) | |
7045 return; | |
7046 curwin->w_alt_fnum = buf->b_fnum; | |
7047 return; | |
7048 } | |
7049 | |
336 | 7050 #ifdef FEAT_EVAL |
7051 if (name == '=') | |
7052 { | |
7053 char_u *p, *s; | |
7054 | |
7055 p = vim_strnsave(str, (int)len); | |
7056 if (p == NULL) | |
7057 return; | |
7058 if (must_append) | |
7059 { | |
7060 s = concat_str(get_expr_line_src(), p); | |
7061 vim_free(p); | |
7062 p = s; | |
7063 } | |
7064 set_expr_line(p); | |
7065 return; | |
7066 } | |
7067 #endif | |
7068 | |
7 | 7069 if (name == '_') /* black hole: nothing to do */ |
7070 return; | |
7071 | |
5798 | 7072 if (init_write_reg(name, &old_y_previous, &old_y_current, must_append, |
7073 &yank_type) == FAIL) | |
7074 return; | |
7075 | |
7076 str_to_reg(y_current, yank_type, str, len, block_len, FALSE); | |
7077 | |
7078 finish_write_reg(name, old_y_previous, old_y_current); | |
7 | 7079 } |
7080 #endif /* FEAT_EVAL */ | |
7081 | |
7082 #if defined(FEAT_CLIPBOARD) || defined(FEAT_EVAL) | |
7083 /* | |
7084 * Put a string into a register. When the register is not empty, the string | |
7085 * is appended. | |
7086 */ | |
7087 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7088 str_to_reg( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7089 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
|
7090 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
|
7091 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
|
7092 long len, /* length of string */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7093 long blocklen, /* width of Visual block */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7094 int str_list) /* TRUE if str is char_u ** */ |
7 | 7095 { |
2896 | 7096 int type; /* MCHAR, MLINE or MBLOCK */ |
7 | 7097 int lnum; |
7098 long start; | |
7099 long i; | |
7100 int extra; | |
7101 int newlines; /* number of lines added */ | |
7102 int extraline = 0; /* extra line at the end */ | |
7103 int append = FALSE; /* append to last line in register */ | |
7104 char_u *s; | |
5798 | 7105 char_u **ss; |
7 | 7106 char_u **pp; |
7107 long maxlen; | |
7108 | |
2000 | 7109 if (y_ptr->y_array == NULL) /* NULL means empty register */ |
7 | 7110 y_ptr->y_size = 0; |
7111 | |
2896 | 7112 if (yank_type == MAUTO) |
5798 | 7113 type = ((str_list || (len > 0 && (str[len - 1] == NL |
7114 || str[len - 1] == CAR))) | |
2896 | 7115 ? MLINE : MCHAR); |
7116 else | |
7117 type = yank_type; | |
7118 | |
7 | 7119 /* |
7120 * Count the number of lines within the string | |
7121 */ | |
7122 newlines = 0; | |
5798 | 7123 if (str_list) |
7124 { | |
7125 for (ss = (char_u **) str; *ss != NULL; ++ss) | |
7 | 7126 ++newlines; |
5798 | 7127 } |
7128 else | |
7129 { | |
7130 for (i = 0; i < len; i++) | |
7131 if (str[i] == '\n') | |
7132 ++newlines; | |
7133 if (type == MCHAR || len == 0 || str[len - 1] != '\n') | |
7134 { | |
7135 extraline = 1; | |
7136 ++newlines; /* count extra newline at the end */ | |
7137 } | |
7138 if (y_ptr->y_size > 0 && y_ptr->y_type == MCHAR) | |
7139 { | |
7140 append = TRUE; | |
7141 --newlines; /* uncount newline when appending first line */ | |
7142 } | |
7 | 7143 } |
7144 | |
6807 | 7145 /* Without any lines make the register empty. */ |
7146 if (y_ptr->y_size + newlines == 0) | |
7147 { | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
7148 VIM_CLEAR(y_ptr->y_array); |
6807 | 7149 return; |
7150 } | |
7151 | |
7 | 7152 /* |
7153 * Allocate an array to hold the pointers to the new register lines. | |
7154 * If the register was not empty, move the existing lines to the new array. | |
7155 */ | |
7156 pp = (char_u **)lalloc_clear((y_ptr->y_size + newlines) | |
7157 * sizeof(char_u *), TRUE); | |
7158 if (pp == NULL) /* out of memory */ | |
7159 return; | |
7160 for (lnum = 0; lnum < y_ptr->y_size; ++lnum) | |
7161 pp[lnum] = y_ptr->y_array[lnum]; | |
7162 vim_free(y_ptr->y_array); | |
7163 y_ptr->y_array = pp; | |
7164 maxlen = 0; | |
7165 | |
7166 /* | |
7167 * Find the end of each line and save it into the array. | |
7168 */ | |
5798 | 7169 if (str_list) |
7170 { | |
7171 for (ss = (char_u **) str; *ss != NULL; ++ss, ++lnum) | |
7 | 7172 { |
5856 | 7173 i = (long)STRLEN(*ss); |
5798 | 7174 pp[lnum] = vim_strnsave(*ss, i); |
7175 if (i > maxlen) | |
7176 maxlen = i; | |
7 | 7177 } |
5798 | 7178 } |
7179 else | |
7180 { | |
7181 for (start = 0; start < len + extraline; start += i + 1) | |
7 | 7182 { |
5798 | 7183 for (i = start; i < len; ++i) /* find the end of the line */ |
7184 if (str[i] == '\n') | |
7185 break; | |
7186 i -= start; /* i is now length of line */ | |
7187 if (i > maxlen) | |
7188 maxlen = i; | |
7189 if (append) | |
7190 { | |
7191 --lnum; | |
7192 extra = (int)STRLEN(y_ptr->y_array[lnum]); | |
7193 } | |
7194 else | |
7195 extra = 0; | |
7196 s = alloc((unsigned)(i + extra + 1)); | |
7197 if (s == NULL) | |
7198 break; | |
7199 if (extra) | |
7200 mch_memmove(s, y_ptr->y_array[lnum], (size_t)extra); | |
7201 if (append) | |
7202 vim_free(y_ptr->y_array[lnum]); | |
7203 if (i) | |
7204 mch_memmove(s + extra, str + start, (size_t)i); | |
7205 extra += i; | |
7206 s[extra] = NUL; | |
7207 y_ptr->y_array[lnum++] = s; | |
7208 while (--extra >= 0) | |
7209 { | |
7210 if (*s == NUL) | |
7211 *s = '\n'; /* replace NUL with newline */ | |
7212 ++s; | |
7213 } | |
7214 append = FALSE; /* only first line is appended */ | |
7 | 7215 } |
7216 } | |
7217 y_ptr->y_type = type; | |
7218 y_ptr->y_size = lnum; | |
7219 if (type == MBLOCK) | |
7220 y_ptr->y_width = (blocklen < 0 ? maxlen - 1 : blocklen); | |
7221 else | |
7222 y_ptr->y_width = 0; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7223 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7224 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
|
7225 #endif |
7 | 7226 } |
7227 #endif /* FEAT_CLIPBOARD || FEAT_EVAL || PROTO */ | |
7228 | |
7229 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7230 clear_oparg(oparg_T *oap) |
7 | 7231 { |
7232 vim_memset(oap, 0, sizeof(oparg_T)); | |
7233 } | |
7234 | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7235 static varnumber_T line_count_info(char_u *line, varnumber_T *wc, varnumber_T *cc, varnumber_T limit, int eol_size); |
7 | 7236 |
7237 /* | |
161 | 7238 * Count the number of bytes, characters and "words" in a line. |
7 | 7239 * |
7240 * "Words" are counted by looking for boundaries between non-space and | |
7241 * space characters. (it seems to produce results that match 'wc'.) | |
7242 * | |
161 | 7243 * Return value is byte count; word count for the line is added to "*wc". |
7244 * Char count is added to "*cc". | |
7 | 7245 * |
7246 * The function will only examine the first "limit" characters in the | |
7247 * line, stopping if it encounters an end-of-line (NUL byte). In that | |
7248 * case, eol_size will be added to the character count to account for | |
7249 * the size of the EOL character. | |
7250 */ | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7251 static varnumber_T |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7252 line_count_info( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7253 char_u *line, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7254 varnumber_T *wc, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7255 varnumber_T *cc, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7256 varnumber_T limit, |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7257 int eol_size) |
7 | 7258 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7259 varnumber_T i; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7260 varnumber_T words = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7261 varnumber_T chars = 0; |
7 | 7262 int is_word = 0; |
7263 | |
3626 | 7264 for (i = 0; i < limit && line[i] != NUL; ) |
7 | 7265 { |
7266 if (is_word) | |
7267 { | |
7268 if (vim_isspace(line[i])) | |
7269 { | |
7270 words++; | |
7271 is_word = 0; | |
7272 } | |
7273 } | |
7274 else if (!vim_isspace(line[i])) | |
7275 is_word = 1; | |
161 | 7276 ++chars; |
7277 #ifdef FEAT_MBYTE | |
474 | 7278 i += (*mb_ptr2len)(line + i); |
161 | 7279 #else |
7280 ++i; | |
7281 #endif | |
7 | 7282 } |
7283 | |
7284 if (is_word) | |
7285 words++; | |
7286 *wc += words; | |
7287 | |
7288 /* Add eol_size if the end of line was reached before hitting limit. */ | |
2996 | 7289 if (i < limit && line[i] == NUL) |
161 | 7290 { |
7 | 7291 i += eol_size; |
161 | 7292 chars += eol_size; |
7293 } | |
7294 *cc += chars; | |
7 | 7295 return i; |
7296 } | |
7297 | |
7298 /* | |
7299 * Give some info about the position of the cursor (for "g CTRL-G"). | |
7300 * In Visual mode, give some info about the selected region. (In this case, | |
7301 * 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
|
7302 * When "dict" is not NULL store the info there instead of showing it. |
7 | 7303 */ |
7304 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7305 cursor_pos_info(dict_T *dict) |
7 | 7306 { |
7307 char_u *p; | |
274 | 7308 char_u buf1[50]; |
7309 char_u buf2[40]; | |
7 | 7310 linenr_T lnum; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7311 varnumber_T byte_count = 0; |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7312 #ifdef FEAT_MBYTE |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7313 varnumber_T bom_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7314 #endif |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7315 varnumber_T byte_count_cursor = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7316 varnumber_T char_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7317 varnumber_T char_count_cursor = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7318 varnumber_T word_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7319 varnumber_T word_count_cursor = 0; |
7 | 7320 int eol_size; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7321 varnumber_T last_check = 100000L; |
7 | 7322 long line_count_selected = 0; |
7323 pos_T min_pos, max_pos; | |
7324 oparg_T oparg; | |
7325 struct block_def bd; | |
7326 | |
7327 /* | |
7328 * Compute the length of the file in characters. | |
7329 */ | |
7330 if (curbuf->b_ml.ml_flags & ML_EMPTY) | |
7331 { | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7332 if (dict == NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7333 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7334 MSG(_(no_lines_msg)); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7335 return; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7336 } |
7 | 7337 } |
7338 else | |
7339 { | |
7340 if (get_fileformat(curbuf) == EOL_DOS) | |
7341 eol_size = 2; | |
7342 else | |
7343 eol_size = 1; | |
7344 | |
7345 if (VIsual_active) | |
7346 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
7347 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 7348 { |
7349 min_pos = VIsual; | |
7350 max_pos = curwin->w_cursor; | |
7351 } | |
7352 else | |
7353 { | |
7354 min_pos = curwin->w_cursor; | |
7355 max_pos = VIsual; | |
7356 } | |
7357 if (*p_sel == 'e' && max_pos.col > 0) | |
7358 --max_pos.col; | |
7359 | |
7360 if (VIsual_mode == Ctrl_V) | |
7361 { | |
1866 | 7362 #ifdef FEAT_LINEBREAK |
7363 char_u * saved_sbr = p_sbr; | |
7364 | |
7365 /* Make 'sbr' empty for a moment to get the correct size. */ | |
7366 p_sbr = empty_option; | |
7367 #endif | |
7 | 7368 oparg.is_VIsual = 1; |
7369 oparg.block_mode = TRUE; | |
7370 oparg.op_type = OP_NOP; | |
7371 getvcols(curwin, &min_pos, &max_pos, | |
688 | 7372 &oparg.start_vcol, &oparg.end_vcol); |
1866 | 7373 #ifdef FEAT_LINEBREAK |
7374 p_sbr = saved_sbr; | |
7375 #endif | |
688 | 7376 if (curwin->w_curswant == MAXCOL) |
7377 oparg.end_vcol = MAXCOL; | |
7 | 7378 /* Swap the start, end vcol if needed */ |
7379 if (oparg.end_vcol < oparg.start_vcol) | |
7380 { | |
7381 oparg.end_vcol += oparg.start_vcol; | |
7382 oparg.start_vcol = oparg.end_vcol - oparg.start_vcol; | |
7383 oparg.end_vcol -= oparg.start_vcol; | |
7384 } | |
7385 } | |
7386 line_count_selected = max_pos.lnum - min_pos.lnum + 1; | |
7387 } | |
7388 | |
7389 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) | |
7390 { | |
7391 /* Check for a CTRL-C every 100000 characters. */ | |
161 | 7392 if (byte_count > last_check) |
7 | 7393 { |
7394 ui_breakcheck(); | |
7395 if (got_int) | |
7396 return; | |
161 | 7397 last_check = byte_count + 100000L; |
7 | 7398 } |
7399 | |
7400 /* Do extra processing for VIsual mode. */ | |
7401 if (VIsual_active | |
7402 && lnum >= min_pos.lnum && lnum <= max_pos.lnum) | |
7403 { | |
45 | 7404 char_u *s = NULL; |
7405 long len = 0L; | |
7406 | |
7 | 7407 switch (VIsual_mode) |
7408 { | |
7409 case Ctrl_V: | |
5735 | 7410 #ifdef FEAT_VIRTUALEDIT |
7 | 7411 virtual_op = virtual_active(); |
5735 | 7412 #endif |
7 | 7413 block_prep(&oparg, &bd, lnum, 0); |
5735 | 7414 #ifdef FEAT_VIRTUALEDIT |
7 | 7415 virtual_op = MAYBE; |
5735 | 7416 #endif |
45 | 7417 s = bd.textstart; |
7418 len = (long)bd.textlen; | |
7 | 7419 break; |
7420 case 'V': | |
45 | 7421 s = ml_get(lnum); |
7422 len = MAXCOL; | |
7 | 7423 break; |
7424 case 'v': | |
7425 { | |
7426 colnr_T start_col = (lnum == min_pos.lnum) | |
7427 ? min_pos.col : 0; | |
7428 colnr_T end_col = (lnum == max_pos.lnum) | |
7429 ? max_pos.col - start_col + 1 : MAXCOL; | |
7430 | |
45 | 7431 s = ml_get(lnum) + start_col; |
7432 len = end_col; | |
7 | 7433 } |
7434 break; | |
7435 } | |
45 | 7436 if (s != NULL) |
7437 { | |
161 | 7438 byte_count_cursor += line_count_info(s, &word_count_cursor, |
7439 &char_count_cursor, len, eol_size); | |
45 | 7440 if (lnum == curbuf->b_ml.ml_line_count |
7441 && !curbuf->b_p_eol | |
6933 | 7442 && (curbuf->b_p_bin || !curbuf->b_p_fixeol) |
50 | 7443 && (long)STRLEN(s) < len) |
161 | 7444 byte_count_cursor -= eol_size; |
45 | 7445 } |
7 | 7446 } |
7447 else | |
7448 { | |
7449 /* In non-visual mode, check for the line the cursor is on */ | |
7450 if (lnum == curwin->w_cursor.lnum) | |
7451 { | |
7452 word_count_cursor += word_count; | |
161 | 7453 char_count_cursor += char_count; |
7454 byte_count_cursor = byte_count + | |
7455 line_count_info(ml_get(lnum), | |
7456 &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
|
7457 (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
|
7458 eol_size); |
7 | 7459 } |
7460 } | |
7461 /* Add to the running totals */ | |
161 | 7462 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
|
7463 &char_count, (varnumber_T)MAXCOL, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7464 eol_size); |
7 | 7465 } |
7466 | |
7467 /* Correction for when last line doesn't have an EOL. */ | |
6933 | 7468 if (!curbuf->b_p_eol && (curbuf->b_p_bin || !curbuf->b_p_fixeol)) |
161 | 7469 byte_count -= eol_size; |
7 | 7470 |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7471 if (dict == NULL) |
7 | 7472 { |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7473 if (VIsual_active) |
7 | 7474 { |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7475 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
|
7476 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7477 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
|
7478 &max_pos.col); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7479 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
|
7480 (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
|
7481 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7482 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7483 buf1[0] = NUL; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7484 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7485 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
|
7486 && char_count == byte_count) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7487 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7488 _("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
|
7489 buf1, line_count_selected, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7490 (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
|
7491 word_count_cursor, word_count, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7492 byte_count_cursor, byte_count); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7493 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7494 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7495 _("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
|
7496 buf1, line_count_selected, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7497 (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
|
7498 word_count_cursor, word_count, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7499 char_count_cursor, char_count, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7500 byte_count_cursor, byte_count); |
7 | 7501 } |
7502 else | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7503 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7504 p = ml_get_curline(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7505 validate_virtcol(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7506 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
|
7507 (int)curwin->w_virtcol + 1); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7508 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
|
7509 linetabsize(p)); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7510 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7511 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
|
7512 && char_count == byte_count) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7513 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7514 _("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
|
7515 (char *)buf1, (char *)buf2, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7516 (long)curwin->w_cursor.lnum, |
7 | 7517 (long)curbuf->b_ml.ml_line_count, |
7518 word_count_cursor, word_count, | |
161 | 7519 byte_count_cursor, byte_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7520 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7521 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7522 _("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
|
7523 (char *)buf1, (char *)buf2, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7524 (long)curwin->w_cursor.lnum, |
161 | 7525 (long)curbuf->b_ml.ml_line_count, |
7526 word_count_cursor, word_count, | |
7527 char_count_cursor, char_count, | |
7528 byte_count_cursor, byte_count); | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7529 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7530 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7531 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7532 #ifdef FEAT_MBYTE |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7533 bom_count = bomb_size(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7534 if (bom_count > 0) |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7535 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
|
7536 _("(+%ld for BOM)"), bom_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7537 #endif |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7538 if (dict == NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7539 { |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7540 /* 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
|
7541 p = p_shm; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7542 p_shm = (char_u *)""; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7543 msg(IObuff); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7544 p_shm = p; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7545 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7546 } |
7484
1fe988587423
commit https://github.com/vim/vim/commit/718272a7e13c71095ce07eb3b3d5e1f9790a6991
Christian Brabandt <cb@256bit.org>
parents:
7480
diff
changeset
|
7547 #if defined(FEAT_EVAL) |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7548 if (dict != NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7549 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7550 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
|
7551 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
|
7552 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
|
7553 # ifdef FEAT_MBYTE |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7554 + bom_count |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7555 # endif |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7556 , NULL); |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7557 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
|
7558 byte_count_cursor, NULL); |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7559 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
|
7560 char_count_cursor, NULL); |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7561 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
|
7562 word_count_cursor, NULL); |
7 | 7563 } |
7484
1fe988587423
commit https://github.com/vim/vim/commit/718272a7e13c71095ce07eb3b3d5e1f9790a6991
Christian Brabandt <cb@256bit.org>
parents:
7480
diff
changeset
|
7564 #endif |
7 | 7565 } |