Mercurial > vim
annotate src/ops.c @ 11826:bf8cfdcdbdd8 v8.0.0793
patch 8.0.0793: using wrong terminal name for terminal window
commit https://github.com/vim/vim/commit/93723a4ef18f260b82d89759db2f1eeae730c4ec
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Jul 28 15:55:32 2017 +0200
patch 8.0.0793: using wrong terminal name for terminal window
Problem: Using wrong terminal name for terminal window.
Solution: When 'term' starts with "xterm" use it for $TERM in a terminal
window.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 28 Jul 2017 16:00:04 +0200 |
parents | 570f00932da8 |
children | 66b677c77467 |
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) |
186 if (opchars[i][0] == char1 && opchars[i][1] == char2) | |
187 break; | |
188 return i; | |
189 } | |
190 | |
191 /* | |
192 * Return TRUE if operator "op" always works on whole lines. | |
193 */ | |
194 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
195 op_on_lines(int op) |
7 | 196 { |
197 return opchars[op][2]; | |
198 } | |
199 | |
200 /* | |
201 * Get first operator command character. | |
202 * Returns 'g' or 'z' if there is another command character. | |
203 */ | |
204 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
205 get_op_char(int optype) |
7 | 206 { |
207 return opchars[optype][0]; | |
208 } | |
209 | |
210 /* | |
211 * Get second operator command character. | |
212 */ | |
213 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
214 get_extra_op_char(int optype) |
7 | 215 { |
216 return opchars[optype][1]; | |
217 } | |
218 | |
219 /* | |
220 * op_shift - handle a shift operation | |
221 */ | |
222 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
223 op_shift(oparg_T *oap, int curs_top, int amount) |
7 | 224 { |
225 long i; | |
226 int first_char; | |
227 char_u *s; | |
228 int block_col = 0; | |
229 | |
230 if (u_save((linenr_T)(oap->start.lnum - 1), | |
231 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
232 return; | |
233 | |
234 if (oap->block_mode) | |
235 block_col = curwin->w_cursor.col; | |
236 | |
237 for (i = oap->line_count; --i >= 0; ) | |
238 { | |
239 first_char = *ml_get_curline(); | |
240 if (first_char == NUL) /* empty line */ | |
241 curwin->w_cursor.col = 0; | |
242 #ifdef FEAT_VISUALEXTRA | |
243 else if (oap->block_mode) | |
244 shift_block(oap, amount); | |
245 #endif | |
246 else | |
247 /* Move the line right if it doesn't start with '#', 'smartindent' | |
248 * isn't set or 'cindent' isn't set or '#' isn't in 'cino'. */ | |
249 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) | |
250 if (first_char != '#' || !preprocs_left()) | |
251 #endif | |
252 { | |
1516 | 253 shift_line(oap->op_type == OP_LSHIFT, p_sr, amount, FALSE); |
7 | 254 } |
255 ++curwin->w_cursor.lnum; | |
256 } | |
257 | |
258 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); | |
259 if (oap->block_mode) | |
260 { | |
261 curwin->w_cursor.lnum = oap->start.lnum; | |
262 curwin->w_cursor.col = block_col; | |
263 } | |
5735 | 264 else if (curs_top) /* put cursor on first line, for ">>" */ |
7 | 265 { |
266 curwin->w_cursor.lnum = oap->start.lnum; | |
267 beginline(BL_SOL | BL_FIX); /* shift_line() may have set cursor.col */ | |
268 } | |
269 else | |
270 --curwin->w_cursor.lnum; /* put cursor on last line, for ":>" */ | |
271 | |
10486
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
272 #ifdef FEAT_FOLDING |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
273 /* 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
|
274 foldOpenCursor(); |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
275 #endif |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
276 |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
277 |
7 | 278 if (oap->line_count > p_report) |
279 { | |
280 if (oap->op_type == OP_RSHIFT) | |
281 s = (char_u *)">"; | |
282 else | |
283 s = (char_u *)"<"; | |
284 if (oap->line_count == 1) | |
285 { | |
286 if (amount == 1) | |
287 sprintf((char *)IObuff, _("1 line %sed 1 time"), s); | |
288 else | |
289 sprintf((char *)IObuff, _("1 line %sed %d times"), s, amount); | |
290 } | |
291 else | |
292 { | |
293 if (amount == 1) | |
294 sprintf((char *)IObuff, _("%ld lines %sed 1 time"), | |
295 oap->line_count, s); | |
296 else | |
297 sprintf((char *)IObuff, _("%ld lines %sed %d times"), | |
298 oap->line_count, s, amount); | |
299 } | |
300 msg(IObuff); | |
301 } | |
302 | |
303 /* | |
304 * Set "'[" and "']" marks. | |
305 */ | |
306 curbuf->b_op_start = oap->start; | |
307 curbuf->b_op_end.lnum = oap->end.lnum; | |
308 curbuf->b_op_end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
309 if (curbuf->b_op_end.col > 0) | |
310 --curbuf->b_op_end.col; | |
311 } | |
312 | |
313 /* | |
314 * shift the current line one shiftwidth left (if left != 0) or right | |
315 * leaves cursor on first blank in the line | |
316 */ | |
317 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
318 shift_line( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
319 int left, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
320 int round, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
321 int amount, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
322 int call_changed_bytes) /* call changed_bytes() */ |
7 | 323 { |
324 int count; | |
325 int i, j; | |
5438 | 326 int p_sw = (int)get_sw_value(curbuf); |
7 | 327 |
328 count = get_indent(); /* get current indent */ | |
329 | |
330 if (round) /* round off indent */ | |
331 { | |
332 i = count / p_sw; /* number of p_sw rounded down */ | |
333 j = count % p_sw; /* extra spaces */ | |
334 if (j && left) /* first remove extra spaces */ | |
335 --amount; | |
336 if (left) | |
337 { | |
338 i -= amount; | |
339 if (i < 0) | |
340 i = 0; | |
341 } | |
342 else | |
343 i += amount; | |
344 count = i * p_sw; | |
345 } | |
346 else /* original vi indent */ | |
347 { | |
348 if (left) | |
349 { | |
350 count -= p_sw * amount; | |
351 if (count < 0) | |
352 count = 0; | |
353 } | |
354 else | |
355 count += p_sw * amount; | |
356 } | |
357 | |
358 /* Set new indent */ | |
359 #ifdef FEAT_VREPLACE | |
360 if (State & VREPLACE_FLAG) | |
1516 | 361 change_indent(INDENT_SET, count, FALSE, NUL, call_changed_bytes); |
7 | 362 else |
363 #endif | |
1516 | 364 (void)set_indent(count, call_changed_bytes ? SIN_CHANGED : 0); |
7 | 365 } |
366 | |
367 #if defined(FEAT_VISUALEXTRA) || defined(PROTO) | |
368 /* | |
369 * Shift one line of the current block one shiftwidth right or left. | |
370 * Leaves cursor on first character in block. | |
371 */ | |
372 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
373 shift_block(oparg_T *oap, int amount) |
7 | 374 { |
375 int left = (oap->op_type == OP_LSHIFT); | |
376 int oldstate = State; | |
1839 | 377 int total; |
378 char_u *newp, *oldp; | |
7 | 379 int oldcol = curwin->w_cursor.col; |
5438 | 380 int p_sw = (int)get_sw_value(curbuf); |
7 | 381 int p_ts = (int)curbuf->b_p_ts; |
382 struct block_def bd; | |
383 int incr; | |
1839 | 384 colnr_T ws_vcol; |
7 | 385 int i = 0, j = 0; |
386 int len; | |
387 #ifdef FEAT_RIGHTLEFT | |
388 int old_p_ri = p_ri; | |
389 | |
4352 | 390 p_ri = 0; /* don't want revins in indent */ |
7 | 391 #endif |
392 | |
393 State = INSERT; /* don't want REPLACE for State */ | |
394 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); | |
395 if (bd.is_short) | |
396 return; | |
397 | |
398 /* total is number of screen columns to be inserted/removed */ | |
399 total = amount * p_sw; | |
400 oldp = ml_get_curline(); | |
401 | |
402 if (!left) | |
403 { | |
404 /* | |
405 * 1. Get start vcol | |
406 * 2. Total ws vcols | |
407 * 3. Divvy into TABs & spp | |
408 * 4. Construct new string | |
409 */ | |
410 total += bd.pre_whitesp; /* all virtual WS upto & incl a split TAB */ | |
411 ws_vcol = bd.start_vcol - bd.pre_whitesp; | |
412 if (bd.startspaces) | |
413 { | |
414 #ifdef FEAT_MBYTE | |
415 if (has_mbyte) | |
8399
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
416 { |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
417 if ((*mb_ptr2len)(bd.textstart) == 1) |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
418 ++bd.textstart; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
419 else |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
420 { |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
421 ws_vcol = 0; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
422 bd.startspaces = 0; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
423 } |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
424 } |
1995 | 425 else |
426 #endif | |
427 ++bd.textstart; | |
7 | 428 } |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
429 for ( ; VIM_ISWHITE(*bd.textstart); ) |
7 | 430 { |
5995 | 431 /* TODO: is passing bd.textstart for start of the line OK? */ |
432 incr = lbr_chartabsize_adv(bd.textstart, &bd.textstart, | |
433 (colnr_T)(bd.start_vcol)); | |
7 | 434 total += incr; |
435 bd.start_vcol += incr; | |
436 } | |
437 /* OK, now total=all the VWS reqd, and textstart points at the 1st | |
438 * non-ws char in the block. */ | |
439 if (!curbuf->b_p_et) | |
440 i = ((ws_vcol % p_ts) + total) / p_ts; /* number of tabs */ | |
441 if (i) | |
442 j = ((ws_vcol % p_ts) + total) % p_ts; /* number of spp */ | |
443 else | |
444 j = total; | |
445 /* if we're splitting a TAB, allow for it */ | |
446 bd.textcol -= bd.pre_whitesp_c - (bd.startspaces != 0); | |
447 len = (int)STRLEN(bd.textstart) + 1; | |
448 newp = alloc_check((unsigned)(bd.textcol + i + j + len)); | |
449 if (newp == NULL) | |
450 return; | |
451 vim_memset(newp, NUL, (size_t)(bd.textcol + i + j + len)); | |
452 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
6929 | 453 vim_memset(newp + bd.textcol, TAB, (size_t)i); |
454 vim_memset(newp + bd.textcol + i, ' ', (size_t)j); | |
7 | 455 /* the end */ |
456 mch_memmove(newp + bd.textcol + i + j, bd.textstart, (size_t)len); | |
457 } | |
458 else /* left */ | |
459 { | |
1839 | 460 colnr_T destination_col; /* column to which text in block will |
461 be shifted */ | |
462 char_u *verbatim_copy_end; /* end of the part of the line which is | |
463 copied verbatim */ | |
464 colnr_T verbatim_copy_width;/* the (displayed) width of this part | |
465 of line */ | |
466 unsigned fill; /* nr of spaces that replace a TAB */ | |
467 unsigned new_line_len; /* the length of the line after the | |
468 block shift */ | |
469 size_t block_space_width; | |
470 size_t shift_amount; | |
471 char_u *non_white = bd.textstart; | |
472 colnr_T non_white_col; | |
473 | |
474 /* | |
475 * Firstly, let's find the first non-whitespace character that is | |
476 * displayed after the block's start column and the character's column | |
477 * number. Also, let's calculate the width of all the whitespace | |
478 * characters that are displayed in the block and precede the searched | |
479 * non-whitespace character. | |
480 */ | |
481 | |
482 /* If "bd.startspaces" is set, "bd.textstart" points to the character, | |
483 * the part of which is displayed at the block's beginning. Let's start | |
484 * searching from the next character. */ | |
485 if (bd.startspaces) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
486 MB_PTR_ADV(non_white); |
1839 | 487 |
488 /* The character's column is in "bd.start_vcol". */ | |
489 non_white_col = bd.start_vcol; | |
490 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
491 while (VIM_ISWHITE(*non_white)) |
7 | 492 { |
5995 | 493 incr = lbr_chartabsize_adv(bd.textstart, &non_white, non_white_col); |
1839 | 494 non_white_col += incr; |
7 | 495 } |
1839 | 496 |
497 block_space_width = non_white_col - oap->start_vcol; | |
498 /* We will shift by "total" or "block_space_width", whichever is less. | |
499 */ | |
1860 | 500 shift_amount = (block_space_width < (size_t)total |
501 ? block_space_width : (size_t)total); | |
1839 | 502 |
503 /* The column to which we will shift the text. */ | |
1860 | 504 destination_col = (colnr_T)(non_white_col - shift_amount); |
1839 | 505 |
506 /* Now let's find out how much of the beginning of the line we can | |
507 * reuse without modification. */ | |
508 verbatim_copy_end = bd.textstart; | |
509 verbatim_copy_width = bd.start_vcol; | |
510 | |
511 /* If "bd.startspaces" is set, "bd.textstart" points to the character | |
512 * preceding the block. We have to subtract its width to obtain its | |
513 * column number. */ | |
514 if (bd.startspaces) | |
515 verbatim_copy_width -= bd.start_char_vcols; | |
516 while (verbatim_copy_width < destination_col) | |
7 | 517 { |
5995 | 518 char_u *line = verbatim_copy_end; |
519 | |
520 /* TODO: is passing verbatim_copy_end for start of the line OK? */ | |
521 incr = lbr_chartabsize(line, verbatim_copy_end, | |
522 verbatim_copy_width); | |
1839 | 523 if (verbatim_copy_width + incr > destination_col) |
524 break; | |
525 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
|
526 MB_PTR_ADV(verbatim_copy_end); |
7 | 527 } |
528 | |
1839 | 529 /* If "destination_col" is different from the width of the initial |
530 * part of the line that will be copied, it means we encountered a tab | |
531 * character, which we will have to partly replace with spaces. */ | |
532 fill = destination_col - verbatim_copy_width; | |
533 | |
534 /* The replacement line will consist of: | |
535 * - the beginning of the original line up to "verbatim_copy_end", | |
536 * - "fill" number of spaces, | |
537 * - the rest of the line, pointed to by non_white. */ | |
538 new_line_len = (unsigned)(verbatim_copy_end - oldp) | |
539 + fill | |
540 + (unsigned)STRLEN(non_white) + 1; | |
541 | |
542 newp = alloc_check(new_line_len); | |
7 | 543 if (newp == NULL) |
544 return; | |
1839 | 545 mch_memmove(newp, oldp, (size_t)(verbatim_copy_end - oldp)); |
6929 | 546 vim_memset(newp + (verbatim_copy_end - oldp), ' ', (size_t)fill); |
1839 | 547 STRMOVE(newp + (verbatim_copy_end - oldp) + fill, non_white); |
7 | 548 } |
549 /* replace the line */ | |
550 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
551 changed_bytes(curwin->w_cursor.lnum, (colnr_T)bd.textcol); | |
552 State = oldstate; | |
553 curwin->w_cursor.col = oldcol; | |
554 #ifdef FEAT_RIGHTLEFT | |
555 p_ri = old_p_ri; | |
556 #endif | |
557 } | |
558 #endif | |
559 | |
560 #ifdef FEAT_VISUALEXTRA | |
561 /* | |
562 * Insert string "s" (b_insert ? before : after) block :AKelly | |
563 * Caller must prepare for undo. | |
564 */ | |
565 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
566 block_insert( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
567 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
568 char_u *s, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
569 int b_insert, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
570 struct block_def *bdp) |
7 | 571 { |
572 int p_ts; | |
573 int count = 0; /* extra spaces to replace a cut TAB */ | |
574 int spaces = 0; /* non-zero if cutting a TAB */ | |
575 colnr_T offset; /* pointer along new line */ | |
576 unsigned s_len; /* STRLEN(s) */ | |
577 char_u *newp, *oldp; /* new, old lines */ | |
578 linenr_T lnum; /* loop var */ | |
579 int oldstate = State; | |
580 | |
581 State = INSERT; /* don't want REPLACE for State */ | |
582 s_len = (unsigned)STRLEN(s); | |
583 | |
584 for (lnum = oap->start.lnum + 1; lnum <= oap->end.lnum; lnum++) | |
585 { | |
586 block_prep(oap, bdp, lnum, TRUE); | |
587 if (bdp->is_short && b_insert) | |
588 continue; /* OP_INSERT, line ends before block start */ | |
589 | |
590 oldp = ml_get(lnum); | |
591 | |
592 if (b_insert) | |
593 { | |
594 p_ts = bdp->start_char_vcols; | |
595 spaces = bdp->startspaces; | |
596 if (spaces != 0) | |
597 count = p_ts - 1; /* we're cutting a TAB */ | |
598 offset = bdp->textcol; | |
599 } | |
600 else /* append */ | |
601 { | |
602 p_ts = bdp->end_char_vcols; | |
603 if (!bdp->is_short) /* spaces = padding after block */ | |
604 { | |
605 spaces = (bdp->endspaces ? p_ts - bdp->endspaces : 0); | |
606 if (spaces != 0) | |
607 count = p_ts - 1; /* we're cutting a TAB */ | |
608 offset = bdp->textcol + bdp->textlen - (spaces != 0); | |
609 } | |
610 else /* spaces = padding to block edge */ | |
611 { | |
612 /* if $ used, just append to EOL (ie spaces==0) */ | |
613 if (!bdp->is_MAX) | |
614 spaces = (oap->end_vcol - bdp->end_vcol) + 1; | |
615 count = spaces; | |
616 offset = bdp->textcol + bdp->textlen; | |
617 } | |
618 } | |
619 | |
6140 | 620 #ifdef FEAT_MBYTE |
621 if (has_mbyte && spaces > 0) | |
622 { | |
6460 | 623 int off; |
624 | |
6140 | 625 /* Avoid starting halfway a multi-byte character. */ |
626 if (b_insert) | |
627 { | |
6460 | 628 off = (*mb_head_off)(oldp, oldp + offset + spaces); |
6140 | 629 } |
630 else | |
631 { | |
6460 | 632 off = (*mb_off_next)(oldp, oldp + offset); |
6140 | 633 offset += off; |
634 } | |
6460 | 635 spaces -= off; |
636 count -= off; | |
6140 | 637 } |
638 #endif | |
639 | |
7 | 640 newp = alloc_check((unsigned)(STRLEN(oldp)) + s_len + count + 1); |
641 if (newp == NULL) | |
642 continue; | |
643 | |
644 /* copy up to shifted part */ | |
645 mch_memmove(newp, oldp, (size_t)(offset)); | |
646 oldp += offset; | |
647 | |
648 /* insert pre-padding */ | |
6929 | 649 vim_memset(newp + offset, ' ', (size_t)spaces); |
7 | 650 |
651 /* copy the new text */ | |
652 mch_memmove(newp + offset + spaces, s, (size_t)s_len); | |
653 offset += s_len; | |
654 | |
655 if (spaces && !bdp->is_short) | |
656 { | |
657 /* insert post-padding */ | |
6929 | 658 vim_memset(newp + offset + spaces, ' ', (size_t)(p_ts - spaces)); |
7 | 659 /* We're splitting a TAB, don't copy it. */ |
660 oldp++; | |
661 /* We allowed for that TAB, remember this now */ | |
662 count++; | |
663 } | |
664 | |
665 if (spaces > 0) | |
666 offset += count; | |
1622 | 667 STRMOVE(newp + offset, oldp); |
7 | 668 |
669 ml_replace(lnum, newp, FALSE); | |
670 | |
671 if (lnum == oap->end.lnum) | |
672 { | |
673 /* Set "']" mark to the end of the block instead of the end of | |
674 * the insert in the first line. */ | |
675 curbuf->b_op_end.lnum = oap->end.lnum; | |
676 curbuf->b_op_end.col = offset; | |
677 } | |
678 } /* for all lnum */ | |
679 | |
680 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); | |
681 | |
682 State = oldstate; | |
683 } | |
684 #endif | |
685 | |
686 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) || defined(PROTO) | |
687 /* | |
688 * op_reindent - handle reindenting a block of lines. | |
689 */ | |
690 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
691 op_reindent(oparg_T *oap, int (*how)(void)) |
7 | 692 { |
693 long i; | |
694 char_u *l; | |
6971 | 695 int amount; |
7 | 696 linenr_T first_changed = 0; |
697 linenr_T last_changed = 0; | |
698 linenr_T start_lnum = curwin->w_cursor.lnum; | |
699 | |
216 | 700 /* Don't even try when 'modifiable' is off. */ |
701 if (!curbuf->b_p_ma) | |
702 { | |
703 EMSG(_(e_modifiable)); | |
704 return; | |
705 } | |
706 | |
7 | 707 for (i = oap->line_count; --i >= 0 && !got_int; ) |
708 { | |
709 /* it's a slow thing to do, so give feedback so there's no worry that | |
710 * the computer's just hung. */ | |
711 | |
712 if (i > 1 | |
713 && (i % 50 == 0 || i == oap->line_count - 1) | |
714 && oap->line_count > p_report) | |
715 smsg((char_u *)_("%ld lines to indent... "), i); | |
716 | |
717 /* | |
718 * Be vi-compatible: For lisp indenting the first line is not | |
719 * indented, unless there is only one line. | |
720 */ | |
721 #ifdef FEAT_LISP | |
722 if (i != oap->line_count - 1 || oap->line_count == 1 | |
723 || how != get_lisp_indent) | |
724 #endif | |
725 { | |
726 l = skipwhite(ml_get_curline()); | |
727 if (*l == NUL) /* empty or blank line */ | |
6971 | 728 amount = 0; |
7 | 729 else |
6971 | 730 amount = how(); /* get the indent for this line */ |
731 | |
732 if (amount >= 0 && set_indent(amount, SIN_UNDO)) | |
7 | 733 { |
734 /* did change the indent, call changed_lines() later */ | |
735 if (first_changed == 0) | |
736 first_changed = curwin->w_cursor.lnum; | |
737 last_changed = curwin->w_cursor.lnum; | |
738 } | |
739 } | |
740 ++curwin->w_cursor.lnum; | |
1550 | 741 curwin->w_cursor.col = 0; /* make sure it's valid */ |
7 | 742 } |
743 | |
744 /* put cursor on first non-blank of indented line */ | |
745 curwin->w_cursor.lnum = start_lnum; | |
746 beginline(BL_SOL | BL_FIX); | |
747 | |
748 /* Mark changed lines so that they will be redrawn. When Visual | |
749 * highlighting was present, need to continue until the last line. When | |
750 * there is no change still need to remove the Visual highlighting. */ | |
751 if (last_changed != 0) | |
752 changed_lines(first_changed, 0, | |
753 oap->is_VIsual ? start_lnum + oap->line_count : | |
754 last_changed + 1, 0L); | |
755 else if (oap->is_VIsual) | |
756 redraw_curbuf_later(INVERTED); | |
757 | |
758 if (oap->line_count > p_report) | |
759 { | |
760 i = oap->line_count - (i + 1); | |
761 if (i == 1) | |
762 MSG(_("1 line indented ")); | |
763 else | |
764 smsg((char_u *)_("%ld lines indented "), i); | |
765 } | |
766 /* set '[ and '] marks */ | |
767 curbuf->b_op_start = oap->start; | |
768 curbuf->b_op_end = oap->end; | |
769 } | |
770 #endif /* defined(FEAT_LISP) || defined(FEAT_CINDENT) */ | |
771 | |
772 #if defined(FEAT_EVAL) || defined(PROTO) | |
773 /* | |
774 * Keep the last expression line here, for repeating. | |
775 */ | |
776 static char_u *expr_line = NULL; | |
777 | |
778 /* | |
779 * Get an expression for the "\"=expr1" or "CTRL-R =expr1" | |
780 * Returns '=' when OK, NUL otherwise. | |
781 */ | |
782 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
783 get_expr_register(void) |
7 | 784 { |
785 char_u *new_line; | |
786 | |
787 new_line = getcmdline('=', 0L, 0); | |
788 if (new_line == NULL) | |
789 return NUL; | |
790 if (*new_line == NUL) /* use previous line */ | |
791 vim_free(new_line); | |
792 else | |
793 set_expr_line(new_line); | |
794 return '='; | |
795 } | |
796 | |
797 /* | |
798 * Set the expression for the '=' register. | |
799 * Argument must be an allocated string. | |
800 */ | |
801 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
802 set_expr_line(char_u *new_line) |
7 | 803 { |
804 vim_free(expr_line); | |
805 expr_line = new_line; | |
806 } | |
807 | |
808 /* | |
809 * Get the result of the '=' register expression. | |
810 * Returns a pointer to allocated memory, or NULL for failure. | |
811 */ | |
812 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
813 get_expr_line(void) |
7 | 814 { |
815 char_u *expr_copy; | |
816 char_u *rv; | |
994 | 817 static int nested = 0; |
7 | 818 |
819 if (expr_line == NULL) | |
820 return NULL; | |
821 | |
822 /* Make a copy of the expression, because evaluating it may cause it to be | |
823 * changed. */ | |
824 expr_copy = vim_strsave(expr_line); | |
825 if (expr_copy == NULL) | |
826 return NULL; | |
827 | |
994 | 828 /* When we are invoked recursively limit the evaluation to 10 levels. |
829 * Then return the string as-is. */ | |
830 if (nested >= 10) | |
831 return expr_copy; | |
832 | |
833 ++nested; | |
714 | 834 rv = eval_to_string(expr_copy, NULL, TRUE); |
994 | 835 --nested; |
7 | 836 vim_free(expr_copy); |
837 return rv; | |
838 } | |
283 | 839 |
840 /* | |
841 * Get the '=' register expression itself, without evaluating it. | |
842 */ | |
843 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
844 get_expr_line_src(void) |
283 | 845 { |
846 if (expr_line == NULL) | |
847 return NULL; | |
848 return vim_strsave(expr_line); | |
849 } | |
7 | 850 #endif /* FEAT_EVAL */ |
851 | |
852 /* | |
853 * Check if 'regname' is a valid name of a yank register. | |
854 * Note: There is no check for 0 (default register), caller should do this | |
855 */ | |
856 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
857 valid_yank_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
858 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
859 int writing) /* if TRUE check for writable registers */ |
7 | 860 { |
861 if ( (regname > 0 && ASCII_ISALNUM(regname)) | |
862 || (!writing && vim_strchr((char_u *) | |
863 #ifdef FEAT_EVAL | |
6557 | 864 "/.%:=" |
7 | 865 #else |
6557 | 866 "/.%:" |
7 | 867 #endif |
868 , regname) != NULL) | |
6557 | 869 || regname == '#' |
7 | 870 || regname == '"' |
871 || regname == '-' | |
872 || regname == '_' | |
873 #ifdef FEAT_CLIPBOARD | |
874 || regname == '*' | |
875 || regname == '+' | |
876 #endif | |
877 #ifdef FEAT_DND | |
878 || (!writing && regname == '~') | |
879 #endif | |
880 ) | |
881 return TRUE; | |
882 return FALSE; | |
883 } | |
884 | |
885 /* | |
886 * Set y_current and y_append, according to the value of "regname". | |
887 * Cannot handle the '_' register. | |
140 | 888 * Must only be called with a valid register name! |
7 | 889 * |
890 * If regname is 0 and writing, use register 0 | |
891 * If regname is 0 and reading, use previous register | |
892 */ | |
15 | 893 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
894 get_yank_register(int regname, int writing) |
7 | 895 { |
896 int i; | |
897 | |
898 y_append = FALSE; | |
899 if ((regname == 0 || regname == '"') && !writing && y_previous != NULL) | |
900 { | |
901 y_current = y_previous; | |
902 return; | |
903 } | |
904 i = regname; | |
905 if (VIM_ISDIGIT(i)) | |
906 i -= '0'; | |
907 else if (ASCII_ISLOWER(i)) | |
908 i = CharOrdLow(i) + 10; | |
909 else if (ASCII_ISUPPER(i)) | |
910 { | |
911 i = CharOrdUp(i) + 10; | |
912 y_append = TRUE; | |
913 } | |
914 else if (regname == '-') | |
915 i = DELETION_REGISTER; | |
916 #ifdef FEAT_CLIPBOARD | |
917 /* When selection is not available, use register 0 instead of '*' */ | |
918 else if (clip_star.available && regname == '*') | |
919 i = STAR_REGISTER; | |
920 /* When clipboard is not available, use register 0 instead of '+' */ | |
921 else if (clip_plus.available && regname == '+') | |
922 i = PLUS_REGISTER; | |
923 #endif | |
924 #ifdef FEAT_DND | |
925 else if (!writing && regname == '~') | |
926 i = TILDE_REGISTER; | |
927 #endif | |
928 else /* not 0-9, a-z, A-Z or '-': use register 0 */ | |
929 i = 0; | |
930 y_current = &(y_regs[i]); | |
931 if (writing) /* remember the register we write into for do_put() */ | |
932 y_previous = y_current; | |
933 } | |
934 | |
15 | 935 #if defined(FEAT_CLIPBOARD) || defined(PROTO) |
7 | 936 /* |
937 * When "regname" is a clipboard register, obtain the selection. If it's not | |
938 * available return zero, otherwise return "regname". | |
939 */ | |
15 | 940 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
941 may_get_selection(int regname) |
7 | 942 { |
943 if (regname == '*') | |
944 { | |
945 if (!clip_star.available) | |
946 regname = 0; | |
947 else | |
948 clip_get_selection(&clip_star); | |
949 } | |
950 else if (regname == '+') | |
951 { | |
952 if (!clip_plus.available) | |
953 regname = 0; | |
954 else | |
955 clip_get_selection(&clip_plus); | |
956 } | |
957 return regname; | |
958 } | |
959 #endif | |
960 | |
961 /* | |
962 * Obtain the contents of a "normal" register. The register is made empty. | |
963 * The returned pointer has allocated memory, use put_register() later. | |
964 */ | |
965 void * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
966 get_register( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
967 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
968 int copy) /* make a copy, if FALSE make register empty. */ |
7 | 969 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
970 yankreg_T *reg; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
971 int i; |
7 | 972 |
973 #ifdef FEAT_CLIPBOARD | |
974 /* When Visual area changed, may have to update selection. Obtain the | |
975 * selection too. */ | |
1435 | 976 if (name == '*' && clip_star.available) |
7 | 977 { |
3674 | 978 if (clip_isautosel_star()) |
979 clip_update_selection(&clip_star); | |
980 may_get_selection(name); | |
981 } | |
982 if (name == '+' && clip_plus.available) | |
983 { | |
984 if (clip_isautosel_plus()) | |
985 clip_update_selection(&clip_plus); | |
7 | 986 may_get_selection(name); |
987 } | |
988 #endif | |
989 | |
990 get_yank_register(name, 0); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
991 reg = (yankreg_T *)alloc((unsigned)sizeof(yankreg_T)); |
7 | 992 if (reg != NULL) |
993 { | |
994 *reg = *y_current; | |
995 if (copy) | |
996 { | |
997 /* If we run out of memory some or all of the lines are empty. */ | |
998 if (reg->y_size == 0) | |
999 reg->y_array = NULL; | |
1000 else | |
1001 reg->y_array = (char_u **)alloc((unsigned)(sizeof(char_u *) | |
1002 * reg->y_size)); | |
1003 if (reg->y_array != NULL) | |
1004 { | |
1005 for (i = 0; i < reg->y_size; ++i) | |
1006 reg->y_array[i] = vim_strsave(y_current->y_array[i]); | |
1007 } | |
1008 } | |
1009 else | |
1010 y_current->y_array = NULL; | |
1011 } | |
1012 return (void *)reg; | |
1013 } | |
1014 | |
1015 /* | |
1451 | 1016 * Put "reg" into register "name". Free any previous contents and "reg". |
7 | 1017 */ |
1018 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1019 put_register(int name, void *reg) |
7 | 1020 { |
1021 get_yank_register(name, 0); | |
1022 free_yank_all(); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1023 *y_current = *(yankreg_T *)reg; |
1451 | 1024 vim_free(reg); |
7 | 1025 |
5735 | 1026 #ifdef FEAT_CLIPBOARD |
7 | 1027 /* Send text written to clipboard register to the clipboard. */ |
1028 may_set_selection(); | |
5735 | 1029 #endif |
7 | 1030 } |
4209 | 1031 |
1032 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1033 free_register(void *reg) |
4209 | 1034 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1035 yankreg_T tmp; |
4209 | 1036 |
1037 tmp = *y_current; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1038 *y_current = *(yankreg_T *)reg; |
4209 | 1039 free_yank_all(); |
1040 vim_free(reg); | |
1041 *y_current = tmp; | |
1042 } | |
7 | 1043 |
1044 #if defined(FEAT_MOUSE) || defined(PROTO) | |
1045 /* | |
1046 * return TRUE if the current yank register has type MLINE | |
1047 */ | |
1048 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1049 yank_register_mline(int regname) |
7 | 1050 { |
1051 if (regname != 0 && !valid_yank_reg(regname, FALSE)) | |
1052 return FALSE; | |
1053 if (regname == '_') /* black hole is always empty */ | |
1054 return FALSE; | |
1055 get_yank_register(regname, FALSE); | |
1056 return (y_current->y_type == MLINE); | |
1057 } | |
1058 #endif | |
1059 | |
1060 /* | |
1157 | 1061 * Start or stop recording into a yank register. |
7 | 1062 * |
1157 | 1063 * Return FAIL for failure, OK otherwise. |
7 | 1064 */ |
1065 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1066 do_record(int c) |
7 | 1067 { |
1157 | 1068 char_u *p; |
1069 static int regname; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1070 yankreg_T *old_y_previous, *old_y_current; |
1157 | 1071 int retval; |
7 | 1072 |
1073 if (Recording == FALSE) /* start recording */ | |
1074 { | |
1075 /* registers 0-9, a-z and " are allowed */ | |
1076 if (c < 0 || (!ASCII_ISALNUM(c) && c != '"')) | |
1077 retval = FAIL; | |
1078 else | |
1079 { | |
7233
9487ea110214
commit https://github.com/vim/vim/commit/a0ed84a26897c994512873a895b9fc54e90c6845
Christian Brabandt <cb@256bit.org>
parents:
7011
diff
changeset
|
1080 Recording = c; |
7 | 1081 showmode(); |
1082 regname = c; | |
1083 retval = OK; | |
1084 } | |
1085 } | |
1086 else /* stop recording */ | |
1087 { | |
1088 /* | |
1157 | 1089 * Get the recorded key hits. K_SPECIAL and CSI will be escaped, this |
1090 * needs to be removed again to put it in a register. exec_reg then | |
1091 * adds the escaping back later. | |
7 | 1092 */ |
1093 Recording = FALSE; | |
1094 MSG(""); | |
1095 p = get_recorded(); | |
1096 if (p == NULL) | |
1097 retval = FAIL; | |
1098 else | |
1099 { | |
1081 | 1100 /* Remove escaping for CSI and K_SPECIAL in multi-byte chars. */ |
1101 vim_unescape_csi(p); | |
1102 | |
7 | 1103 /* |
1104 * We don't want to change the default register here, so save and | |
1105 * restore the current register name. | |
1106 */ | |
1107 old_y_previous = y_previous; | |
1108 old_y_current = y_current; | |
1109 | |
1110 retval = stuff_yank(regname, p); | |
1111 | |
1112 y_previous = old_y_previous; | |
1113 y_current = old_y_current; | |
1114 } | |
1115 } | |
1116 return retval; | |
1117 } | |
1118 | |
1119 /* | |
1120 * Stuff string "p" into yank register "regname" as a single line (append if | |
1121 * uppercase). "p" must have been alloced. | |
1122 * | |
1123 * return FAIL for failure, OK otherwise | |
1124 */ | |
1125 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1126 stuff_yank(int regname, char_u *p) |
7 | 1127 { |
1128 char_u *lp; | |
1129 char_u **pp; | |
1130 | |
1131 /* check for read-only register */ | |
1132 if (regname != 0 && !valid_yank_reg(regname, TRUE)) | |
1133 { | |
1134 vim_free(p); | |
1135 return FAIL; | |
1136 } | |
1137 if (regname == '_') /* black hole: don't do anything */ | |
1138 { | |
1139 vim_free(p); | |
1140 return OK; | |
1141 } | |
1142 get_yank_register(regname, TRUE); | |
1143 if (y_append && y_current->y_array != NULL) | |
1144 { | |
1145 pp = &(y_current->y_array[y_current->y_size - 1]); | |
1146 lp = lalloc((long_u)(STRLEN(*pp) + STRLEN(p) + 1), TRUE); | |
1147 if (lp == NULL) | |
1148 { | |
1149 vim_free(p); | |
1150 return FAIL; | |
1151 } | |
1152 STRCPY(lp, *pp); | |
1153 STRCAT(lp, p); | |
1154 vim_free(p); | |
1155 vim_free(*pp); | |
1156 *pp = lp; | |
1157 } | |
1158 else | |
1159 { | |
1160 free_yank_all(); | |
1161 if ((y_current->y_array = | |
1162 (char_u **)alloc((unsigned)sizeof(char_u *))) == NULL) | |
1163 { | |
1164 vim_free(p); | |
1165 return FAIL; | |
1166 } | |
1167 y_current->y_array[0] = p; | |
1168 y_current->y_size = 1; | |
1169 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
|
1170 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1171 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
|
1172 #endif |
7 | 1173 } |
1174 return OK; | |
1175 } | |
1176 | |
1893 | 1177 static int execreg_lastc = NUL; |
1178 | |
7 | 1179 /* |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
1180 * Execute a yank register: copy it into the stuff buffer. |
7 | 1181 * |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
1182 * Return FAIL for failure, OK otherwise. |
7 | 1183 */ |
1184 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1185 do_execreg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1186 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1187 int colon, /* insert ':' before each line */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1188 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
|
1189 int silent) /* set "silent" flag in typeahead buffer */ |
7 | 1190 { |
1191 long i; | |
1192 char_u *p; | |
1193 int retval = OK; | |
1194 int remap; | |
1195 | |
1196 if (regname == '@') /* repeat previous one */ | |
168 | 1197 { |
1893 | 1198 if (execreg_lastc == NUL) |
168 | 1199 { |
1200 EMSG(_("E748: No previously used register")); | |
1201 return FAIL; | |
1202 } | |
1893 | 1203 regname = execreg_lastc; |
168 | 1204 } |
7 | 1205 /* check for valid regname */ |
1206 if (regname == '%' || regname == '#' || !valid_yank_reg(regname, FALSE)) | |
168 | 1207 { |
1208 emsg_invreg(regname); | |
7 | 1209 return FAIL; |
168 | 1210 } |
1893 | 1211 execreg_lastc = regname; |
7 | 1212 |
1213 #ifdef FEAT_CLIPBOARD | |
1214 regname = may_get_selection(regname); | |
1215 #endif | |
1216 | |
1217 if (regname == '_') /* black hole: don't stuff anything */ | |
1218 return OK; | |
1219 | |
1220 #ifdef FEAT_CMDHIST | |
1221 if (regname == ':') /* use last command line */ | |
1222 { | |
1223 if (last_cmdline == NULL) | |
1224 { | |
1225 EMSG(_(e_nolastcmd)); | |
1226 return FAIL; | |
1227 } | |
1228 vim_free(new_last_cmdline); /* don't keep the cmdline containing @: */ | |
1229 new_last_cmdline = NULL; | |
16 | 1230 /* Escape all control characters with a CTRL-V */ |
1231 p = vim_strsave_escaped_ext(last_cmdline, | |
20 | 1232 (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 | 1233 if (p != NULL) |
480 | 1234 { |
1235 /* When in Visual mode "'<,'>" will be prepended to the command. | |
1236 * Remove it when it's already there. */ | |
1237 if (VIsual_active && STRNCMP(p, "'<,'>", 5) == 0) | |
1077 | 1238 retval = put_in_typebuf(p + 5, TRUE, TRUE, silent); |
480 | 1239 else |
1077 | 1240 retval = put_in_typebuf(p, TRUE, TRUE, silent); |
480 | 1241 } |
16 | 1242 vim_free(p); |
7 | 1243 } |
1244 #endif | |
1245 #ifdef FEAT_EVAL | |
1246 else if (regname == '=') | |
1247 { | |
1248 p = get_expr_line(); | |
1249 if (p == NULL) | |
1250 return FAIL; | |
1077 | 1251 retval = put_in_typebuf(p, TRUE, colon, silent); |
7 | 1252 vim_free(p); |
1253 } | |
1254 #endif | |
1255 else if (regname == '.') /* use last inserted text */ | |
1256 { | |
1257 p = get_last_insert_save(); | |
1258 if (p == NULL) | |
1259 { | |
1260 EMSG(_(e_noinstext)); | |
1261 return FAIL; | |
1262 } | |
1077 | 1263 retval = put_in_typebuf(p, FALSE, colon, silent); |
7 | 1264 vim_free(p); |
1265 } | |
1266 else | |
1267 { | |
1268 get_yank_register(regname, FALSE); | |
1269 if (y_current->y_array == NULL) | |
1270 return FAIL; | |
1271 | |
1272 /* Disallow remaping for ":@r". */ | |
1273 remap = colon ? REMAP_NONE : REMAP_YES; | |
1274 | |
1275 /* | |
1276 * Insert lines into typeahead buffer, from last one to first one. | |
1277 */ | |
1034 | 1278 put_reedit_in_typebuf(silent); |
7 | 1279 for (i = y_current->y_size; --i >= 0; ) |
1280 { | |
1077 | 1281 char_u *escaped; |
1282 | |
7 | 1283 /* insert NL between lines and after last line if type is MLINE */ |
1284 if (y_current->y_type == MLINE || i < y_current->y_size - 1 | |
1285 || addcr) | |
1286 { | |
1034 | 1287 if (ins_typebuf((char_u *)"\n", remap, 0, TRUE, silent) == FAIL) |
7 | 1288 return FAIL; |
1289 } | |
1077 | 1290 escaped = vim_strsave_escape_csi(y_current->y_array[i]); |
1291 if (escaped == NULL) | |
1292 return FAIL; | |
1293 retval = ins_typebuf(escaped, remap, 0, TRUE, silent); | |
1294 vim_free(escaped); | |
1295 if (retval == FAIL) | |
7 | 1296 return FAIL; |
1034 | 1297 if (colon && ins_typebuf((char_u *)":", remap, 0, TRUE, silent) |
7 | 1298 == FAIL) |
1299 return FAIL; | |
1300 } | |
1301 Exec_reg = TRUE; /* disable the 'q' command */ | |
1302 } | |
1303 return retval; | |
1304 } | |
1305 | |
1306 /* | |
1307 * If "restart_edit" is not zero, put it in the typeahead buffer, so that it's | |
1308 * used only after other typeahead has been processed. | |
1309 */ | |
1310 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1311 put_reedit_in_typebuf(int silent) |
7 | 1312 { |
1313 char_u buf[3]; | |
1314 | |
1315 if (restart_edit != NUL) | |
1316 { | |
1317 if (restart_edit == 'V') | |
1318 { | |
1319 buf[0] = 'g'; | |
1320 buf[1] = 'R'; | |
1321 buf[2] = NUL; | |
1322 } | |
1323 else | |
1324 { | |
1325 buf[0] = restart_edit == 'I' ? 'i' : restart_edit; | |
1326 buf[1] = NUL; | |
1327 } | |
1034 | 1328 if (ins_typebuf(buf, REMAP_NONE, 0, TRUE, silent) == OK) |
7 | 1329 restart_edit = NUL; |
1330 } | |
1331 } | |
1332 | |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1333 /* |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1334 * 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
|
1335 * executed again. |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1336 * 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
|
1337 * no remapping. |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1338 */ |
7 | 1339 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1340 put_in_typebuf( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1341 char_u *s, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1342 int esc, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1343 int colon, /* add ':' before the line */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1344 int silent) |
7 | 1345 { |
1346 int retval = OK; | |
1347 | |
1034 | 1348 put_reedit_in_typebuf(silent); |
7 | 1349 if (colon) |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1350 retval = ins_typebuf((char_u *)"\n", REMAP_NONE, 0, TRUE, silent); |
7 | 1351 if (retval == OK) |
1077 | 1352 { |
1353 char_u *p; | |
1354 | |
1355 if (esc) | |
1356 p = vim_strsave_escape_csi(s); | |
1357 else | |
1358 p = s; | |
1359 if (p == NULL) | |
1360 retval = FAIL; | |
1361 else | |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1362 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
|
1363 0, TRUE, silent); |
1077 | 1364 if (esc) |
1365 vim_free(p); | |
1366 } | |
7 | 1367 if (colon && retval == OK) |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1368 retval = ins_typebuf((char_u *)":", REMAP_NONE, 0, TRUE, silent); |
7 | 1369 return retval; |
1370 } | |
1371 | |
1372 /* | |
1373 * Insert a yank register: copy it into the Read buffer. | |
1374 * Used by CTRL-R command and middle mouse button in insert mode. | |
1375 * | |
1376 * return FAIL for failure, OK otherwise | |
1377 */ | |
1378 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1379 insert_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1380 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1381 int literally) /* insert literally, not as if typed */ |
7 | 1382 { |
1383 long i; | |
1384 int retval = OK; | |
1385 char_u *arg; | |
1386 int allocated; | |
1387 | |
1388 /* | |
1389 * It is possible to get into an endless loop by having CTRL-R a in | |
1390 * register a and then, in insert mode, doing CTRL-R a. | |
1391 * If you hit CTRL-C, the loop will be broken here. | |
1392 */ | |
1393 ui_breakcheck(); | |
1394 if (got_int) | |
1395 return FAIL; | |
1396 | |
1397 /* check for valid regname */ | |
1398 if (regname != NUL && !valid_yank_reg(regname, FALSE)) | |
1399 return FAIL; | |
1400 | |
1401 #ifdef FEAT_CLIPBOARD | |
1402 regname = may_get_selection(regname); | |
1403 #endif | |
1404 | |
1405 if (regname == '.') /* insert last inserted text */ | |
1406 retval = stuff_inserted(NUL, 1L, TRUE); | |
1407 else if (get_spec_reg(regname, &arg, &allocated, TRUE)) | |
1408 { | |
1409 if (arg == NULL) | |
1410 return FAIL; | |
1411 stuffescaped(arg, literally); | |
1412 if (allocated) | |
1413 vim_free(arg); | |
1414 } | |
1415 else /* name or number register */ | |
1416 { | |
1417 get_yank_register(regname, FALSE); | |
1418 if (y_current->y_array == NULL) | |
1419 retval = FAIL; | |
1420 else | |
1421 { | |
1422 for (i = 0; i < y_current->y_size; ++i) | |
1423 { | |
1424 stuffescaped(y_current->y_array[i], literally); | |
1425 /* | |
1426 * Insert a newline between lines and after last line if | |
1427 * y_type is MLINE. | |
1428 */ | |
1429 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | |
1430 stuffcharReadbuff('\n'); | |
1431 } | |
1432 } | |
1433 } | |
1434 | |
1435 return retval; | |
1436 } | |
1437 | |
1438 /* | |
1439 * Stuff a string into the typeahead buffer, such that edit() will insert it | |
1440 * literally ("literally" TRUE) or interpret is as typed characters. | |
1441 */ | |
1442 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1443 stuffescaped(char_u *arg, int literally) |
7 | 1444 { |
1445 int c; | |
1446 char_u *start; | |
1447 | |
1448 while (*arg != NUL) | |
1449 { | |
1450 /* Stuff a sequence of normal ASCII characters, that's fast. Also | |
1451 * stuff K_SPECIAL to get the effect of a special key when "literally" | |
1452 * is TRUE. */ | |
1453 start = arg; | |
1454 while ((*arg >= ' ' | |
1455 #ifndef EBCDIC | |
1456 && *arg < DEL /* EBCDIC: chars above space are normal */ | |
1457 #endif | |
1458 ) | |
1459 || (*arg == K_SPECIAL && !literally)) | |
1460 ++arg; | |
1461 if (arg > start) | |
1462 stuffReadbuffLen(start, (long)(arg - start)); | |
1463 | |
1464 /* stuff a single special character */ | |
1465 if (*arg != NUL) | |
1466 { | |
1467 #ifdef FEAT_MBYTE | |
1468 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
|
1469 c = mb_cptr2char_adv(&arg); |
7 | 1470 else |
1471 #endif | |
1472 c = *arg++; | |
1473 if (literally && ((c < ' ' && c != TAB) || c == DEL)) | |
1474 stuffcharReadbuff(Ctrl_V); | |
1475 stuffcharReadbuff(c); | |
1476 } | |
1477 } | |
1478 } | |
1479 | |
1480 /* | |
1157 | 1481 * If "regname" is a special register, return TRUE and store a pointer to its |
1482 * value in "argp". | |
7 | 1483 */ |
15 | 1484 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1485 get_spec_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1486 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1487 char_u **argp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1488 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
|
1489 int errmsg) /* give error message when failing */ |
7 | 1490 { |
1491 int cnt; | |
1492 | |
1493 *argp = NULL; | |
1494 *allocated = FALSE; | |
1495 switch (regname) | |
1496 { | |
1497 case '%': /* file name */ | |
1498 if (errmsg) | |
1499 check_fname(); /* will give emsg if not set */ | |
1500 *argp = curbuf->b_fname; | |
1501 return TRUE; | |
1502 | |
1503 case '#': /* alternate file name */ | |
1504 *argp = getaltfname(errmsg); /* may give emsg if not set */ | |
1505 return TRUE; | |
1506 | |
1507 #ifdef FEAT_EVAL | |
1508 case '=': /* result of expression */ | |
1509 *argp = get_expr_line(); | |
1510 *allocated = TRUE; | |
1511 return TRUE; | |
1512 #endif | |
1513 | |
1514 case ':': /* last command line */ | |
1515 if (last_cmdline == NULL && errmsg) | |
1516 EMSG(_(e_nolastcmd)); | |
1517 *argp = last_cmdline; | |
1518 return TRUE; | |
1519 | |
1520 case '/': /* last search-pattern */ | |
1521 if (last_search_pat() == NULL && errmsg) | |
1522 EMSG(_(e_noprevre)); | |
1523 *argp = last_search_pat(); | |
1524 return TRUE; | |
1525 | |
1526 case '.': /* last inserted text */ | |
1527 *argp = get_last_insert_save(); | |
1528 *allocated = TRUE; | |
1529 if (*argp == NULL && errmsg) | |
1530 EMSG(_(e_noinstext)); | |
1531 return TRUE; | |
1532 | |
1533 #ifdef FEAT_SEARCHPATH | |
1534 case Ctrl_F: /* Filename under cursor */ | |
1535 case Ctrl_P: /* Path under cursor, expand via "path" */ | |
1536 if (!errmsg) | |
1537 return FALSE; | |
1538 *argp = file_name_at_cursor(FNAME_MESS | FNAME_HYP | |
681 | 1539 | (regname == Ctrl_P ? FNAME_EXP : 0), 1L, NULL); |
7 | 1540 *allocated = TRUE; |
1541 return TRUE; | |
1542 #endif | |
1543 | |
1544 case Ctrl_W: /* word under cursor */ | |
1545 case Ctrl_A: /* WORD (mnemonic All) under cursor */ | |
1546 if (!errmsg) | |
1547 return FALSE; | |
1548 cnt = find_ident_under_cursor(argp, regname == Ctrl_W | |
1549 ? (FIND_IDENT|FIND_STRING) : FIND_STRING); | |
1550 *argp = cnt ? vim_strnsave(*argp, cnt) : NULL; | |
1551 *allocated = TRUE; | |
1552 return TRUE; | |
1553 | |
1554 case '_': /* black hole: always empty */ | |
1555 *argp = (char_u *)""; | |
1556 return TRUE; | |
1557 } | |
1558 | |
1559 return FALSE; | |
1560 } | |
1561 | |
1562 /* | |
15 | 1563 * Paste a yank register into the command line. |
1564 * Only for non-special registers. | |
1565 * Used by CTRL-R command in command-line mode | |
7 | 1566 * insert_reg() can't be used here, because special characters from the |
1567 * register contents will be interpreted as commands. | |
1568 * | |
1569 * return FAIL for failure, OK otherwise | |
1570 */ | |
1571 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1572 cmdline_paste_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1573 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1574 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
|
1575 int remcr) /* don't add CR characters */ |
7 | 1576 { |
1577 long i; | |
1578 | |
1579 get_yank_register(regname, FALSE); | |
1580 if (y_current->y_array == NULL) | |
1581 return FAIL; | |
1582 | |
1583 for (i = 0; i < y_current->y_size; ++i) | |
1584 { | |
1585 cmdline_paste_str(y_current->y_array[i], literally); | |
1586 | |
1015 | 1587 /* 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
|
1588 * 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
|
1589 if ((y_current->y_type == MLINE || i < y_current->y_size - 1) && !remcr) |
7 | 1590 cmdline_paste_str((char_u *)"\r", literally); |
1591 | |
1592 /* Check for CTRL-C, in case someone tries to paste a few thousand | |
1593 * lines and gets bored. */ | |
1594 ui_breakcheck(); | |
1595 if (got_int) | |
1596 return FAIL; | |
1597 } | |
1598 return OK; | |
1599 } | |
1600 | |
1601 #if defined(FEAT_CLIPBOARD) || defined(PROTO) | |
1602 /* | |
1603 * Adjust the register name pointed to with "rp" for the clipboard being | |
1604 * used always and the clipboard being available. | |
1605 */ | |
1606 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1607 adjust_clip_reg(int *rp) |
7 | 1608 { |
2654 | 1609 /* If no reg. specified, and "unnamed" or "unnamedplus" is in 'clipboard', |
1610 * use '*' or '+' reg, respectively. "unnamedplus" prevails. */ | |
6116 | 1611 if (*rp == 0 && (clip_unnamed != 0 || clip_unnamed_saved != 0)) |
1612 { | |
1613 if (clip_unnamed != 0) | |
1614 *rp = ((clip_unnamed & CLIP_UNNAMED_PLUS) && clip_plus.available) | |
2654 | 1615 ? '+' : '*'; |
6116 | 1616 else |
1617 *rp = ((clip_unnamed_saved & CLIP_UNNAMED_PLUS) && clip_plus.available) | |
1618 ? '+' : '*'; | |
1619 } | |
7 | 1620 if (!clip_star.available && *rp == '*') |
1621 *rp = 0; | |
1622 if (!clip_plus.available && *rp == '+') | |
1623 *rp = 0; | |
1624 } | |
1625 #endif | |
1626 | |
1627 /* | |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1628 * 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
|
1629 */ |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1630 void |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1631 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
|
1632 { |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1633 int n; |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1634 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1635 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
|
1636 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
|
1637 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
|
1638 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
|
1639 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
|
1640 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
|
1641 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
|
1642 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
|
1643 } |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1644 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1645 /* |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1646 * Handle a delete operation. |
7 | 1647 * |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1648 * Return FAIL if undo failed, OK otherwise. |
7 | 1649 */ |
1650 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1651 op_delete(oparg_T *oap) |
7 | 1652 { |
1653 int n; | |
1654 linenr_T lnum; | |
1655 char_u *ptr; | |
1656 char_u *newp, *oldp; | |
1657 struct block_def bd; | |
1658 linenr_T old_lcount = curbuf->b_ml.ml_line_count; | |
1659 int did_yank = FALSE; | |
3782 | 1660 int orig_regname = oap->regname; |
7 | 1661 |
1662 if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to do */ | |
1663 return OK; | |
1664 | |
1665 /* Nothing to delete, return here. Do prepare undo, for op_change(). */ | |
1666 if (oap->empty) | |
1667 return u_save_cursor(); | |
1668 | |
1669 if (!curbuf->b_p_ma) | |
1670 { | |
1671 EMSG(_(e_modifiable)); | |
1672 return FAIL; | |
1673 } | |
1674 | |
1675 #ifdef FEAT_CLIPBOARD | |
1676 adjust_clip_reg(&oap->regname); | |
1677 #endif | |
1678 | |
1679 #ifdef FEAT_MBYTE | |
1680 if (has_mbyte) | |
1681 mb_adjust_opend(oap); | |
1682 #endif | |
1683 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1684 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1685 * 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
|
1686 * 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
|
1687 * 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
|
1688 */ |
7 | 1689 if ( oap->motion_type == MCHAR |
1690 && !oap->is_VIsual | |
50 | 1691 && !oap->block_mode |
7 | 1692 && oap->line_count > 1 |
3254 | 1693 && oap->motion_force == NUL |
7 | 1694 && oap->op_type == OP_DELETE) |
1695 { | |
2957 | 1696 ptr = ml_get(oap->end.lnum) + oap->end.col; |
1697 if (*ptr != NUL) | |
1698 ptr += oap->inclusive; | |
7 | 1699 ptr = skipwhite(ptr); |
1700 if (*ptr == NUL && inindent(0)) | |
1701 oap->motion_type = MLINE; | |
1702 } | |
1703 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1704 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1705 * 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
|
1706 * 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
|
1707 */ |
7 | 1708 if ( oap->motion_type == MCHAR |
1709 && oap->line_count == 1 | |
1710 && oap->op_type == OP_DELETE | |
1711 && *ml_get(oap->start.lnum) == NUL) | |
1712 { | |
1713 /* | |
446 | 1714 * It's an error to operate on an empty region, when 'E' included in |
7 | 1715 * 'cpoptions' (Vi compatible). |
1716 */ | |
446 | 1717 #ifdef FEAT_VIRTUALEDIT |
1718 if (virtual_op) | |
1719 /* Virtual editing: Nothing gets deleted, but we set the '[ and '] | |
1720 * marks as if it happened. */ | |
1721 goto setmarks; | |
1722 #endif | |
7 | 1723 if (vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL) |
1724 beep_flush(); | |
1725 return OK; | |
1726 } | |
1727 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1728 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1729 * 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
|
1730 * 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
|
1731 * 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
|
1732 */ |
7 | 1733 if (oap->regname != '_') |
1734 { | |
1735 if (oap->regname != 0) | |
1736 { | |
1737 /* check for read-only register */ | |
1738 if (!valid_yank_reg(oap->regname, TRUE)) | |
1739 { | |
1740 beep_flush(); | |
1741 return OK; | |
1742 } | |
1743 get_yank_register(oap->regname, TRUE); /* yank into specif'd reg. */ | |
1744 if (op_yank(oap, TRUE, FALSE) == OK) /* yank without message */ | |
1745 did_yank = TRUE; | |
1746 } | |
1747 | |
1748 /* | |
1749 * Put deleted text into register 1 and shift number registers if the | |
1750 * delete contains a line break, or when a regname has been specified. | |
3782 | 1751 * Use the register name from before adjust_clip_reg() may have |
1752 * changed it. | |
7 | 1753 */ |
3782 | 1754 if (orig_regname != 0 || oap->motion_type == MLINE |
7 | 1755 || oap->line_count > 1 || oap->use_reg_one) |
1756 { | |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1757 shift_delete_registers(); |
7 | 1758 if (op_yank(oap, TRUE, FALSE) == OK) |
1759 did_yank = TRUE; | |
1760 } | |
1761 | |
3468 | 1762 /* Yank into small delete register when no named register specified |
1763 * and the delete is within one line. */ | |
1764 if (( | |
1765 #ifdef FEAT_CLIPBOARD | |
3584 | 1766 ((clip_unnamed & CLIP_UNNAMED) && oap->regname == '*') || |
1767 ((clip_unnamed & CLIP_UNNAMED_PLUS) && oap->regname == '+') || | |
3468 | 1768 #endif |
1769 oap->regname == 0) && oap->motion_type != MLINE | |
7 | 1770 && oap->line_count == 1) |
1771 { | |
1772 oap->regname = '-'; | |
1773 get_yank_register(oap->regname, TRUE); | |
1774 if (op_yank(oap, TRUE, FALSE) == OK) | |
1775 did_yank = TRUE; | |
1776 oap->regname = 0; | |
1777 } | |
1778 | |
1779 /* | |
1780 * If there's too much stuff to fit in the yank register, then get a | |
1781 * confirmation before doing the delete. This is crude, but simple. | |
1782 * And it avoids doing a delete of something we can't put back if we | |
1783 * want. | |
1784 */ | |
1785 if (!did_yank) | |
1786 { | |
1787 int msg_silent_save = msg_silent; | |
1788 | |
1789 msg_silent = 0; /* must display the prompt */ | |
1790 n = ask_yesno((char_u *)_("cannot yank; delete anyway"), TRUE); | |
1791 msg_silent = msg_silent_save; | |
1792 if (n != 'y') | |
1793 { | |
1794 EMSG(_(e_abort)); | |
1795 return FAIL; | |
1796 } | |
1797 } | |
1798 } | |
1799 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1800 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1801 * 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
|
1802 */ |
7 | 1803 if (oap->block_mode) |
1804 { | |
1805 if (u_save((linenr_T)(oap->start.lnum - 1), | |
1806 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
1807 return FAIL; | |
1808 | |
1809 for (lnum = curwin->w_cursor.lnum; lnum <= oap->end.lnum; ++lnum) | |
1810 { | |
1811 block_prep(oap, &bd, lnum, TRUE); | |
1812 if (bd.textlen == 0) /* nothing to delete */ | |
1813 continue; | |
1814 | |
1815 /* Adjust cursor position for tab replaced by spaces and 'lbr'. */ | |
1816 if (lnum == curwin->w_cursor.lnum) | |
1817 { | |
1818 curwin->w_cursor.col = bd.textcol + bd.startspaces; | |
1819 # ifdef FEAT_VIRTUALEDIT | |
1820 curwin->w_cursor.coladd = 0; | |
1821 # endif | |
1822 } | |
1823 | |
1824 /* n == number of chars deleted | |
1825 * If we delete a TAB, it may be replaced by several characters. | |
1826 * Thus the number of characters may increase! | |
1827 */ | |
1828 n = bd.textlen - bd.startspaces - bd.endspaces; | |
1829 oldp = ml_get(lnum); | |
1830 newp = alloc_check((unsigned)STRLEN(oldp) + 1 - n); | |
1831 if (newp == NULL) | |
1832 continue; | |
1833 /* copy up to deleted part */ | |
1834 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
1835 /* insert spaces */ | |
6929 | 1836 vim_memset(newp + bd.textcol, ' ', |
7 | 1837 (size_t)(bd.startspaces + bd.endspaces)); |
1838 /* copy the part after the deleted part */ | |
1839 oldp += bd.textcol + bd.textlen; | |
1622 | 1840 STRMOVE(newp + bd.textcol + bd.startspaces + bd.endspaces, oldp); |
7 | 1841 /* replace the line */ |
1842 ml_replace(lnum, newp, FALSE); | |
1843 } | |
1844 | |
1845 check_cursor_col(); | |
1846 changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col, | |
1847 oap->end.lnum + 1, 0L); | |
1848 oap->line_count = 0; /* no lines deleted */ | |
1849 } | |
5735 | 1850 else if (oap->motion_type == MLINE) |
7 | 1851 { |
1852 if (oap->op_type == OP_CHANGE) | |
1853 { | |
1854 /* Delete the lines except the first one. Temporarily move the | |
1855 * cursor to the next line. Save the current line number, if the | |
1856 * last line is deleted it may be changed. | |
1857 */ | |
1858 if (oap->line_count > 1) | |
1859 { | |
1860 lnum = curwin->w_cursor.lnum; | |
1861 ++curwin->w_cursor.lnum; | |
1862 del_lines((long)(oap->line_count - 1), TRUE); | |
1863 curwin->w_cursor.lnum = lnum; | |
1864 } | |
1865 if (u_save_cursor() == FAIL) | |
1866 return FAIL; | |
1867 if (curbuf->b_p_ai) /* don't delete indent */ | |
1868 { | |
1869 beginline(BL_WHITE); /* cursor on first non-white */ | |
1870 did_ai = TRUE; /* delete the indent when ESC hit */ | |
1871 ai_col = curwin->w_cursor.col; | |
1872 } | |
1873 else | |
1874 beginline(0); /* cursor in column 0 */ | |
1875 truncate_line(FALSE); /* delete the rest of the line */ | |
1876 /* leave cursor past last char in line */ | |
1877 if (oap->line_count > 1) | |
1878 u_clearline(); /* "U" command not possible after "2cc" */ | |
1879 } | |
1880 else | |
1881 { | |
1882 del_lines(oap->line_count, TRUE); | |
1883 beginline(BL_WHITE | BL_FIX); | |
1884 u_clearline(); /* "U" command not possible after "dd" */ | |
1885 } | |
1886 } | |
1887 else | |
1888 { | |
1889 #ifdef FEAT_VIRTUALEDIT | |
1890 if (virtual_op) | |
1891 { | |
1892 int endcol = 0; | |
1893 | |
1894 /* For virtualedit: break the tabs that are partly included. */ | |
1895 if (gchar_pos(&oap->start) == '\t') | |
1896 { | |
1897 if (u_save_cursor() == FAIL) /* save first line for undo */ | |
1898 return FAIL; | |
1899 if (oap->line_count == 1) | |
1900 endcol = getviscol2(oap->end.col, oap->end.coladd); | |
1901 coladvance_force(getviscol2(oap->start.col, oap->start.coladd)); | |
1902 oap->start = curwin->w_cursor; | |
1903 if (oap->line_count == 1) | |
1904 { | |
1905 coladvance(endcol); | |
1906 oap->end.col = curwin->w_cursor.col; | |
1907 oap->end.coladd = curwin->w_cursor.coladd; | |
1908 curwin->w_cursor = oap->start; | |
1909 } | |
1910 } | |
1911 | |
1912 /* Break a tab only when it's included in the area. */ | |
1913 if (gchar_pos(&oap->end) == '\t' | |
1914 && (int)oap->end.coladd < oap->inclusive) | |
1915 { | |
1916 /* save last line for undo */ | |
1917 if (u_save((linenr_T)(oap->end.lnum - 1), | |
1918 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
1919 return FAIL; | |
1920 curwin->w_cursor = oap->end; | |
1921 coladvance_force(getviscol2(oap->end.col, oap->end.coladd)); | |
1922 oap->end = curwin->w_cursor; | |
1923 curwin->w_cursor = oap->start; | |
1924 } | |
1925 } | |
1926 #endif | |
1927 | |
1928 if (oap->line_count == 1) /* delete characters within one line */ | |
1929 { | |
1930 if (u_save_cursor() == FAIL) /* save line for undo */ | |
1931 return FAIL; | |
1932 | |
1933 /* if 'cpoptions' contains '$', display '$' at end of change */ | |
5735 | 1934 if ( vim_strchr(p_cpo, CPO_DOLLAR) != NULL |
7 | 1935 && oap->op_type == OP_CHANGE |
1936 && oap->end.lnum == curwin->w_cursor.lnum | |
5735 | 1937 && !oap->is_VIsual) |
7 | 1938 display_dollar(oap->end.col - !oap->inclusive); |
1939 | |
1940 n = oap->end.col - oap->start.col + 1 - !oap->inclusive; | |
1941 | |
1942 #ifdef FEAT_VIRTUALEDIT | |
1943 if (virtual_op) | |
1944 { | |
1945 /* fix up things for virtualedit-delete: | |
1946 * break the tabs which are going to get in our way | |
1947 */ | |
1948 char_u *curline = ml_get_curline(); | |
1949 int len = (int)STRLEN(curline); | |
1950 | |
1951 if (oap->end.coladd != 0 | |
1952 && (int)oap->end.col >= len - 1 | |
1953 && !(oap->start.coladd && (int)oap->end.col >= len - 1)) | |
1954 n++; | |
1955 /* Delete at least one char (e.g, when on a control char). */ | |
1956 if (n == 0 && oap->start.coladd != oap->end.coladd) | |
1957 n = 1; | |
1958 | |
1959 /* When deleted a char in the line, reset coladd. */ | |
1960 if (gchar_cursor() != NUL) | |
1961 curwin->w_cursor.coladd = 0; | |
1962 } | |
1963 #endif | |
6826 | 1964 (void)del_bytes((long)n, !virtual_op, |
1965 oap->op_type == OP_DELETE && !oap->is_VIsual); | |
7 | 1966 } |
1967 else /* delete characters between lines */ | |
1968 { | |
1969 pos_T curpos; | |
1970 | |
1971 /* save deleted and changed lines for undo */ | |
1972 if (u_save((linenr_T)(curwin->w_cursor.lnum - 1), | |
1973 (linenr_T)(curwin->w_cursor.lnum + oap->line_count)) == FAIL) | |
1974 return FAIL; | |
1975 | |
1976 truncate_line(TRUE); /* delete from cursor to end of line */ | |
1977 | |
1978 curpos = curwin->w_cursor; /* remember curwin->w_cursor */ | |
1979 ++curwin->w_cursor.lnum; | |
1980 del_lines((long)(oap->line_count - 2), FALSE); | |
1981 | |
6826 | 1982 /* delete from start of line until op_end */ |
2957 | 1983 n = (oap->end.col + 1 - !oap->inclusive); |
6826 | 1984 curwin->w_cursor.col = 0; |
1985 (void)del_bytes((long)n, !virtual_op, | |
1986 oap->op_type == OP_DELETE && !oap->is_VIsual); | |
1987 curwin->w_cursor = curpos; /* restore curwin->w_cursor */ | |
1988 (void)do_join(2, FALSE, FALSE, FALSE, FALSE); | |
7 | 1989 } |
1990 } | |
1991 | |
1992 msgmore(curbuf->b_ml.ml_line_count - old_lcount); | |
1993 | |
446 | 1994 #ifdef FEAT_VIRTUALEDIT |
1995 setmarks: | |
1996 #endif | |
7 | 1997 if (oap->block_mode) |
1998 { | |
1999 curbuf->b_op_end.lnum = oap->end.lnum; | |
2000 curbuf->b_op_end.col = oap->start.col; | |
2001 } | |
2002 else | |
2003 curbuf->b_op_end = oap->start; | |
2004 curbuf->b_op_start = oap->start; | |
2005 | |
2006 return OK; | |
2007 } | |
2008 | |
2009 #ifdef FEAT_MBYTE | |
2010 /* | |
2011 * Adjust end of operating area for ending on a multi-byte character. | |
2012 * Used for deletion. | |
2013 */ | |
2014 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2015 mb_adjust_opend(oparg_T *oap) |
7 | 2016 { |
2017 char_u *p; | |
2018 | |
2019 if (oap->inclusive) | |
2020 { | |
2021 p = ml_get(oap->end.lnum); | |
2022 oap->end.col += mb_tail_off(p, p + oap->end.col); | |
2023 } | |
2024 } | |
2025 #endif | |
2026 | |
2027 #if defined(FEAT_VISUALEXTRA) || defined(PROTO) | |
2028 /* | |
2029 * Replace a whole area with one character. | |
2030 */ | |
2031 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2032 op_replace(oparg_T *oap, int c) |
7 | 2033 { |
2034 int n, numc; | |
2035 #ifdef FEAT_MBYTE | |
2036 int num_chars; | |
2037 #endif | |
2038 char_u *newp, *oldp; | |
2039 size_t oldlen; | |
2040 struct block_def bd; | |
5428 | 2041 char_u *after_p = NULL; |
2042 int had_ctrl_v_cr = (c == -1 || c == -2); | |
7 | 2043 |
2044 if ((curbuf->b_ml.ml_flags & ML_EMPTY ) || oap->empty) | |
2045 return OK; /* nothing to do */ | |
2046 | |
5428 | 2047 if (had_ctrl_v_cr) |
2048 c = (c == -1 ? '\r' : '\n'); | |
2049 | |
7 | 2050 #ifdef FEAT_MBYTE |
2051 if (has_mbyte) | |
2052 mb_adjust_opend(oap); | |
2053 #endif | |
2054 | |
2055 if (u_save((linenr_T)(oap->start.lnum - 1), | |
2056 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
2057 return FAIL; | |
2058 | |
2059 /* | |
2060 * block mode replace | |
2061 */ | |
2062 if (oap->block_mode) | |
2063 { | |
2064 bd.is_MAX = (curwin->w_curswant == MAXCOL); | |
2065 for ( ; curwin->w_cursor.lnum <= oap->end.lnum; ++curwin->w_cursor.lnum) | |
2066 { | |
1982 | 2067 curwin->w_cursor.col = 0; /* make sure cursor position is valid */ |
7 | 2068 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); |
2069 if (bd.textlen == 0 && (!virtual_op || bd.is_MAX)) | |
2070 continue; /* nothing to replace */ | |
2071 | |
2072 /* n == number of extra chars required | |
2073 * If we split a TAB, it may be replaced by several characters. | |
2074 * Thus the number of characters may increase! | |
2075 */ | |
2076 #ifdef FEAT_VIRTUALEDIT | |
2077 /* If the range starts in virtual space, count the initial | |
2078 * coladd offset as part of "startspaces" */ | |
2079 if (virtual_op && bd.is_short && *bd.textstart == NUL) | |
2080 { | |
2081 pos_T vpos; | |
2082 | |
1982 | 2083 vpos.lnum = curwin->w_cursor.lnum; |
7 | 2084 getvpos(&vpos, oap->start_vcol); |
2085 bd.startspaces += vpos.coladd; | |
2086 n = bd.startspaces; | |
2087 } | |
2088 else | |
2089 #endif | |
2090 /* allow for pre spaces */ | |
2091 n = (bd.startspaces ? bd.start_char_vcols - 1 : 0); | |
2092 | |
2093 /* allow for post spp */ | |
2094 n += (bd.endspaces | |
2095 #ifdef FEAT_VIRTUALEDIT | |
2096 && !bd.is_oneChar | |
2097 #endif | |
2098 && bd.end_char_vcols > 0) ? bd.end_char_vcols - 1 : 0; | |
2099 /* Figure out how many characters to replace. */ | |
2100 numc = oap->end_vcol - oap->start_vcol + 1; | |
2101 if (bd.is_short && (!virtual_op || bd.is_MAX)) | |
2102 numc -= (oap->end_vcol - bd.end_vcol) + 1; | |
2103 | |
2104 #ifdef FEAT_MBYTE | |
2105 /* A double-wide character can be replaced only up to half the | |
2106 * times. */ | |
2107 if ((*mb_char2cells)(c) > 1) | |
2108 { | |
2109 if ((numc & 1) && !bd.is_short) | |
2110 { | |
2111 ++bd.endspaces; | |
2112 ++n; | |
2113 } | |
2114 numc = numc / 2; | |
2115 } | |
2116 | |
2117 /* Compute bytes needed, move character count to num_chars. */ | |
2118 num_chars = numc; | |
2119 numc *= (*mb_char2len)(c); | |
2120 #endif | |
2121 /* oldlen includes textlen, so don't double count */ | |
2122 n += numc - bd.textlen; | |
2123 | |
2124 oldp = ml_get_curline(); | |
2125 oldlen = STRLEN(oldp); | |
2126 newp = alloc_check((unsigned)oldlen + 1 + n); | |
2127 if (newp == NULL) | |
2128 continue; | |
2129 vim_memset(newp, NUL, (size_t)(oldlen + 1 + n)); | |
2130 /* copy up to deleted part */ | |
2131 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
2132 oldp += bd.textcol + bd.textlen; | |
2133 /* insert pre-spaces */ | |
6929 | 2134 vim_memset(newp + bd.textcol, ' ', (size_t)bd.startspaces); |
7 | 2135 /* insert replacement chars CHECK FOR ALLOCATED SPACE */ |
5428 | 2136 /* -1/-2 is used for entering CR literally. */ |
2137 if (had_ctrl_v_cr || (c != '\r' && c != '\n')) | |
7 | 2138 { |
5428 | 2139 #ifdef FEAT_MBYTE |
2140 if (has_mbyte) | |
2141 { | |
2142 n = (int)STRLEN(newp); | |
2143 while (--num_chars >= 0) | |
2144 n += (*mb_char2bytes)(c, newp + n); | |
2145 } | |
2146 else | |
2147 #endif | |
6929 | 2148 vim_memset(newp + STRLEN(newp), c, (size_t)numc); |
5428 | 2149 if (!bd.is_short) |
2150 { | |
2151 /* insert post-spaces */ | |
6929 | 2152 vim_memset(newp + STRLEN(newp), ' ', (size_t)bd.endspaces); |
5428 | 2153 /* copy the part after the changed part */ |
2154 STRMOVE(newp + STRLEN(newp), oldp); | |
2155 } | |
7 | 2156 } |
2157 else | |
2158 { | |
5428 | 2159 /* Replacing with \r or \n means splitting the line. */ |
5475 | 2160 after_p = alloc_check( |
2161 (unsigned)(oldlen + 1 + n - STRLEN(newp))); | |
5428 | 2162 if (after_p != NULL) |
2163 STRMOVE(after_p, oldp); | |
7 | 2164 } |
2165 /* replace the line */ | |
2166 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
5428 | 2167 if (after_p != NULL) |
2168 { | |
2169 ml_append(curwin->w_cursor.lnum++, after_p, 0, FALSE); | |
2170 appended_lines_mark(curwin->w_cursor.lnum, 1L); | |
2171 oap->end.lnum++; | |
2172 vim_free(after_p); | |
2173 } | |
7 | 2174 } |
2175 } | |
2176 else | |
2177 { | |
2178 /* | |
2179 * MCHAR and MLINE motion replace. | |
2180 */ | |
2181 if (oap->motion_type == MLINE) | |
2182 { | |
2183 oap->start.col = 0; | |
2184 curwin->w_cursor.col = 0; | |
2185 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
2186 if (oap->end.col) | |
2187 --oap->end.col; | |
2188 } | |
2189 else if (!oap->inclusive) | |
2190 dec(&(oap->end)); | |
2191 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2192 while (LTOREQ_POS(curwin->w_cursor, oap->end)) |
7 | 2193 { |
2194 n = gchar_cursor(); | |
2195 if (n != NUL) | |
2196 { | |
2197 #ifdef FEAT_MBYTE | |
2198 if ((*mb_char2len)(c) > 1 || (*mb_char2len)(n) > 1) | |
2199 { | |
2200 /* This is slow, but it handles replacing a single-byte | |
2201 * with a multi-byte and the other way around. */ | |
4203 | 2202 if (curwin->w_cursor.lnum == oap->end.lnum) |
2203 oap->end.col += (*mb_char2len)(c) - (*mb_char2len)(n); | |
7 | 2204 n = State; |
2205 State = REPLACE; | |
2206 ins_char(c); | |
2207 State = n; | |
2208 /* Backup to the replaced character. */ | |
2209 dec_cursor(); | |
2210 } | |
2211 else | |
2212 #endif | |
2213 { | |
2214 #ifdef FEAT_VIRTUALEDIT | |
2215 if (n == TAB) | |
2216 { | |
2217 int end_vcol = 0; | |
2218 | |
2219 if (curwin->w_cursor.lnum == oap->end.lnum) | |
2220 { | |
2221 /* oap->end has to be recalculated when | |
2222 * the tab breaks */ | |
2223 end_vcol = getviscol2(oap->end.col, | |
2224 oap->end.coladd); | |
2225 } | |
2226 coladvance_force(getviscol()); | |
2227 if (curwin->w_cursor.lnum == oap->end.lnum) | |
2228 getvpos(&oap->end, end_vcol); | |
2229 } | |
2230 #endif | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2231 PCHAR(curwin->w_cursor, c); |
7 | 2232 } |
2233 } | |
2234 #ifdef FEAT_VIRTUALEDIT | |
2235 else if (virtual_op && curwin->w_cursor.lnum == oap->end.lnum) | |
2236 { | |
2237 int virtcols = oap->end.coladd; | |
2238 | |
2239 if (curwin->w_cursor.lnum == oap->start.lnum | |
2240 && oap->start.col == oap->end.col && oap->start.coladd) | |
2241 virtcols -= oap->start.coladd; | |
2242 | |
2243 /* oap->end has been trimmed so it's effectively inclusive; | |
2244 * as a result an extra +1 must be counted so we don't | |
2245 * trample the NUL byte. */ | |
2246 coladvance_force(getviscol2(oap->end.col, oap->end.coladd) + 1); | |
2247 curwin->w_cursor.col -= (virtcols + 1); | |
2248 for (; virtcols >= 0; virtcols--) | |
2249 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2250 PCHAR(curwin->w_cursor, c); |
7 | 2251 if (inc(&curwin->w_cursor) == -1) |
2252 break; | |
2253 } | |
2254 } | |
2255 #endif | |
2256 | |
2257 /* Advance to next character, stop at the end of the file. */ | |
2258 if (inc_cursor() == -1) | |
2259 break; | |
2260 } | |
2261 } | |
2262 | |
2263 curwin->w_cursor = oap->start; | |
2264 check_cursor(); | |
2265 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, 0L); | |
2266 | |
2267 /* Set "'[" and "']" marks. */ | |
2268 curbuf->b_op_start = oap->start; | |
2269 curbuf->b_op_end = oap->end; | |
2270 | |
2271 return OK; | |
2272 } | |
2273 #endif | |
2274 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
2275 static int swapchars(int op_type, pos_T *pos, int length); |
1525 | 2276 |
7 | 2277 /* |
2278 * Handle the (non-standard vi) tilde operator. Also for "gu", "gU" and "g?". | |
2279 */ | |
2280 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2281 op_tilde(oparg_T *oap) |
7 | 2282 { |
2283 pos_T pos; | |
2284 struct block_def bd; | |
1528 | 2285 int did_change = FALSE; |
7 | 2286 |
2287 if (u_save((linenr_T)(oap->start.lnum - 1), | |
2288 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
2289 return; | |
2290 | |
2291 pos = oap->start; | |
2292 if (oap->block_mode) /* Visual block mode */ | |
2293 { | |
2294 for (; pos.lnum <= oap->end.lnum; ++pos.lnum) | |
2295 { | |
1766 | 2296 int one_change; |
2297 | |
7 | 2298 block_prep(oap, &bd, pos.lnum, FALSE); |
2299 pos.col = bd.textcol; | |
1766 | 2300 one_change = swapchars(oap->op_type, &pos, bd.textlen); |
2301 did_change |= one_change; | |
1525 | 2302 |
5735 | 2303 #ifdef FEAT_NETBEANS_INTG |
2210 | 2304 if (netbeans_active() && one_change) |
7 | 2305 { |
2306 char_u *ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
2307 | |
33 | 2308 netbeans_removed(curbuf, pos.lnum, bd.textcol, |
2309 (long)bd.textlen); | |
7 | 2310 netbeans_inserted(curbuf, pos.lnum, bd.textcol, |
2210 | 2311 &ptr[bd.textcol], bd.textlen); |
7 | 2312 } |
5735 | 2313 #endif |
7 | 2314 } |
2315 if (did_change) | |
2316 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); | |
2317 } | |
2318 else /* not block mode */ | |
2319 { | |
2320 if (oap->motion_type == MLINE) | |
2321 { | |
2322 oap->start.col = 0; | |
2323 pos.col = 0; | |
2324 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
2325 if (oap->end.col) | |
2326 --oap->end.col; | |
2327 } | |
2328 else if (!oap->inclusive) | |
2329 dec(&(oap->end)); | |
2330 | |
1528 | 2331 if (pos.lnum == oap->end.lnum) |
2332 did_change = swapchars(oap->op_type, &pos, | |
2333 oap->end.col - pos.col + 1); | |
2334 else | |
2335 for (;;) | |
2336 { | |
2337 did_change |= swapchars(oap->op_type, &pos, | |
2338 pos.lnum == oap->end.lnum ? oap->end.col + 1: | |
2339 (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
|
2340 if (LTOREQ_POS(oap->end, pos) || inc(&pos) == -1) |
1528 | 2341 break; |
2342 } | |
7 | 2343 if (did_change) |
2344 { | |
2345 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, | |
2346 0L); | |
2347 #ifdef FEAT_NETBEANS_INTG | |
2210 | 2348 if (netbeans_active() && did_change) |
7 | 2349 { |
2350 char_u *ptr; | |
2351 int count; | |
2352 | |
2353 pos = oap->start; | |
2354 while (pos.lnum < oap->end.lnum) | |
2355 { | |
2356 ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
835 | 2357 count = (int)STRLEN(ptr) - pos.col; |
33 | 2358 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7 | 2359 netbeans_inserted(curbuf, pos.lnum, pos.col, |
2210 | 2360 &ptr[pos.col], count); |
7 | 2361 pos.col = 0; |
2362 pos.lnum++; | |
2363 } | |
2364 ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
2365 count = oap->end.col - pos.col + 1; | |
33 | 2366 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7 | 2367 netbeans_inserted(curbuf, pos.lnum, pos.col, |
2210 | 2368 &ptr[pos.col], count); |
7 | 2369 } |
2370 #endif | |
2371 } | |
2372 } | |
2373 | |
2374 if (!did_change && oap->is_VIsual) | |
2375 /* No change: need to remove the Visual selection */ | |
2376 redraw_curbuf_later(INVERTED); | |
2377 | |
2378 /* | |
2379 * Set '[ and '] marks. | |
2380 */ | |
2381 curbuf->b_op_start = oap->start; | |
2382 curbuf->b_op_end = oap->end; | |
2383 | |
2384 if (oap->line_count > p_report) | |
2385 { | |
2386 if (oap->line_count == 1) | |
2387 MSG(_("1 line changed")); | |
2388 else | |
2389 smsg((char_u *)_("%ld lines changed"), oap->line_count); | |
2390 } | |
2391 } | |
2392 | |
2393 /* | |
1525 | 2394 * Invoke swapchar() on "length" bytes at position "pos". |
2395 * "pos" is advanced to just after the changed characters. | |
2396 * "length" is rounded up to include the whole last multi-byte character. | |
2397 * Also works correctly when the number of bytes changes. | |
2398 * Returns TRUE if some character was changed. | |
2399 */ | |
2400 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2401 swapchars(int op_type, pos_T *pos, int length) |
1525 | 2402 { |
2403 int todo; | |
2404 int did_change = 0; | |
2405 | |
2406 for (todo = length; todo > 0; --todo) | |
2407 { | |
2408 # ifdef FEAT_MBYTE | |
2409 if (has_mbyte) | |
5288
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2410 { |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2411 int len = (*mb_ptr2len)(ml_get_pos(pos)); |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2412 |
1525 | 2413 /* we're counting bytes, not characters */ |
5288
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2414 if (len > 0) |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2415 todo -= len - 1; |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2416 } |
1525 | 2417 # endif |
2418 did_change |= swapchar(op_type, pos); | |
2419 if (inc(pos) == -1) /* at end of file */ | |
2420 break; | |
2421 } | |
2422 return did_change; | |
2423 } | |
2424 | |
2425 /* | |
7 | 2426 * If op_type == OP_UPPER: make uppercase, |
2427 * if op_type == OP_LOWER: make lowercase, | |
2428 * if op_type == OP_ROT13: do rot13 encoding, | |
2429 * else swap case of character at 'pos' | |
2430 * returns TRUE when something actually changed. | |
2431 */ | |
2432 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2433 swapchar(int op_type, pos_T *pos) |
7 | 2434 { |
2435 int c; | |
2436 int nc; | |
2437 | |
2438 c = gchar_pos(pos); | |
2439 | |
2440 /* Only do rot13 encoding for ASCII characters. */ | |
2441 if (c >= 0x80 && op_type == OP_ROT13) | |
2442 return FALSE; | |
2443 | |
2444 #ifdef FEAT_MBYTE | |
1525 | 2445 if (op_type == OP_UPPER && c == 0xdf |
2446 && (enc_latin1like || STRCMP(p_enc, "iso-8859-2") == 0)) | |
493 | 2447 { |
2448 pos_T sp = curwin->w_cursor; | |
2449 | |
2450 /* Special handling of German sharp s: change to "SS". */ | |
2451 curwin->w_cursor = *pos; | |
2452 del_char(FALSE); | |
2453 ins_char('S'); | |
2454 ins_char('S'); | |
2455 curwin->w_cursor = sp; | |
2456 inc(pos); | |
2457 } | |
2458 | |
7 | 2459 if (enc_dbcs != 0 && c >= 0x100) /* No lower/uppercase letter */ |
2460 return FALSE; | |
2461 #endif | |
2462 nc = c; | |
2463 if (MB_ISLOWER(c)) | |
2464 { | |
2465 if (op_type == OP_ROT13) | |
2466 nc = ROT13(c, 'a'); | |
2467 else if (op_type != OP_LOWER) | |
2468 nc = MB_TOUPPER(c); | |
2469 } | |
2470 else if (MB_ISUPPER(c)) | |
2471 { | |
2472 if (op_type == OP_ROT13) | |
2473 nc = ROT13(c, 'A'); | |
2474 else if (op_type != OP_UPPER) | |
2475 nc = MB_TOLOWER(c); | |
2476 } | |
2477 if (nc != c) | |
2478 { | |
2479 #ifdef FEAT_MBYTE | |
2480 if (enc_utf8 && (c >= 0x80 || nc >= 0x80)) | |
2481 { | |
2482 pos_T sp = curwin->w_cursor; | |
2483 | |
2484 curwin->w_cursor = *pos; | |
2451
0b8612c2814d
Fix: changing case of a character removed combining characters.
Bram Moolenaar <bram@vim.org>
parents:
2446
diff
changeset
|
2485 /* 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
|
2486 del_bytes(utf_ptr2len(ml_get_cursor()), FALSE, FALSE); |
7 | 2487 ins_char(nc); |
2488 curwin->w_cursor = sp; | |
2489 } | |
2490 else | |
2491 #endif | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2492 PCHAR(*pos, nc); |
7 | 2493 return TRUE; |
2494 } | |
2495 return FALSE; | |
2496 } | |
2497 | |
2498 #if defined(FEAT_VISUALEXTRA) || defined(PROTO) | |
2499 /* | |
2500 * op_insert - Insert and append operators for Visual mode. | |
2501 */ | |
2502 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2503 op_insert(oparg_T *oap, long count1) |
7 | 2504 { |
2505 long ins_len, pre_textlen = 0; | |
2506 char_u *firstline, *ins_text; | |
2507 struct block_def bd; | |
2508 int i; | |
6579 | 2509 pos_T t1; |
7 | 2510 |
2511 /* edit() changes this - record it for OP_APPEND */ | |
2512 bd.is_MAX = (curwin->w_curswant == MAXCOL); | |
2513 | |
2514 /* vis block is still marked. Get rid of it now. */ | |
2515 curwin->w_cursor.lnum = oap->start.lnum; | |
2516 update_screen(INVERTED); | |
2517 | |
2518 if (oap->block_mode) | |
2519 { | |
2520 #ifdef FEAT_VIRTUALEDIT | |
2521 /* When 'virtualedit' is used, need to insert the extra spaces before | |
2522 * doing block_prep(). When only "block" is used, virtual edit is | |
2523 * already disabled, but still need it when calling | |
2524 * coladvance_force(). */ | |
2525 if (curwin->w_cursor.coladd > 0) | |
2526 { | |
2527 int old_ve_flags = ve_flags; | |
2528 | |
2529 ve_flags = VE_ALL; | |
2530 if (u_save_cursor() == FAIL) | |
2531 return; | |
2532 coladvance_force(oap->op_type == OP_APPEND | |
2533 ? oap->end_vcol + 1 : getviscol()); | |
2534 if (oap->op_type == OP_APPEND) | |
2535 --curwin->w_cursor.col; | |
2536 ve_flags = old_ve_flags; | |
2537 } | |
2538 #endif | |
2539 /* Get the info about the block before entering the text */ | |
2540 block_prep(oap, &bd, oap->start.lnum, TRUE); | |
2541 firstline = ml_get(oap->start.lnum) + bd.textcol; | |
2542 if (oap->op_type == OP_APPEND) | |
2543 firstline += bd.textlen; | |
2544 pre_textlen = (long)STRLEN(firstline); | |
2545 } | |
2546 | |
2547 if (oap->op_type == OP_APPEND) | |
2548 { | |
2549 if (oap->block_mode | |
2550 #ifdef FEAT_VIRTUALEDIT | |
2551 && curwin->w_cursor.coladd == 0 | |
2552 #endif | |
2553 ) | |
2554 { | |
2555 /* Move the cursor to the character right of the block. */ | |
2556 curwin->w_set_curswant = TRUE; | |
2557 while (*ml_get_cursor() != NUL | |
2558 && (curwin->w_cursor.col < bd.textcol + bd.textlen)) | |
2559 ++curwin->w_cursor.col; | |
2560 if (bd.is_short && !bd.is_MAX) | |
2561 { | |
2562 /* First line was too short, make it longer and adjust the | |
2563 * values in "bd". */ | |
2564 if (u_save_cursor() == FAIL) | |
2565 return; | |
2566 for (i = 0; i < bd.endspaces; ++i) | |
2567 ins_char(' '); | |
2568 bd.textlen += bd.endspaces; | |
2569 } | |
2570 } | |
2571 else | |
2572 { | |
2573 curwin->w_cursor = oap->end; | |
893 | 2574 check_cursor_col(); |
7 | 2575 |
2576 /* 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
|
2577 if (!LINEEMPTY(curwin->w_cursor.lnum) |
7 | 2578 && oap->start_vcol != oap->end_vcol) |
2579 inc_cursor(); | |
2580 } | |
2581 } | |
2582 | |
6579 | 2583 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
|
2584 (void)edit(NUL, FALSE, (linenr_T)count1); |
7 | 2585 |
6579 | 2586 /* When a tab was inserted, and the characters in front of the tab |
2587 * have been converted to a tab as well, the column of the cursor | |
2588 * might have actually been reduced, so need to adjust here. */ | |
2589 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
|
2590 && LT_POS(curbuf->b_op_start_orig, t1)) |
6579 | 2591 oap->start = curbuf->b_op_start_orig; |
2592 | |
1477 | 2593 /* If user has moved off this line, we don't know what to do, so do |
2594 * nothing. | |
2595 * Also don't repeat the insert when Insert mode ended with CTRL-C. */ | |
2596 if (curwin->w_cursor.lnum != oap->start.lnum || got_int) | |
7 | 2597 return; |
2598 | |
2599 if (oap->block_mode) | |
2600 { | |
2601 struct block_def bd2; | |
2602 | |
5471 | 2603 /* The user may have moved the cursor before inserting something, try |
2604 * to adjust the block for that. */ | |
5680 | 2605 if (oap->start.lnum == curbuf->b_op_start_orig.lnum && !bd.is_MAX) |
5471 | 2606 { |
2607 if (oap->op_type == OP_INSERT | |
5730 | 2608 && oap->start.col |
2609 #ifdef FEAT_VIRTUALEDIT | |
2610 + oap->start.coladd | |
2611 #endif | |
2612 != curbuf->b_op_start_orig.col | |
2613 #ifdef FEAT_VIRTUALEDIT | |
2614 + curbuf->b_op_start_orig.coladd | |
2615 #endif | |
2616 ) | |
5471 | 2617 { |
6579 | 2618 int t = getviscol2(curbuf->b_op_start_orig.col, |
2619 curbuf->b_op_start_orig.coladd); | |
5680 | 2620 oap->start.col = curbuf->b_op_start_orig.col; |
6579 | 2621 pre_textlen -= t - oap->start_vcol; |
2622 oap->start_vcol = t; | |
5471 | 2623 } |
2624 else if (oap->op_type == OP_APPEND | |
5730 | 2625 && oap->end.col |
2626 #ifdef FEAT_VIRTUALEDIT | |
2627 + oap->end.coladd | |
2628 #endif | |
2629 >= curbuf->b_op_start_orig.col | |
2630 #ifdef FEAT_VIRTUALEDIT | |
2631 + curbuf->b_op_start_orig.coladd | |
2632 #endif | |
2633 ) | |
5471 | 2634 { |
6579 | 2635 int t = getviscol2(curbuf->b_op_start_orig.col, |
2636 curbuf->b_op_start_orig.coladd); | |
5680 | 2637 oap->start.col = curbuf->b_op_start_orig.col; |
5471 | 2638 /* reset pre_textlen to the value of OP_INSERT */ |
2639 pre_textlen += bd.textlen; | |
6579 | 2640 pre_textlen -= t - oap->start_vcol; |
2641 oap->start_vcol = t; | |
5471 | 2642 oap->op_type = OP_INSERT; |
2643 } | |
2644 } | |
2645 | |
7 | 2646 /* |
2647 * Spaces and tabs in the indent may have changed to other spaces and | |
1392 | 2648 * tabs. Get the starting column again and correct the length. |
7 | 2649 * Don't do this when "$" used, end-of-line will have changed. |
2650 */ | |
2651 block_prep(oap, &bd2, oap->start.lnum, TRUE); | |
2652 if (!bd.is_MAX || bd2.textlen < bd.textlen) | |
2653 { | |
2654 if (oap->op_type == OP_APPEND) | |
2655 { | |
2656 pre_textlen += bd2.textlen - bd.textlen; | |
2657 if (bd2.endspaces) | |
2658 --bd2.textlen; | |
2659 } | |
2660 bd.textcol = bd2.textcol; | |
2661 bd.textlen = bd2.textlen; | |
2662 } | |
2663 | |
2664 /* | |
2665 * Subsequent calls to ml_get() flush the firstline data - take a | |
2666 * copy of the required string. | |
2667 */ | |
2668 firstline = ml_get(oap->start.lnum) + bd.textcol; | |
2669 if (oap->op_type == OP_APPEND) | |
2670 firstline += bd.textlen; | |
3421 | 2671 if (pre_textlen >= 0 |
2672 && (ins_len = (long)STRLEN(firstline) - pre_textlen) > 0) | |
7 | 2673 { |
2674 ins_text = vim_strnsave(firstline, (int)ins_len); | |
2675 if (ins_text != NULL) | |
2676 { | |
2677 /* block handled here */ | |
2678 if (u_save(oap->start.lnum, | |
2679 (linenr_T)(oap->end.lnum + 1)) == OK) | |
2680 block_insert(oap, ins_text, (oap->op_type == OP_INSERT), | |
2681 &bd); | |
2682 | |
2683 curwin->w_cursor.col = oap->start.col; | |
2684 check_cursor(); | |
2685 vim_free(ins_text); | |
2686 } | |
2687 } | |
2688 } | |
2689 } | |
2690 #endif | |
2691 | |
2692 /* | |
2693 * op_change - handle a change operation | |
2694 * | |
2695 * return TRUE if edit() returns because of a CTRL-O command | |
2696 */ | |
2697 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2698 op_change(oparg_T *oap) |
7 | 2699 { |
2700 colnr_T l; | |
2701 int retval; | |
2702 #ifdef FEAT_VISUALEXTRA | |
2703 long offset; | |
2704 linenr_T linenr; | |
1392 | 2705 long ins_len; |
2706 long pre_textlen = 0; | |
2707 long pre_indent = 0; | |
7 | 2708 char_u *firstline; |
2709 char_u *ins_text, *newp, *oldp; | |
2710 struct block_def bd; | |
2711 #endif | |
2712 | |
2713 l = oap->start.col; | |
2714 if (oap->motion_type == MLINE) | |
2715 { | |
2716 l = 0; | |
2717 #ifdef FEAT_SMARTINDENT | |
2718 if (!p_paste && curbuf->b_p_si | |
2719 # ifdef FEAT_CINDENT | |
2720 && !curbuf->b_p_cin | |
2721 # endif | |
2722 ) | |
2723 can_si = TRUE; /* It's like opening a new line, do si */ | |
2724 #endif | |
2725 } | |
2726 | |
2727 /* First delete the text in the region. In an empty buffer only need to | |
2728 * save for undo */ | |
2729 if (curbuf->b_ml.ml_flags & ML_EMPTY) | |
2730 { | |
2731 if (u_save_cursor() == FAIL) | |
2732 return FALSE; | |
2733 } | |
2734 else if (op_delete(oap) == FAIL) | |
2735 return FALSE; | |
2736 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2737 if ((l > curwin->w_cursor.col) && !LINEEMPTY(curwin->w_cursor.lnum) |
7 | 2738 && !virtual_op) |
2739 inc_cursor(); | |
2740 | |
2741 #ifdef FEAT_VISUALEXTRA | |
2742 /* check for still on same line (<CR> in inserted text meaningless) */ | |
2743 /* skip blank lines too */ | |
2744 if (oap->block_mode) | |
2745 { | |
2746 # ifdef FEAT_VIRTUALEDIT | |
2747 /* Add spaces before getting the current line length. */ | |
2748 if (virtual_op && (curwin->w_cursor.coladd > 0 | |
2749 || gchar_cursor() == NUL)) | |
2750 coladvance_force(getviscol()); | |
2751 # endif | |
1392 | 2752 firstline = ml_get(oap->start.lnum); |
2753 pre_textlen = (long)STRLEN(firstline); | |
2754 pre_indent = (long)(skipwhite(firstline) - firstline); | |
7 | 2755 bd.textcol = curwin->w_cursor.col; |
2756 } | |
2757 #endif | |
2758 | |
2759 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) | |
2760 if (oap->motion_type == MLINE) | |
2761 fix_indent(); | |
2762 #endif | |
2763 | |
2764 retval = edit(NUL, FALSE, (linenr_T)1); | |
2765 | |
2766 #ifdef FEAT_VISUALEXTRA | |
2767 /* | |
39 | 2768 * In Visual block mode, handle copying the new text to all lines of the |
7 | 2769 * block. |
1477 | 2770 * Don't repeat the insert when Insert mode ended with CTRL-C. |
7 | 2771 */ |
1477 | 2772 if (oap->block_mode && oap->start.lnum != oap->end.lnum && !got_int) |
7 | 2773 { |
1392 | 2774 /* Auto-indenting may have changed the indent. If the cursor was past |
2775 * the indent, exclude that indent change from the inserted text. */ | |
7 | 2776 firstline = ml_get(oap->start.lnum); |
1403 | 2777 if (bd.textcol > (colnr_T)pre_indent) |
7 | 2778 { |
1392 | 2779 long new_indent = (long)(skipwhite(firstline) - firstline); |
2780 | |
2781 pre_textlen += new_indent - pre_indent; | |
2782 bd.textcol += new_indent - pre_indent; | |
2783 } | |
2784 | |
2785 ins_len = (long)STRLEN(firstline) - pre_textlen; | |
2786 if (ins_len > 0) | |
2787 { | |
2788 /* Subsequent calls to ml_get() flush the firstline data - take a | |
2789 * copy of the inserted text. */ | |
7 | 2790 if ((ins_text = alloc_check((unsigned)(ins_len + 1))) != NULL) |
2791 { | |
419 | 2792 vim_strncpy(ins_text, firstline + bd.textcol, (size_t)ins_len); |
7 | 2793 for (linenr = oap->start.lnum + 1; linenr <= oap->end.lnum; |
2794 linenr++) | |
2795 { | |
2796 block_prep(oap, &bd, linenr, TRUE); | |
2797 if (!bd.is_short || virtual_op) | |
2798 { | |
2799 # ifdef FEAT_VIRTUALEDIT | |
2800 pos_T vpos; | |
2801 | |
2802 /* If the block starts in virtual space, count the | |
2803 * initial coladd offset as part of "startspaces" */ | |
2804 if (bd.is_short) | |
2805 { | |
1982 | 2806 vpos.lnum = linenr; |
7 | 2807 (void)getvpos(&vpos, oap->start_vcol); |
2808 } | |
2809 else | |
2810 vpos.coladd = 0; | |
2811 # endif | |
2812 oldp = ml_get(linenr); | |
2813 newp = alloc_check((unsigned)(STRLEN(oldp) | |
2814 # ifdef FEAT_VIRTUALEDIT | |
2815 + vpos.coladd | |
2816 # endif | |
2817 + ins_len + 1)); | |
2818 if (newp == NULL) | |
2819 continue; | |
2820 /* copy up to block start */ | |
2821 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
2822 offset = bd.textcol; | |
2823 # ifdef FEAT_VIRTUALEDIT | |
6929 | 2824 vim_memset(newp + offset, ' ', (size_t)vpos.coladd); |
7 | 2825 offset += vpos.coladd; |
2826 # endif | |
2827 mch_memmove(newp + offset, ins_text, (size_t)ins_len); | |
2828 offset += ins_len; | |
2829 oldp += bd.textcol; | |
1622 | 2830 STRMOVE(newp + offset, oldp); |
7 | 2831 ml_replace(linenr, newp, FALSE); |
2832 } | |
2833 } | |
2834 check_cursor(); | |
2835 | |
2836 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); | |
2837 } | |
2838 vim_free(ins_text); | |
2839 } | |
2840 } | |
2841 #endif | |
2842 | |
2843 return retval; | |
2844 } | |
2845 | |
2846 /* | |
2847 * set all the yank registers to empty (called from main()) | |
2848 */ | |
2849 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2850 init_yank(void) |
7 | 2851 { |
2852 int i; | |
2853 | |
2854 for (i = 0; i < NUM_REGISTERS; ++i) | |
2855 y_regs[i].y_array = NULL; | |
2856 } | |
2857 | |
356 | 2858 #if defined(EXITFREE) || defined(PROTO) |
2859 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2860 clear_registers(void) |
356 | 2861 { |
2862 int i; | |
2863 | |
2864 for (i = 0; i < NUM_REGISTERS; ++i) | |
2865 { | |
2866 y_current = &y_regs[i]; | |
2867 if (y_current->y_array != NULL) | |
2868 free_yank_all(); | |
2869 } | |
2870 } | |
2871 #endif | |
2872 | |
7 | 2873 /* |
2874 * Free "n" lines from the current yank register. | |
2875 * Called for normal freeing and in case of error. | |
2876 */ | |
2877 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2878 free_yank(long n) |
7 | 2879 { |
2880 if (y_current->y_array != NULL) | |
2881 { | |
2882 long i; | |
2883 | |
2884 for (i = n; --i >= 0; ) | |
2885 { | |
2886 #ifdef AMIGA /* only for very slow machines */ | |
2887 if ((i & 1023) == 1023) /* this may take a while */ | |
2888 { | |
2889 /* | |
2890 * This message should never cause a hit-return message. | |
2891 * Overwrite this message with any next message. | |
2892 */ | |
2893 ++no_wait_return; | |
2894 smsg((char_u *)_("freeing %ld lines"), i + 1); | |
2895 --no_wait_return; | |
2896 msg_didout = FALSE; | |
2897 msg_col = 0; | |
2898 } | |
2899 #endif | |
2900 vim_free(y_current->y_array[i]); | |
2901 } | |
2902 vim_free(y_current->y_array); | |
2903 y_current->y_array = NULL; | |
2904 #ifdef AMIGA | |
2905 if (n >= 1000) | |
2906 MSG(""); | |
2907 #endif | |
2908 } | |
2909 } | |
2910 | |
2911 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2912 free_yank_all(void) |
7 | 2913 { |
2914 free_yank(y_current->y_size); | |
2915 } | |
2916 | |
2917 /* | |
2918 * Yank the text between "oap->start" and "oap->end" into a yank register. | |
2919 * If we are to append (uppercase register), we first yank into a new yank | |
2920 * register and then concatenate the old and the new one (so we keep the old | |
2921 * one in case of out-of-memory). | |
2922 * | |
5245
8c6615a30951
updated for version 7.4a.047
Bram Moolenaar <bram@vim.org>
parents:
5182
diff
changeset
|
2923 * Return FAIL for failure, OK otherwise. |
7 | 2924 */ |
2925 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2926 op_yank(oparg_T *oap, int deleting, int mess) |
7 | 2927 { |
2928 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
|
2929 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
|
2930 yankreg_T newreg; /* new yank register when appending */ |
7 | 2931 char_u **new_ptr; |
2932 linenr_T lnum; /* current line number */ | |
2933 long j; | |
2934 int yanktype = oap->motion_type; | |
2935 long yanklines = oap->line_count; | |
2936 linenr_T yankendlnum = oap->end.lnum; | |
2937 char_u *p; | |
2938 char_u *pnew; | |
2939 struct block_def bd; | |
2658 | 2940 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
2654 | 2941 int did_star = FALSE; |
2658 | 2942 #endif |
7 | 2943 |
2944 /* check for read-only register */ | |
2945 if (oap->regname != 0 && !valid_yank_reg(oap->regname, TRUE)) | |
2946 { | |
2947 beep_flush(); | |
2948 return FAIL; | |
2949 } | |
2950 if (oap->regname == '_') /* black hole: nothing to do */ | |
2951 return OK; | |
2952 | |
2953 #ifdef FEAT_CLIPBOARD | |
2954 if (!clip_star.available && oap->regname == '*') | |
2955 oap->regname = 0; | |
2956 else if (!clip_plus.available && oap->regname == '+') | |
2957 oap->regname = 0; | |
2958 #endif | |
2959 | |
2960 if (!deleting) /* op_delete() already set y_current */ | |
2961 get_yank_register(oap->regname, TRUE); | |
2962 | |
2963 curr = y_current; | |
2964 /* append to existing contents */ | |
2965 if (y_append && y_current->y_array != NULL) | |
2966 y_current = &newreg; | |
2967 else | |
2968 free_yank_all(); /* free previously yanked lines */ | |
2969 | |
593 | 2970 /* |
2971 * If the cursor was in column 1 before and after the movement, and the | |
2972 * operator is not inclusive, the yank is always linewise. | |
2973 */ | |
7 | 2974 if ( oap->motion_type == MCHAR |
2975 && oap->start.col == 0 | |
2976 && !oap->inclusive | |
2977 && (!oap->is_VIsual || *p_sel == 'o') | |
50 | 2978 && !oap->block_mode |
7 | 2979 && oap->end.col == 0 |
2980 && yanklines > 1) | |
2981 { | |
2982 yanktype = MLINE; | |
2983 --yankendlnum; | |
2984 --yanklines; | |
2985 } | |
2986 | |
2987 y_current->y_size = yanklines; | |
2988 y_current->y_type = yanktype; /* set the yank register type */ | |
2989 y_current->y_width = 0; | |
2990 y_current->y_array = (char_u **)lalloc_clear((long_u)(sizeof(char_u *) * | |
2991 yanklines), TRUE); | |
2992 if (y_current->y_array == NULL) | |
2993 { | |
2994 y_current = curr; | |
2995 return FAIL; | |
2996 } | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
2997 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
2998 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
|
2999 #endif |
7 | 3000 |
3001 y_idx = 0; | |
3002 lnum = oap->start.lnum; | |
3003 | |
3004 if (oap->block_mode) | |
3005 { | |
3006 /* Visual block mode */ | |
3007 y_current->y_type = MBLOCK; /* set the yank register type */ | |
3008 y_current->y_width = oap->end_vcol - oap->start_vcol; | |
3009 | |
3010 if (curwin->w_curswant == MAXCOL && y_current->y_width > 0) | |
3011 y_current->y_width--; | |
3012 } | |
3013 | |
3014 for ( ; lnum <= yankendlnum; lnum++, y_idx++) | |
3015 { | |
3016 switch (y_current->y_type) | |
3017 { | |
3018 case MBLOCK: | |
3019 block_prep(oap, &bd, lnum, FALSE); | |
3020 if (yank_copy_line(&bd, y_idx) == FAIL) | |
3021 goto fail; | |
3022 break; | |
3023 | |
3024 case MLINE: | |
3025 if ((y_current->y_array[y_idx] = | |
3026 vim_strsave(ml_get(lnum))) == NULL) | |
3027 goto fail; | |
3028 break; | |
3029 | |
3030 case MCHAR: | |
3031 { | |
3032 colnr_T startcol = 0, endcol = MAXCOL; | |
3033 #ifdef FEAT_VIRTUALEDIT | |
3034 int is_oneChar = FALSE; | |
3035 colnr_T cs, ce; | |
3036 #endif | |
3037 p = ml_get(lnum); | |
3038 bd.startspaces = 0; | |
3039 bd.endspaces = 0; | |
3040 | |
3041 if (lnum == oap->start.lnum) | |
3042 { | |
3043 startcol = oap->start.col; | |
3044 #ifdef FEAT_VIRTUALEDIT | |
3045 if (virtual_op) | |
3046 { | |
3047 getvcol(curwin, &oap->start, &cs, NULL, &ce); | |
3048 if (ce != cs && oap->start.coladd > 0) | |
3049 { | |
3050 /* Part of a tab selected -- but don't | |
3051 * double-count it. */ | |
3052 bd.startspaces = (ce - cs + 1) | |
3053 - oap->start.coladd; | |
3054 startcol++; | |
3055 } | |
3056 } | |
3057 #endif | |
3058 } | |
3059 | |
3060 if (lnum == oap->end.lnum) | |
3061 { | |
3062 endcol = oap->end.col; | |
3063 #ifdef FEAT_VIRTUALEDIT | |
3064 if (virtual_op) | |
3065 { | |
3066 getvcol(curwin, &oap->end, &cs, NULL, &ce); | |
3067 if (p[endcol] == NUL || (cs + oap->end.coladd < ce | |
3068 # ifdef FEAT_MBYTE | |
3069 /* Don't add space for double-wide | |
3070 * char; endcol will be on last byte | |
3071 * of multi-byte char. */ | |
3072 && (*mb_head_off)(p, p + endcol) == 0 | |
3073 # endif | |
3074 )) | |
3075 { | |
3076 if (oap->start.lnum == oap->end.lnum | |
3077 && oap->start.col == oap->end.col) | |
3078 { | |
3079 /* Special case: inside a single char */ | |
3080 is_oneChar = TRUE; | |
3081 bd.startspaces = oap->end.coladd | |
3082 - oap->start.coladd + oap->inclusive; | |
3083 endcol = startcol; | |
3084 } | |
3085 else | |
3086 { | |
3087 bd.endspaces = oap->end.coladd | |
3088 + oap->inclusive; | |
3089 endcol -= oap->inclusive; | |
3090 } | |
3091 } | |
3092 } | |
3093 #endif | |
3094 } | |
3510 | 3095 if (endcol == MAXCOL) |
3096 endcol = (colnr_T)STRLEN(p); | |
7 | 3097 if (startcol > endcol |
3098 #ifdef FEAT_VIRTUALEDIT | |
3099 || is_oneChar | |
3100 #endif | |
3101 ) | |
3102 bd.textlen = 0; | |
3103 else | |
3104 { | |
3105 bd.textlen = endcol - startcol + oap->inclusive; | |
3106 } | |
3107 bd.textstart = p + startcol; | |
3108 if (yank_copy_line(&bd, y_idx) == FAIL) | |
3109 goto fail; | |
3110 break; | |
3111 } | |
3112 /* NOTREACHED */ | |
3113 } | |
3114 } | |
3115 | |
3116 if (curr != y_current) /* append the new block to the old block */ | |
3117 { | |
3118 new_ptr = (char_u **)lalloc((long_u)(sizeof(char_u *) * | |
3119 (curr->y_size + y_current->y_size)), TRUE); | |
3120 if (new_ptr == NULL) | |
3121 goto fail; | |
3122 for (j = 0; j < curr->y_size; ++j) | |
3123 new_ptr[j] = curr->y_array[j]; | |
3124 vim_free(curr->y_array); | |
3125 curr->y_array = new_ptr; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3126 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3127 curr->y_time_set = vim_time(); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3128 #endif |
7 | 3129 |
3130 if (yanktype == MLINE) /* MLINE overrides MCHAR and MBLOCK */ | |
3131 curr->y_type = MLINE; | |
3132 | |
164 | 3133 /* Concatenate the last line of the old block with the first line of |
3134 * the new block, unless being Vi compatible. */ | |
3135 if (curr->y_type == MCHAR && vim_strchr(p_cpo, CPO_REGAPPEND) == NULL) | |
7 | 3136 { |
3137 pnew = lalloc((long_u)(STRLEN(curr->y_array[curr->y_size - 1]) | |
3138 + STRLEN(y_current->y_array[0]) + 1), TRUE); | |
3139 if (pnew == NULL) | |
3140 { | |
3141 y_idx = y_current->y_size - 1; | |
3142 goto fail; | |
3143 } | |
3144 STRCPY(pnew, curr->y_array[--j]); | |
3145 STRCAT(pnew, y_current->y_array[0]); | |
3146 vim_free(curr->y_array[j]); | |
3147 vim_free(y_current->y_array[0]); | |
3148 curr->y_array[j++] = pnew; | |
3149 y_idx = 1; | |
3150 } | |
3151 else | |
3152 y_idx = 0; | |
3153 while (y_idx < y_current->y_size) | |
3154 curr->y_array[j++] = y_current->y_array[y_idx++]; | |
3155 curr->y_size = j; | |
3156 vim_free(y_current->y_array); | |
3157 y_current = curr; | |
3158 } | |
5981 | 3159 if (curwin->w_p_rnu) |
3160 redraw_later(SOME_VALID); /* cursor moved to start */ | |
7 | 3161 if (mess) /* Display message about yank? */ |
3162 { | |
3163 if (yanktype == MCHAR | |
3164 && !oap->block_mode | |
3165 && yanklines == 1) | |
3166 yanklines = 0; | |
3167 /* Some versions of Vi use ">=" here, some don't... */ | |
3168 if (yanklines > p_report) | |
3169 { | |
11682
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3170 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
|
3171 |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3172 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
|
3173 *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
|
3174 else |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3175 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
|
3176 _(" 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
|
3177 |
7 | 3178 /* redisplay now, so message is not deleted */ |
3179 update_topline_redraw(); | |
3180 if (yanklines == 1) | |
205 | 3181 { |
3182 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
|
3183 smsg((char_u *)_("block of 1 line yanked%s"), namebuf); |
205 | 3184 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
|
3185 smsg((char_u *)_("1 line yanked%s"), namebuf); |
205 | 3186 } |
3187 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
|
3188 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
|
3189 yanklines, namebuf); |
7 | 3190 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
|
3191 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
|
3192 namebuf); |
7 | 3193 } |
3194 } | |
3195 | |
3196 /* | |
3197 * Set "'[" and "']" marks. | |
3198 */ | |
3199 curbuf->b_op_start = oap->start; | |
3200 curbuf->b_op_end = oap->end; | |
5735 | 3201 if (yanktype == MLINE && !oap->block_mode) |
36 | 3202 { |
3203 curbuf->b_op_start.col = 0; | |
3204 curbuf->b_op_end.col = MAXCOL; | |
3205 } | |
7 | 3206 |
3207 #ifdef FEAT_CLIPBOARD | |
3208 /* | |
3209 * If we were yanking to the '*' register, send result to clipboard. | |
3210 * If no register was specified, and "unnamed" in 'clipboard', make a copy | |
3211 * to the '*' register. | |
3212 */ | |
3213 if (clip_star.available | |
3214 && (curr == &(y_regs[STAR_REGISTER]) | |
2654 | 3215 || (!deleting && oap->regname == 0 |
6116 | 3216 && ((clip_unnamed | clip_unnamed_saved) & CLIP_UNNAMED)))) |
7 | 3217 { |
3218 if (curr != &(y_regs[STAR_REGISTER])) | |
3219 /* Copy the text from register 0 to the clipboard register. */ | |
3220 copy_yank_reg(&(y_regs[STAR_REGISTER])); | |
3221 | |
3222 clip_own_selection(&clip_star); | |
3223 clip_gen_set_selection(&clip_star); | |
2658 | 3224 # ifdef FEAT_X11 |
2654 | 3225 did_star = TRUE; |
2658 | 3226 # endif |
7 | 3227 } |
3228 | |
3229 # ifdef FEAT_X11 | |
3230 /* | |
3231 * If we were yanking to the '+' register, send result to selection. | |
3232 * Also copy to the '*' register, in case auto-select is off. | |
3233 */ | |
2654 | 3234 if (clip_plus.available |
3235 && (curr == &(y_regs[PLUS_REGISTER]) | |
3236 || (!deleting && oap->regname == 0 | |
6116 | 3237 && ((clip_unnamed | clip_unnamed_saved) & |
3238 CLIP_UNNAMED_PLUS)))) | |
7 | 3239 { |
2654 | 3240 if (curr != &(y_regs[PLUS_REGISTER])) |
3241 /* Copy the text from register 0 to the clipboard register. */ | |
3242 copy_yank_reg(&(y_regs[PLUS_REGISTER])); | |
3243 | |
7 | 3244 clip_own_selection(&clip_plus); |
3245 clip_gen_set_selection(&clip_plus); | |
3674 | 3246 if (!clip_isautosel_star() && !did_star |
3247 && curr == &(y_regs[PLUS_REGISTER])) | |
7 | 3248 { |
3249 copy_yank_reg(&(y_regs[STAR_REGISTER])); | |
3250 clip_own_selection(&clip_star); | |
3251 clip_gen_set_selection(&clip_star); | |
3252 } | |
3253 } | |
3254 # endif | |
3255 #endif | |
3256 | |
3257 return OK; | |
3258 | |
3259 fail: /* free the allocated lines */ | |
3260 free_yank(y_idx + 1); | |
3261 y_current = curr; | |
3262 return FAIL; | |
3263 } | |
3264 | |
3265 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3266 yank_copy_line(struct block_def *bd, long y_idx) |
7 | 3267 { |
3268 char_u *pnew; | |
3269 | |
3270 if ((pnew = alloc(bd->startspaces + bd->endspaces + bd->textlen + 1)) | |
3271 == NULL) | |
3272 return FAIL; | |
3273 y_current->y_array[y_idx] = pnew; | |
6929 | 3274 vim_memset(pnew, ' ', (size_t)bd->startspaces); |
7 | 3275 pnew += bd->startspaces; |
3276 mch_memmove(pnew, bd->textstart, (size_t)bd->textlen); | |
3277 pnew += bd->textlen; | |
6929 | 3278 vim_memset(pnew, ' ', (size_t)bd->endspaces); |
7 | 3279 pnew += bd->endspaces; |
3280 *pnew = NUL; | |
3281 return OK; | |
3282 } | |
3283 | |
3284 #ifdef FEAT_CLIPBOARD | |
3285 /* | |
3286 * Make a copy of the y_current register to register "reg". | |
3287 */ | |
3288 static void | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3289 copy_yank_reg(yankreg_T *reg) |
7 | 3290 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3291 yankreg_T *curr = y_current; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3292 long j; |
7 | 3293 |
3294 y_current = reg; | |
3295 free_yank_all(); | |
3296 *y_current = *curr; | |
3297 y_current->y_array = (char_u **)lalloc_clear( | |
3298 (long_u)(sizeof(char_u *) * y_current->y_size), TRUE); | |
3299 if (y_current->y_array == NULL) | |
3300 y_current->y_size = 0; | |
3301 else | |
3302 for (j = 0; j < y_current->y_size; ++j) | |
3303 if ((y_current->y_array[j] = vim_strsave(curr->y_array[j])) == NULL) | |
3304 { | |
3305 free_yank(j); | |
3306 y_current->y_size = 0; | |
3307 break; | |
3308 } | |
3309 y_current = curr; | |
3310 } | |
3311 #endif | |
3312 | |
3313 /* | |
140 | 3314 * Put contents of register "regname" into the text. |
3315 * Caller must check "regname" to be valid! | |
3316 * "flags": PUT_FIXINDENT make indent look nice | |
3317 * PUT_CURSEND leave cursor after end of new text | |
3318 * PUT_LINE force linewise put (":put") | |
7 | 3319 */ |
3320 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3321 do_put( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3322 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3323 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
|
3324 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3325 int flags) |
7 | 3326 { |
3327 char_u *ptr; | |
3328 char_u *newp, *oldp; | |
3329 int yanklen; | |
3330 int totlen = 0; /* init for gcc */ | |
3331 linenr_T lnum; | |
3332 colnr_T col; | |
3333 long i; /* index in y_array[] */ | |
3334 int y_type; | |
3335 long y_size; | |
3336 int oldlen; | |
3337 long y_width = 0; | |
3338 colnr_T vcol; | |
3339 int delcount; | |
3340 int incr = 0; | |
3341 long j; | |
3342 struct block_def bd; | |
3343 char_u **y_array = NULL; | |
3344 long nr_lines = 0; | |
3345 pos_T new_cursor; | |
3346 int indent; | |
3347 int orig_indent = 0; /* init for gcc */ | |
3348 int indent_diff = 0; /* init for gcc */ | |
3349 int first_indent = TRUE; | |
3350 int lendiff = 0; | |
3351 pos_T old_pos; | |
3352 char_u *insert_string = NULL; | |
3353 int allocated = FALSE; | |
3354 long cnt; | |
3355 | |
3356 #ifdef FEAT_CLIPBOARD | |
3357 /* Adjust register name for "unnamed" in 'clipboard'. */ | |
3358 adjust_clip_reg(®name); | |
3359 (void)may_get_selection(regname); | |
3360 #endif | |
3361 | |
3362 if (flags & PUT_FIXINDENT) | |
3363 orig_indent = get_indent(); | |
3364 | |
3365 curbuf->b_op_start = curwin->w_cursor; /* default for '[ mark */ | |
3366 curbuf->b_op_end = curwin->w_cursor; /* default for '] mark */ | |
3367 | |
3368 /* | |
3369 * Using inserted text works differently, because the register includes | |
3370 * special characters (newlines, etc.). | |
3371 */ | |
3372 if (regname == '.') | |
3373 { | |
10494
1e700d72561d
commit https://github.com/vim/vim/commit/f8eb9c51e5bbd10e59c9b1247f8f6c7f5b77ccd0
Christian Brabandt <cb@256bit.org>
parents:
10486
diff
changeset
|
3374 if (VIsual_active) |
1e700d72561d
commit https://github.com/vim/vim/commit/f8eb9c51e5bbd10e59c9b1247f8f6c7f5b77ccd0
Christian Brabandt <cb@256bit.org>
parents:
10486
diff
changeset
|
3375 stuffcharReadbuff(VIsual_mode); |
7 | 3376 (void)stuff_inserted((dir == FORWARD ? (count == -1 ? 'o' : 'a') : |
3377 (count == -1 ? 'O' : 'i')), count, FALSE); | |
3378 /* Putting the text is done later, so can't really move the cursor to | |
3379 * the next character. Use "l" to simulate it. */ | |
3380 if ((flags & PUT_CURSEND) && gchar_cursor() != NUL) | |
3381 stuffcharReadbuff('l'); | |
3382 return; | |
3383 } | |
3384 | |
3385 /* | |
3386 * For special registers '%' (file name), '#' (alternate file name) and | |
3387 * ':' (last command line), etc. we have to create a fake yank register. | |
3388 */ | |
3389 if (get_spec_reg(regname, &insert_string, &allocated, TRUE)) | |
3390 { | |
3391 if (insert_string == NULL) | |
3392 return; | |
3393 } | |
3394 | |
4005 | 3395 #ifdef FEAT_AUTOCMD |
3396 /* Autocommands may be executed when saving lines for undo, which may make | |
3397 * y_array invalid. Start undo now to avoid that. */ | |
3398 u_save(curwin->w_cursor.lnum, curwin->w_cursor.lnum + 1); | |
3399 #endif | |
3400 | |
7 | 3401 if (insert_string != NULL) |
3402 { | |
3403 y_type = MCHAR; | |
3404 #ifdef FEAT_EVAL | |
3405 if (regname == '=') | |
3406 { | |
3407 /* For the = register we need to split the string at NL | |
3093 | 3408 * characters. |
3409 * Loop twice: count the number of lines and save them. */ | |
7 | 3410 for (;;) |
3411 { | |
3412 y_size = 0; | |
3413 ptr = insert_string; | |
3414 while (ptr != NULL) | |
3415 { | |
3416 if (y_array != NULL) | |
3417 y_array[y_size] = ptr; | |
3418 ++y_size; | |
3419 ptr = vim_strchr(ptr, '\n'); | |
3420 if (ptr != NULL) | |
3421 { | |
3422 if (y_array != NULL) | |
3423 *ptr = NUL; | |
3424 ++ptr; | |
3093 | 3425 /* A trailing '\n' makes the register linewise. */ |
7 | 3426 if (*ptr == NUL) |
3427 { | |
3428 y_type = MLINE; | |
3429 break; | |
3430 } | |
3431 } | |
3432 } | |
3433 if (y_array != NULL) | |
3434 break; | |
3435 y_array = (char_u **)alloc((unsigned) | |
3436 (y_size * sizeof(char_u *))); | |
3437 if (y_array == NULL) | |
3438 goto end; | |
3439 } | |
3440 } | |
3441 else | |
3442 #endif | |
3443 { | |
3444 y_size = 1; /* use fake one-line yank register */ | |
3445 y_array = &insert_string; | |
3446 } | |
3447 } | |
3448 else | |
3449 { | |
3450 get_yank_register(regname, FALSE); | |
3451 | |
3452 y_type = y_current->y_type; | |
3453 y_width = y_current->y_width; | |
3454 y_size = y_current->y_size; | |
3455 y_array = y_current->y_array; | |
3456 } | |
3457 | |
3458 if (y_type == MLINE) | |
3459 { | |
3460 if (flags & PUT_LINE_SPLIT) | |
3461 { | |
6845 | 3462 char_u *p; |
3463 | |
7 | 3464 /* "p" or "P" in Visual mode: split the lines to put the text in |
3465 * between. */ | |
3466 if (u_save_cursor() == FAIL) | |
3467 goto end; | |
6845 | 3468 p = ml_get_cursor(); |
3469 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
|
3470 MB_PTR_ADV(p); |
6845 | 3471 ptr = vim_strsave(p); |
7 | 3472 if (ptr == NULL) |
3473 goto end; | |
3474 ml_append(curwin->w_cursor.lnum, ptr, (colnr_T)0, FALSE); | |
3475 vim_free(ptr); | |
3476 | |
6845 | 3477 oldp = ml_get_curline(); |
3478 p = oldp + curwin->w_cursor.col; | |
3479 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
|
3480 MB_PTR_ADV(p); |
6845 | 3481 ptr = vim_strnsave(oldp, p - oldp); |
7 | 3482 if (ptr == NULL) |
3483 goto end; | |
3484 ml_replace(curwin->w_cursor.lnum, ptr, FALSE); | |
3485 ++nr_lines; | |
3486 dir = FORWARD; | |
3487 } | |
3488 if (flags & PUT_LINE_FORWARD) | |
3489 { | |
3490 /* Must be "p" for a Visual block, put lines below the block. */ | |
692 | 3491 curwin->w_cursor = curbuf->b_visual.vi_end; |
7 | 3492 dir = FORWARD; |
3493 } | |
3494 curbuf->b_op_start = curwin->w_cursor; /* default for '[ mark */ | |
3495 curbuf->b_op_end = curwin->w_cursor; /* default for '] mark */ | |
3496 } | |
3497 | |
3498 if (flags & PUT_LINE) /* :put command or "p" in Visual line mode. */ | |
3499 y_type = MLINE; | |
3500 | |
3501 if (y_size == 0 || y_array == NULL) | |
3502 { | |
3503 EMSG2(_("E353: Nothing in register %s"), | |
3504 regname == 0 ? (char_u *)"\"" : transchar(regname)); | |
3505 goto end; | |
3506 } | |
3507 | |
3508 if (y_type == MBLOCK) | |
3509 { | |
3510 lnum = curwin->w_cursor.lnum + y_size + 1; | |
3511 if (lnum > curbuf->b_ml.ml_line_count) | |
3512 lnum = curbuf->b_ml.ml_line_count + 1; | |
3513 if (u_save(curwin->w_cursor.lnum - 1, lnum) == FAIL) | |
3514 goto end; | |
3515 } | |
5735 | 3516 else if (y_type == MLINE) |
7 | 3517 { |
3518 lnum = curwin->w_cursor.lnum; | |
3519 #ifdef FEAT_FOLDING | |
3520 /* Correct line number for closed fold. Don't move the cursor yet, | |
3521 * u_save() uses it. */ | |
3522 if (dir == BACKWARD) | |
3523 (void)hasFolding(lnum, &lnum, NULL); | |
3524 else | |
3525 (void)hasFolding(lnum, NULL, &lnum); | |
3526 #endif | |
3527 if (dir == FORWARD) | |
3528 ++lnum; | |
5053
35b6fc57a286
updated for version 7.3.1270
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3529 /* 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
|
3530 * 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
|
3531 if ((BUFEMPTY() ? u_save(0, 2) : u_save(lnum - 1, lnum)) == FAIL) |
7 | 3532 goto end; |
3533 #ifdef FEAT_FOLDING | |
3534 if (dir == FORWARD) | |
3535 curwin->w_cursor.lnum = lnum - 1; | |
3536 else | |
3537 curwin->w_cursor.lnum = lnum; | |
3538 curbuf->b_op_start = curwin->w_cursor; /* for mark_adjust() */ | |
3539 #endif | |
3540 } | |
3541 else if (u_save_cursor() == FAIL) | |
3542 goto end; | |
3543 | |
3544 yanklen = (int)STRLEN(y_array[0]); | |
3545 | |
3546 #ifdef FEAT_VIRTUALEDIT | |
3547 if (ve_flags == VE_ALL && y_type == MCHAR) | |
3548 { | |
3549 if (gchar_cursor() == TAB) | |
3550 { | |
3551 /* Don't need to insert spaces when "p" on the last position of a | |
3552 * tab or "P" on the first position. */ | |
3553 if (dir == FORWARD | |
3554 ? (int)curwin->w_cursor.coladd < curbuf->b_p_ts - 1 | |
3555 : curwin->w_cursor.coladd > 0) | |
3556 coladvance_force(getviscol()); | |
3557 else | |
3558 curwin->w_cursor.coladd = 0; | |
3559 } | |
3560 else if (curwin->w_cursor.coladd > 0 || gchar_cursor() == NUL) | |
3561 coladvance_force(getviscol() + (dir == FORWARD)); | |
3562 } | |
3563 #endif | |
3564 | |
3565 lnum = curwin->w_cursor.lnum; | |
3566 col = curwin->w_cursor.col; | |
3567 | |
3568 /* | |
3569 * Block mode | |
3570 */ | |
3571 if (y_type == MBLOCK) | |
3572 { | |
10664
94db9c08e206
patch 8.0.0222: blockwise put on multi-byte character misplaced
Christian Brabandt <cb@256bit.org>
parents:
10494
diff
changeset
|
3573 int c = gchar_cursor(); |
7 | 3574 colnr_T endcol2 = 0; |
3575 | |
3576 if (dir == FORWARD && c != NUL) | |
3577 { | |
3578 #ifdef FEAT_VIRTUALEDIT | |
3579 if (ve_flags == VE_ALL) | |
3580 getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2); | |
3581 else | |
3582 #endif | |
3583 getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col); | |
3584 | |
3585 #ifdef FEAT_MBYTE | |
3586 if (has_mbyte) | |
3587 /* move to start of next multi-byte character */ | |
474 | 3588 curwin->w_cursor.col += (*mb_ptr2len)(ml_get_cursor()); |
7 | 3589 else |
3590 #endif | |
3591 #ifdef FEAT_VIRTUALEDIT | |
3592 if (c != TAB || ve_flags != VE_ALL) | |
3593 #endif | |
3594 ++curwin->w_cursor.col; | |
3595 ++col; | |
3596 } | |
3597 else | |
3598 getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2); | |
3599 | |
3600 #ifdef FEAT_VIRTUALEDIT | |
3601 col += curwin->w_cursor.coladd; | |
1304 | 3602 if (ve_flags == VE_ALL |
3603 && (curwin->w_cursor.coladd > 0 | |
3604 || endcol2 == curwin->w_cursor.col)) | |
7 | 3605 { |
3606 if (dir == FORWARD && c == NUL) | |
3607 ++col; | |
3608 if (dir != FORWARD && c != NUL) | |
3609 ++curwin->w_cursor.col; | |
3610 if (c == TAB) | |
3611 { | |
3612 if (dir == BACKWARD && curwin->w_cursor.col) | |
3613 curwin->w_cursor.col--; | |
3614 if (dir == FORWARD && col - 1 == endcol2) | |
3615 curwin->w_cursor.col++; | |
3616 } | |
3617 } | |
3618 curwin->w_cursor.coladd = 0; | |
3619 #endif | |
699 | 3620 bd.textcol = 0; |
7 | 3621 for (i = 0; i < y_size; ++i) |
3622 { | |
3623 int spaces; | |
3624 char shortline; | |
3625 | |
3626 bd.startspaces = 0; | |
3627 bd.endspaces = 0; | |
3628 vcol = 0; | |
3629 delcount = 0; | |
3630 | |
3631 /* add a new line */ | |
3632 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
3633 { | |
3634 if (ml_append(curbuf->b_ml.ml_line_count, (char_u *)"", | |
3635 (colnr_T)1, FALSE) == FAIL) | |
3636 break; | |
3637 ++nr_lines; | |
3638 } | |
3639 /* get the old line and advance to the position to insert at */ | |
3640 oldp = ml_get_curline(); | |
3641 oldlen = (int)STRLEN(oldp); | |
3642 for (ptr = oldp; vcol < col && *ptr; ) | |
3643 { | |
3644 /* Count a tab for what it's worth (if list mode not on) */ | |
5995 | 3645 incr = lbr_chartabsize_adv(oldp, &ptr, (colnr_T)vcol); |
7 | 3646 vcol += incr; |
3647 } | |
3648 bd.textcol = (colnr_T)(ptr - oldp); | |
3649 | |
3650 shortline = (vcol < col) || (vcol == col && !*ptr) ; | |
3651 | |
3652 if (vcol < col) /* line too short, padd with spaces */ | |
3653 bd.startspaces = col - vcol; | |
3654 else if (vcol > col) | |
3655 { | |
3656 bd.endspaces = vcol - col; | |
3657 bd.startspaces = incr - bd.endspaces; | |
3658 --bd.textcol; | |
3659 delcount = 1; | |
3660 #ifdef FEAT_MBYTE | |
3661 if (has_mbyte) | |
3662 bd.textcol -= (*mb_head_off)(oldp, oldp + bd.textcol); | |
3663 #endif | |
3664 if (oldp[bd.textcol] != TAB) | |
3665 { | |
3666 /* Only a Tab can be split into spaces. Other | |
3667 * characters will have to be moved to after the | |
3668 * block, causing misalignment. */ | |
3669 delcount = 0; | |
3670 bd.endspaces = 0; | |
3671 } | |
3672 } | |
3673 | |
3674 yanklen = (int)STRLEN(y_array[i]); | |
3675 | |
3676 /* calculate number of spaces required to fill right side of block*/ | |
3677 spaces = y_width + 1; | |
3678 for (j = 0; j < yanklen; j++) | |
5995 | 3679 spaces -= lbr_chartabsize(NULL, &y_array[i][j], 0); |
7 | 3680 if (spaces < 0) |
3681 spaces = 0; | |
3682 | |
3683 /* insert the new text */ | |
3684 totlen = count * (yanklen + spaces) + bd.startspaces + bd.endspaces; | |
3685 newp = alloc_check((unsigned)totlen + oldlen + 1); | |
3686 if (newp == NULL) | |
3687 break; | |
3688 /* copy part up to cursor to new line */ | |
3689 ptr = newp; | |
3690 mch_memmove(ptr, oldp, (size_t)bd.textcol); | |
3691 ptr += bd.textcol; | |
3692 /* may insert some spaces before the new text */ | |
6929 | 3693 vim_memset(ptr, ' ', (size_t)bd.startspaces); |
7 | 3694 ptr += bd.startspaces; |
3695 /* insert the new text */ | |
3696 for (j = 0; j < count; ++j) | |
3697 { | |
3698 mch_memmove(ptr, y_array[i], (size_t)yanklen); | |
3699 ptr += yanklen; | |
3700 | |
3701 /* insert block's trailing spaces only if there's text behind */ | |
3702 if ((j < count - 1 || !shortline) && spaces) | |
3703 { | |
6929 | 3704 vim_memset(ptr, ' ', (size_t)spaces); |
7 | 3705 ptr += spaces; |
3706 } | |
3707 } | |
3708 /* may insert some spaces after the new text */ | |
6929 | 3709 vim_memset(ptr, ' ', (size_t)bd.endspaces); |
7 | 3710 ptr += bd.endspaces; |
3711 /* move the text after the cursor to the end of the line. */ | |
3712 mch_memmove(ptr, oldp + bd.textcol + delcount, | |
3713 (size_t)(oldlen - bd.textcol - delcount + 1)); | |
3714 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
3715 | |
3716 ++curwin->w_cursor.lnum; | |
3717 if (i == 0) | |
3718 curwin->w_cursor.col += bd.startspaces; | |
3719 } | |
3720 | |
3721 changed_lines(lnum, 0, curwin->w_cursor.lnum, nr_lines); | |
3722 | |
3723 /* Set '[ mark. */ | |
3724 curbuf->b_op_start = curwin->w_cursor; | |
3725 curbuf->b_op_start.lnum = lnum; | |
3726 | |
3727 /* adjust '] mark */ | |
3728 curbuf->b_op_end.lnum = curwin->w_cursor.lnum - 1; | |
3729 curbuf->b_op_end.col = bd.textcol + totlen - 1; | |
237 | 3730 # ifdef FEAT_VIRTUALEDIT |
7 | 3731 curbuf->b_op_end.coladd = 0; |
237 | 3732 # endif |
7 | 3733 if (flags & PUT_CURSEND) |
3734 { | |
916 | 3735 colnr_T len; |
3736 | |
7 | 3737 curwin->w_cursor = curbuf->b_op_end; |
3738 curwin->w_cursor.col++; | |
916 | 3739 |
3740 /* in Insert mode we might be after the NUL, correct for that */ | |
3741 len = (colnr_T)STRLEN(ml_get_curline()); | |
3742 if (curwin->w_cursor.col > len) | |
3743 curwin->w_cursor.col = len; | |
7 | 3744 } |
3745 else | |
3746 curwin->w_cursor.lnum = lnum; | |
3747 } | |
3748 else | |
3749 { | |
3750 /* | |
3751 * Character or Line mode | |
3752 */ | |
3753 if (y_type == MCHAR) | |
3754 { | |
3755 /* if type is MCHAR, FORWARD is the same as BACKWARD on the next | |
3756 * char */ | |
3757 if (dir == FORWARD && gchar_cursor() != NUL) | |
3758 { | |
3759 #ifdef FEAT_MBYTE | |
3760 if (has_mbyte) | |
3761 { | |
474 | 3762 int bytelen = (*mb_ptr2len)(ml_get_cursor()); |
7 | 3763 |
3764 /* put it on the next of the multi-byte character. */ | |
3765 col += bytelen; | |
3766 if (yanklen) | |
3767 { | |
3768 curwin->w_cursor.col += bytelen; | |
3769 curbuf->b_op_end.col += bytelen; | |
3770 } | |
3771 } | |
3772 else | |
3773 #endif | |
3774 { | |
3775 ++col; | |
3776 if (yanklen) | |
3777 { | |
3778 ++curwin->w_cursor.col; | |
3779 ++curbuf->b_op_end.col; | |
3780 } | |
3781 } | |
3782 } | |
3783 curbuf->b_op_start = curwin->w_cursor; | |
3784 } | |
3785 /* | |
3786 * Line mode: BACKWARD is the same as FORWARD on the previous line | |
3787 */ | |
3788 else if (dir == BACKWARD) | |
3789 --lnum; | |
699 | 3790 new_cursor = curwin->w_cursor; |
7 | 3791 |
3792 /* | |
3793 * simple case: insert into current line | |
3794 */ | |
3795 if (y_type == MCHAR && y_size == 1) | |
3796 { | |
10692
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
3797 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
|
3798 |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3799 if (VIsual_active) |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3800 { |
10692
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
3801 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
|
3802 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
|
3803 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
|
3804 } |
10670
bce3eccea39a
patch 8.0.0225: put in Visual block mode terminates early
Christian Brabandt <cb@256bit.org>
parents:
10664
diff
changeset
|
3805 |
5365 | 3806 do { |
3807 totlen = count * yanklen; | |
3808 if (totlen > 0) | |
7 | 3809 { |
5365 | 3810 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
|
3811 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
|
3812 { |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3813 lnum++; |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3814 continue; |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3815 } |
5365 | 3816 newp = alloc_check((unsigned)(STRLEN(oldp) + totlen + 1)); |
3817 if (newp == NULL) | |
3818 goto end; /* alloc() gave an error message */ | |
3819 mch_memmove(newp, oldp, (size_t)col); | |
3820 ptr = newp + col; | |
3821 for (i = 0; i < count; ++i) | |
3822 { | |
3823 mch_memmove(ptr, y_array[0], (size_t)yanklen); | |
3824 ptr += yanklen; | |
3825 } | |
3826 STRMOVE(ptr, oldp + col); | |
3827 ml_replace(lnum, newp, FALSE); | |
3828 /* Place cursor on last putted char. */ | |
3829 if (lnum == curwin->w_cursor.lnum) | |
5496 | 3830 { |
3831 /* make sure curwin->w_virtcol is updated */ | |
3832 changed_cline_bef_curs(); | |
5365 | 3833 curwin->w_cursor.col += (colnr_T)(totlen - 1); |
5496 | 3834 } |
7 | 3835 } |
5365 | 3836 if (VIsual_active) |
3837 lnum++; | |
10692
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
3838 } while (VIsual_active && lnum <= end_lnum); |
5365 | 3839 |
6379 | 3840 if (VIsual_active) /* reset lnum to the last visual line */ |
3841 lnum--; | |
3842 | |
7 | 3843 curbuf->b_op_end = curwin->w_cursor; |
3844 /* For "CTRL-O p" in Insert mode, put cursor after last char */ | |
3845 if (totlen && (restart_edit != 0 || (flags & PUT_CURSEND))) | |
3846 ++curwin->w_cursor.col; | |
3847 changed_bytes(lnum, col); | |
3848 } | |
3849 else | |
3850 { | |
3851 /* | |
3852 * Insert at least one line. When y_type is MCHAR, break the first | |
3853 * line in two. | |
3854 */ | |
3855 for (cnt = 1; cnt <= count; ++cnt) | |
3856 { | |
3857 i = 0; | |
3858 if (y_type == MCHAR) | |
3859 { | |
3860 /* | |
3861 * Split the current line in two at the insert position. | |
3862 * First insert y_array[size - 1] in front of second line. | |
3863 * Then append y_array[0] to first line. | |
3864 */ | |
3865 lnum = new_cursor.lnum; | |
3866 ptr = ml_get(lnum) + col; | |
3867 totlen = (int)STRLEN(y_array[y_size - 1]); | |
3868 newp = alloc_check((unsigned)(STRLEN(ptr) + totlen + 1)); | |
3869 if (newp == NULL) | |
3870 goto error; | |
3871 STRCPY(newp, y_array[y_size - 1]); | |
3872 STRCAT(newp, ptr); | |
3873 /* insert second line */ | |
3874 ml_append(lnum, newp, (colnr_T)0, FALSE); | |
3875 vim_free(newp); | |
3876 | |
3877 oldp = ml_get(lnum); | |
3878 newp = alloc_check((unsigned)(col + yanklen + 1)); | |
3879 if (newp == NULL) | |
3880 goto error; | |
3881 /* copy first part of line */ | |
3882 mch_memmove(newp, oldp, (size_t)col); | |
3883 /* append to first line */ | |
3884 mch_memmove(newp + col, y_array[0], (size_t)(yanklen + 1)); | |
3885 ml_replace(lnum, newp, FALSE); | |
3886 | |
3887 curwin->w_cursor.lnum = lnum; | |
3888 i = 1; | |
3889 } | |
3890 | |
3891 for (; i < y_size; ++i) | |
3892 { | |
3893 if ((y_type != MCHAR || i < y_size - 1) | |
3894 && ml_append(lnum, y_array[i], (colnr_T)0, FALSE) | |
3895 == FAIL) | |
3896 goto error; | |
3897 lnum++; | |
3898 ++nr_lines; | |
3899 if (flags & PUT_FIXINDENT) | |
3900 { | |
3901 old_pos = curwin->w_cursor; | |
3902 curwin->w_cursor.lnum = lnum; | |
3903 ptr = ml_get(lnum); | |
3904 if (cnt == count && i == y_size - 1) | |
3905 lendiff = (int)STRLEN(ptr); | |
3906 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) | |
3907 if (*ptr == '#' && preprocs_left()) | |
3908 indent = 0; /* Leave # lines at start */ | |
3909 else | |
3910 #endif | |
3911 if (*ptr == NUL) | |
3912 indent = 0; /* Ignore empty lines */ | |
3913 else if (first_indent) | |
3914 { | |
3915 indent_diff = orig_indent - get_indent(); | |
3916 indent = orig_indent; | |
3917 first_indent = FALSE; | |
3918 } | |
3919 else if ((indent = get_indent() + indent_diff) < 0) | |
3920 indent = 0; | |
3921 (void)set_indent(indent, 0); | |
3922 curwin->w_cursor = old_pos; | |
3923 /* remember how many chars were removed */ | |
3924 if (cnt == count && i == y_size - 1) | |
3925 lendiff -= (int)STRLEN(ml_get(lnum)); | |
3926 } | |
3927 } | |
3928 } | |
3929 | |
3930 error: | |
3931 /* Adjust marks. */ | |
3932 if (y_type == MLINE) | |
3933 { | |
3934 curbuf->b_op_start.col = 0; | |
3935 if (dir == FORWARD) | |
3936 curbuf->b_op_start.lnum++; | |
3937 } | |
9225
b0b2bd8e5217
commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents:
8989
diff
changeset
|
3938 /* 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
|
3939 * 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
|
3940 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
|
3941 < 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
|
3942 #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
|
3943 || 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
|
3944 #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
|
3945 ) |
9225
b0b2bd8e5217
commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents:
8989
diff
changeset
|
3946 mark_adjust(curbuf->b_op_start.lnum + (y_type == MCHAR), |
7 | 3947 (linenr_T)MAXLNUM, nr_lines, 0L); |
3948 | |
3949 /* note changed text for displaying and folding */ | |
3950 if (y_type == MCHAR) | |
3951 changed_lines(curwin->w_cursor.lnum, col, | |
3952 curwin->w_cursor.lnum + 1, nr_lines); | |
3953 else | |
3954 changed_lines(curbuf->b_op_start.lnum, 0, | |
3955 curbuf->b_op_start.lnum, nr_lines); | |
3956 | |
3957 /* put '] mark at last inserted character */ | |
3958 curbuf->b_op_end.lnum = lnum; | |
3959 /* correct length for change in indent */ | |
3960 col = (colnr_T)STRLEN(y_array[y_size - 1]) - lendiff; | |
3961 if (col > 1) | |
3962 curbuf->b_op_end.col = col - 1; | |
3963 else | |
3964 curbuf->b_op_end.col = 0; | |
3965 | |
168 | 3966 if (flags & PUT_CURSLINE) |
3967 { | |
237 | 3968 /* ":put": put cursor on last inserted line */ |
168 | 3969 curwin->w_cursor.lnum = lnum; |
3970 beginline(BL_WHITE | BL_FIX); | |
3971 } | |
3972 else if (flags & PUT_CURSEND) | |
7 | 3973 { |
3974 /* put cursor after inserted text */ | |
3975 if (y_type == MLINE) | |
3976 { | |
3977 if (lnum >= curbuf->b_ml.ml_line_count) | |
3978 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
3979 else | |
3980 curwin->w_cursor.lnum = lnum + 1; | |
3981 curwin->w_cursor.col = 0; | |
3982 } | |
3983 else | |
3984 { | |
3985 curwin->w_cursor.lnum = lnum; | |
3986 curwin->w_cursor.col = col; | |
3987 } | |
3988 } | |
3989 else if (y_type == MLINE) | |
3990 { | |
168 | 3991 /* put cursor on first non-blank in first inserted line */ |
7 | 3992 curwin->w_cursor.col = 0; |
3993 if (dir == FORWARD) | |
3994 ++curwin->w_cursor.lnum; | |
3995 beginline(BL_WHITE | BL_FIX); | |
3996 } | |
3997 else /* put cursor on first inserted character */ | |
3998 curwin->w_cursor = new_cursor; | |
3999 } | |
4000 } | |
4001 | |
4002 msgmore(nr_lines); | |
4003 curwin->w_set_curswant = TRUE; | |
4004 | |
4005 end: | |
4006 if (allocated) | |
4007 vim_free(insert_string); | |
840 | 4008 if (regname == '=') |
4009 vim_free(y_array); | |
4010 | |
5380 | 4011 VIsual_active = FALSE; |
4012 | |
140 | 4013 /* If the cursor is past the end of the line put it at the end. */ |
844 | 4014 adjust_cursor_eol(); |
4015 } | |
4016 | |
4017 /* | |
4018 * When the cursor is on the NUL past the end of the line and it should not be | |
4019 * there move it left. | |
4020 */ | |
4021 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4022 adjust_cursor_eol(void) |
844 | 4023 { |
4024 if (curwin->w_cursor.col > 0 | |
4025 && gchar_cursor() == NUL | |
773 | 4026 #ifdef FEAT_VIRTUALEDIT |
4027 && (ve_flags & VE_ONEMORE) == 0 | |
4028 #endif | |
7 | 4029 && !(restart_edit || (State & INSERT))) |
4030 { | |
557 | 4031 /* Put the cursor on the last character in the line. */ |
555 | 4032 dec_cursor(); |
844 | 4033 |
7 | 4034 #ifdef FEAT_VIRTUALEDIT |
4035 if (ve_flags == VE_ALL) | |
557 | 4036 { |
4037 colnr_T scol, ecol; | |
4038 | |
4039 /* Coladd is set to the width of the last character. */ | |
4040 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); | |
4041 curwin->w_cursor.coladd = ecol - scol + 1; | |
4042 } | |
7 | 4043 #endif |
4044 } | |
4045 } | |
4046 | |
4047 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) || defined(PROTO) | |
4048 /* | |
4049 * Return TRUE if lines starting with '#' should be left aligned. | |
4050 */ | |
4051 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4052 preprocs_left(void) |
7 | 4053 { |
4054 return | |
4055 # ifdef FEAT_SMARTINDENT | |
4056 # ifdef FEAT_CINDENT | |
4057 (curbuf->b_p_si && !curbuf->b_p_cin) || | |
4058 # else | |
4059 curbuf->b_p_si | |
4060 # endif | |
4061 # endif | |
4062 # ifdef FEAT_CINDENT | |
5438 | 4063 (curbuf->b_p_cin && in_cinkeys('#', ' ', TRUE) |
4064 && curbuf->b_ind_hash_comment == 0) | |
7 | 4065 # endif |
4066 ; | |
4067 } | |
4068 #endif | |
4069 | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4070 /* |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4071 * 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
|
4072 */ |
7 | 4073 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4074 get_register_name(int num) |
7 | 4075 { |
4076 if (num == -1) | |
4077 return '"'; | |
4078 else if (num < 10) | |
4079 return num + '0'; | |
4080 else if (num == DELETION_REGISTER) | |
4081 return '-'; | |
4082 #ifdef FEAT_CLIPBOARD | |
4083 else if (num == STAR_REGISTER) | |
4084 return '*'; | |
4085 else if (num == PLUS_REGISTER) | |
4086 return '+'; | |
4087 #endif | |
4088 else | |
4089 { | |
4090 #ifdef EBCDIC | |
4091 int i; | |
4092 | |
4093 /* EBCDIC is really braindead ... */ | |
4094 i = 'a' + (num - 10); | |
4095 if (i > 'i') | |
4096 i += 7; | |
4097 if (i > 'r') | |
4098 i += 8; | |
4099 return i; | |
4100 #else | |
4101 return num + 'a' - 10; | |
4102 #endif | |
4103 } | |
4104 } | |
4105 | |
4106 /* | |
4107 * ":dis" and ":registers": Display the contents of the yank registers. | |
4108 */ | |
4109 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4110 ex_display(exarg_T *eap) |
7 | 4111 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4112 int i, n; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4113 long j; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4114 char_u *p; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4115 yankreg_T *yb; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4116 int name; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4117 int attr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4118 char_u *arg = eap->arg; |
22 | 4119 #ifdef FEAT_MBYTE |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4120 int clen; |
22 | 4121 #else |
4122 # define clen 1 | |
4123 #endif | |
7 | 4124 |
4125 if (arg != NULL && *arg == NUL) | |
4126 arg = NULL; | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11131
diff
changeset
|
4127 attr = HL_ATTR(HLF_8); |
7 | 4128 |
4129 /* Highlight title */ | |
4130 MSG_PUTS_TITLE(_("\n--- Registers ---")); | |
4131 for (i = -1; i < NUM_REGISTERS && !got_int; ++i) | |
4132 { | |
4133 name = get_register_name(i); | |
2644 | 4134 if (arg != NULL && vim_strchr(arg, name) == NULL |
4135 #ifdef ONE_CLIPBOARD | |
4136 /* Star register and plus register contain the same thing. */ | |
4137 && (name != '*' || vim_strchr(arg, '+') == NULL) | |
4138 #endif | |
4139 ) | |
7 | 4140 continue; /* did not ask for this register */ |
4141 | |
4142 #ifdef FEAT_CLIPBOARD | |
4143 /* Adjust register name for "unnamed" in 'clipboard'. | |
4144 * When it's a clipboard register, fill it with the current contents | |
4145 * of the clipboard. */ | |
4146 adjust_clip_reg(&name); | |
4147 (void)may_get_selection(name); | |
4148 #endif | |
4149 | |
4150 if (i == -1) | |
4151 { | |
4152 if (y_previous != NULL) | |
4153 yb = y_previous; | |
4154 else | |
4155 yb = &(y_regs[0]); | |
4156 } | |
4157 else | |
4158 yb = &(y_regs[i]); | |
2000 | 4159 |
4160 #ifdef FEAT_EVAL | |
4161 if (name == MB_TOLOWER(redir_reg) | |
4162 || (redir_reg == '"' && yb == y_previous)) | |
4163 continue; /* do not list register being written to, the | |
4164 * pointer can be freed */ | |
4165 #endif | |
4166 | |
7 | 4167 if (yb->y_array != NULL) |
4168 { | |
4169 msg_putchar('\n'); | |
4170 msg_putchar('"'); | |
4171 msg_putchar(name); | |
4172 MSG_PUTS(" "); | |
4173 | |
4174 n = (int)Columns - 6; | |
4175 for (j = 0; j < yb->y_size && n > 1; ++j) | |
4176 { | |
4177 if (j) | |
4178 { | |
4179 MSG_PUTS_ATTR("^J", attr); | |
4180 n -= 2; | |
4181 } | |
4182 for (p = yb->y_array[j]; *p && (n -= ptr2cells(p)) >= 0; ++p) | |
4183 { | |
4184 #ifdef FEAT_MBYTE | |
474 | 4185 clen = (*mb_ptr2len)(p); |
22 | 4186 #endif |
4187 msg_outtrans_len(p, clen); | |
4188 #ifdef FEAT_MBYTE | |
4189 p += clen - 1; | |
7 | 4190 #endif |
4191 } | |
4192 } | |
4193 if (n > 1 && yb->y_type == MLINE) | |
4194 MSG_PUTS_ATTR("^J", attr); | |
4195 out_flush(); /* show one line at a time */ | |
4196 } | |
4197 ui_breakcheck(); | |
4198 } | |
4199 | |
4200 /* | |
4201 * display last inserted text | |
4202 */ | |
4203 if ((p = get_last_insert()) != NULL | |
4204 && (arg == NULL || vim_strchr(arg, '.') != NULL) && !got_int) | |
4205 { | |
4206 MSG_PUTS("\n\". "); | |
4207 dis_msg(p, TRUE); | |
4208 } | |
4209 | |
4210 /* | |
4211 * display last command line | |
4212 */ | |
4213 if (last_cmdline != NULL && (arg == NULL || vim_strchr(arg, ':') != NULL) | |
4214 && !got_int) | |
4215 { | |
4216 MSG_PUTS("\n\": "); | |
4217 dis_msg(last_cmdline, FALSE); | |
4218 } | |
4219 | |
4220 /* | |
4221 * display current file name | |
4222 */ | |
4223 if (curbuf->b_fname != NULL | |
4224 && (arg == NULL || vim_strchr(arg, '%') != NULL) && !got_int) | |
4225 { | |
4226 MSG_PUTS("\n\"% "); | |
4227 dis_msg(curbuf->b_fname, FALSE); | |
4228 } | |
4229 | |
4230 /* | |
4231 * display alternate file name | |
4232 */ | |
4233 if ((arg == NULL || vim_strchr(arg, '%') != NULL) && !got_int) | |
4234 { | |
4235 char_u *fname; | |
4236 linenr_T dummy; | |
4237 | |
4238 if (buflist_name_nr(0, &fname, &dummy) != FAIL) | |
4239 { | |
4240 MSG_PUTS("\n\"# "); | |
4241 dis_msg(fname, FALSE); | |
4242 } | |
4243 } | |
4244 | |
4245 /* | |
4246 * display last search pattern | |
4247 */ | |
4248 if (last_search_pat() != NULL | |
4249 && (arg == NULL || vim_strchr(arg, '/') != NULL) && !got_int) | |
4250 { | |
4251 MSG_PUTS("\n\"/ "); | |
4252 dis_msg(last_search_pat(), FALSE); | |
4253 } | |
4254 | |
4255 #ifdef FEAT_EVAL | |
4256 /* | |
4257 * display last used expression | |
4258 */ | |
4259 if (expr_line != NULL && (arg == NULL || vim_strchr(arg, '=') != NULL) | |
4260 && !got_int) | |
4261 { | |
4262 MSG_PUTS("\n\"= "); | |
4263 dis_msg(expr_line, FALSE); | |
4264 } | |
4265 #endif | |
4266 } | |
4267 | |
4268 /* | |
4269 * display a string for do_dis() | |
4270 * truncate at end of screen line | |
4271 */ | |
4272 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4273 dis_msg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4274 char_u *p, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4275 int skip_esc) /* if TRUE, ignore trailing ESC */ |
7 | 4276 { |
4277 int n; | |
4278 #ifdef FEAT_MBYTE | |
4279 int l; | |
4280 #endif | |
4281 | |
4282 n = (int)Columns - 6; | |
4283 while (*p != NUL | |
4284 && !(*p == ESC && skip_esc && *(p + 1) == NUL) | |
4285 && (n -= ptr2cells(p)) >= 0) | |
4286 { | |
4287 #ifdef FEAT_MBYTE | |
474 | 4288 if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) |
7 | 4289 { |
4290 msg_outtrans_len(p, l); | |
4291 p += l; | |
4292 } | |
4293 else | |
4294 #endif | |
4295 msg_outtrans_len(p++, 1); | |
4296 } | |
4297 ui_breakcheck(); | |
4298 } | |
4299 | |
3562 | 4300 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4301 /* | |
4302 * If "process" is TRUE and the line begins with a comment leader (possibly | |
4303 * after some white space), return a pointer to the text after it. Put a boolean | |
4304 * value indicating whether the line ends with an unclosed comment in | |
4305 * "is_comment". | |
4306 * line - line to be processed, | |
4307 * process - if FALSE, will only check whether the line ends with an unclosed | |
3584 | 4308 * comment, |
3562 | 4309 * include_space - whether to also skip space following the comment leader, |
4310 * is_comment - will indicate whether the current line ends with an unclosed | |
3584 | 4311 * comment. |
3562 | 4312 */ |
11131
8d9ecf09183a
patch 8.0.0453: adding fold marker creates new comment
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4313 char_u * |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4314 skip_comment( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4315 char_u *line, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4316 int process, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4317 int include_space, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4318 int *is_comment) |
3562 | 4319 { |
4320 char_u *comment_flags = NULL; | |
4321 int lead_len; | |
4322 int leader_offset = get_last_leader_offset(line, &comment_flags); | |
4323 | |
4324 *is_comment = FALSE; | |
4325 if (leader_offset != -1) | |
4326 { | |
4327 /* Let's check whether the line ends with an unclosed comment. | |
4328 * If the last comment leader has COM_END in flags, there's no comment. | |
4329 */ | |
4330 while (*comment_flags) | |
4331 { | |
4332 if (*comment_flags == COM_END | |
4333 || *comment_flags == ':') | |
4334 break; | |
4335 ++comment_flags; | |
4336 } | |
4337 if (*comment_flags != COM_END) | |
4338 *is_comment = TRUE; | |
4339 } | |
4340 | |
4341 if (process == FALSE) | |
4342 return line; | |
4343 | |
4344 lead_len = get_leader_len(line, &comment_flags, FALSE, include_space); | |
4345 | |
4346 if (lead_len == 0) | |
4347 return line; | |
4348 | |
4349 /* Find: | |
4350 * - COM_END, | |
4351 * - colon, | |
4352 * whichever comes first. | |
4353 */ | |
4354 while (*comment_flags) | |
4355 { | |
3580 | 4356 if (*comment_flags == COM_END |
3562 | 4357 || *comment_flags == ':') |
4358 { | |
4359 break; | |
4360 } | |
4361 ++comment_flags; | |
4362 } | |
4363 | |
4364 /* If we found a colon, it means that we are not processing a line | |
3580 | 4365 * starting with a closing part of a three-part comment. That's good, |
4366 * because we don't want to remove those as this would be annoying. | |
3562 | 4367 */ |
4368 if (*comment_flags == ':' || *comment_flags == NUL) | |
4369 line += lead_len; | |
4370 | |
4371 return line; | |
4372 } | |
4373 #endif | |
4374 | |
7 | 4375 /* |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4376 * 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
|
4377 * When "save_undo" is TRUE save lines for undo first. |
5848 | 4378 * Set "use_formatoptions" to FALSE when e.g. processing backspace and comment |
4379 * leaders should not be removed. | |
4380 * When setmark is TRUE, sets the '[ and '] mark, else, the caller is expected | |
4381 * to set those marks. | |
7 | 4382 * |
1217 | 4383 * return FAIL for failure, OK otherwise |
7 | 4384 */ |
4385 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4386 do_join( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4387 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4388 int insert_space, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4389 int save_undo, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4390 int use_formatoptions UNUSED, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4391 int setmark) |
7 | 4392 { |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4393 char_u *curr = NULL; |
2597 | 4394 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
|
4395 char_u *cend; |
7 | 4396 char_u *newp; |
2597 | 4397 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
|
4398 int endcurr1 = NUL; |
3e4574a4b627
Fix a few compiler warnings.
Bram Moolenaar <bram@vim.org>
parents:
2298
diff
changeset
|
4399 int endcurr2 = NUL; |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4400 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
|
4401 int sumsize = 0; /* size of the long new line */ |
7 | 4402 linenr_T t; |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4403 colnr_T col = 0; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4404 int ret = OK; |
3562 | 4405 #if defined(FEAT_COMMENTS) || defined(PROTO) |
3574 | 4406 int *comments = NULL; |
3562 | 4407 int remove_comments = (use_formatoptions == TRUE) |
4408 && has_format_option(FO_REMOVE_COMS); | |
4409 int prev_was_comment; | |
4410 #endif | |
4411 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4412 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4413 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
|
4414 (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
|
4415 return FAIL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4416 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4417 /* 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
|
4418 * 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
|
4419 * 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
|
4420 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
|
4421 if (spaces == NULL) |
7 | 4422 return FAIL; |
3562 | 4423 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4424 if (remove_comments) | |
4425 { | |
4426 comments = (int *)lalloc_clear((long_u)count * sizeof(int), TRUE); | |
4427 if (comments == NULL) | |
4428 { | |
4429 vim_free(spaces); | |
4430 return FAIL; | |
4431 } | |
4432 } | |
4433 #endif | |
7 | 4434 |
4435 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4436 * 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
|
4437 * and setup the array of space strings lengths |
7 | 4438 */ |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4439 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
|
4440 { |
2597 | 4441 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t)); |
5848 | 4442 if (t == 0 && setmark) |
5664 | 4443 { |
4444 /* Set the '[ mark. */ | |
4445 curwin->w_buffer->b_op_start.lnum = curwin->w_cursor.lnum; | |
4446 curwin->w_buffer->b_op_start.col = (colnr_T)STRLEN(curr); | |
4447 } | |
3562 | 4448 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4449 if (remove_comments) | |
4450 { | |
4451 /* We don't want to remove the comment leader if the | |
4452 * previous line is not a comment. */ | |
4453 if (t > 0 && prev_was_comment) | |
4454 { | |
4455 | |
4456 char_u *new_curr = skip_comment(curr, TRUE, insert_space, | |
4457 &prev_was_comment); | |
3576 | 4458 comments[t] = (int)(new_curr - curr); |
3562 | 4459 curr = new_curr; |
4460 } | |
4461 else | |
4462 curr = skip_comment(curr, FALSE, insert_space, | |
4463 &prev_was_comment); | |
4464 } | |
4465 #endif | |
4466 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4467 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
|
4468 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4469 curr = skipwhite(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4470 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
|
4471 #ifdef FEAT_MBYTE |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4472 && (!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
|
4473 || (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
|
4474 && (!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
|
4475 || 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
|
4476 #endif |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4477 ) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4478 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4479 /* 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
|
4480 if (endcurr1 == ' ') |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4481 endcurr1 = endcurr2; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4482 else |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4483 ++spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4484 /* 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
|
4485 if ( p_js |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4486 && (endcurr1 == '.' |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4487 || (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
|
4488 && (endcurr1 == '?' || endcurr1 == '!')))) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4489 ++spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4490 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4491 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4492 currsize = (int)STRLEN(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4493 sumsize += currsize + spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4494 endcurr1 = endcurr2 = NUL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4495 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
|
4496 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4497 #ifdef FEAT_MBYTE |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4498 if (has_mbyte) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4499 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4500 cend = curr + currsize; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4501 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
|
4502 endcurr1 = (*mb_ptr2char)(cend); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4503 if (cend > curr) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4504 { |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4505 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
|
4506 endcurr2 = (*mb_ptr2char)(cend); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4507 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4508 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4509 else |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4510 #endif |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4511 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4512 endcurr1 = *(curr + currsize - 1); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4513 if (currsize > 1) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4514 endcurr2 = *(curr + currsize - 2); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4515 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4516 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4517 line_breakcheck(); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4518 if (got_int) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4519 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4520 ret = FAIL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4521 goto theend; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4522 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4523 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4524 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4525 /* 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
|
4526 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
|
4527 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4528 /* 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
|
4529 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
|
4530 cend = newp + sumsize; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4531 *cend = 0; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4532 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4533 /* |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4534 * 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
|
4535 * |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4536 * 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
|
4537 * 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
|
4538 * 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
|
4539 */ |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4540 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
|
4541 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4542 cend -= currsize; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4543 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
|
4544 if (spaces[t] > 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4545 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4546 cend -= spaces[t]; |
6929 | 4547 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
|
4548 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4549 mark_col_adjust(curwin->w_cursor.lnum + t, (colnr_T)0, (linenr_T)-t, |
2597 | 4550 (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
|
4551 if (t == 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4552 break; |
2597 | 4553 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t - 1)); |
3562 | 4554 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4555 if (remove_comments) | |
4556 curr += comments[t - 1]; | |
4557 #endif | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4558 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
|
4559 curr = skipwhite(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4560 currsize = (int)STRLEN(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4561 } |
7 | 4562 ml_replace(curwin->w_cursor.lnum, newp, FALSE); |
4563 | |
5848 | 4564 if (setmark) |
4565 { | |
4566 /* Set the '] mark. */ | |
4567 curwin->w_buffer->b_op_end.lnum = curwin->w_cursor.lnum; | |
4568 curwin->w_buffer->b_op_end.col = (colnr_T)STRLEN(newp); | |
4569 } | |
5664 | 4570 |
7 | 4571 /* Only report the change in the first line here, del_lines() will report |
4572 * the deleted line. */ | |
4573 changed_lines(curwin->w_cursor.lnum, currsize, | |
4574 curwin->w_cursor.lnum + 1, 0L); | |
4575 | |
4576 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4577 * Delete following lines. To do this we move the cursor there |
7 | 4578 * briefly, and then move it back. After del_lines() the cursor may |
4579 * have moved up (last line deleted), so the current lnum is kept in t. | |
4580 */ | |
4581 t = curwin->w_cursor.lnum; | |
4582 ++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
|
4583 del_lines(count - 1, FALSE); |
7 | 4584 curwin->w_cursor.lnum = t; |
4585 | |
4586 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4587 * Set the cursor column: |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4588 * 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
|
4589 * vim: use the column of the last join |
7 | 4590 */ |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4591 curwin->w_cursor.col = |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4592 (vim_strchr(p_cpo, CPO_JOINCOL) != NULL ? currsize : col); |
7 | 4593 check_cursor_col(); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4594 |
7 | 4595 #ifdef FEAT_VIRTUALEDIT |
4596 curwin->w_cursor.coladd = 0; | |
4597 #endif | |
4598 curwin->w_set_curswant = TRUE; | |
4599 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4600 theend: |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4601 vim_free(spaces); |
3562 | 4602 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4603 if (remove_comments) | |
4604 vim_free(comments); | |
4605 #endif | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4606 return ret; |
7 | 4607 } |
4608 | |
4609 #ifdef FEAT_COMMENTS | |
4610 /* | |
4611 * Return TRUE if the two comment leaders given are the same. "lnum" is | |
4612 * the first line. White-space is ignored. Note that the whole of | |
4613 * 'leader1' must match 'leader2_len' characters from 'leader2' -- webb | |
4614 */ | |
4615 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4616 same_leader( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4617 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4618 int leader1_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4619 char_u *leader1_flags, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4620 int leader2_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4621 char_u *leader2_flags) |
7 | 4622 { |
4623 int idx1 = 0, idx2 = 0; | |
4624 char_u *p; | |
4625 char_u *line1; | |
4626 char_u *line2; | |
4627 | |
4628 if (leader1_len == 0) | |
4629 return (leader2_len == 0); | |
4630 | |
4631 /* | |
4632 * If first leader has 'f' flag, the lines can be joined only if the | |
4633 * second line does not have a leader. | |
4634 * If first leader has 'e' flag, the lines can never be joined. | |
4635 * If fist leader has 's' flag, the lines can only be joined if there is | |
4636 * some text after it and the second line has the 'm' flag. | |
4637 */ | |
4638 if (leader1_flags != NULL) | |
4639 { | |
4640 for (p = leader1_flags; *p && *p != ':'; ++p) | |
4641 { | |
4642 if (*p == COM_FIRST) | |
4643 return (leader2_len == 0); | |
4644 if (*p == COM_END) | |
4645 return FALSE; | |
4646 if (*p == COM_START) | |
4647 { | |
4648 if (*(ml_get(lnum) + leader1_len) == NUL) | |
4649 return FALSE; | |
4650 if (leader2_flags == NULL || leader2_len == 0) | |
4651 return FALSE; | |
4652 for (p = leader2_flags; *p && *p != ':'; ++p) | |
4653 if (*p == COM_MIDDLE) | |
4654 return TRUE; | |
4655 return FALSE; | |
4656 } | |
4657 } | |
4658 } | |
4659 | |
4660 /* | |
4661 * Get current line and next line, compare the leaders. | |
4662 * The first line has to be saved, only one line can be locked at a time. | |
4663 */ | |
4664 line1 = vim_strsave(ml_get(lnum)); | |
4665 if (line1 != NULL) | |
4666 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4667 for (idx1 = 0; VIM_ISWHITE(line1[idx1]); ++idx1) |
7 | 4668 ; |
4669 line2 = ml_get(lnum + 1); | |
4670 for (idx2 = 0; idx2 < leader2_len; ++idx2) | |
4671 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4672 if (!VIM_ISWHITE(line2[idx2])) |
7 | 4673 { |
4674 if (line1[idx1++] != line2[idx2]) | |
4675 break; | |
4676 } | |
4677 else | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4678 while (VIM_ISWHITE(line1[idx1])) |
7 | 4679 ++idx1; |
4680 } | |
4681 vim_free(line1); | |
4682 } | |
4683 return (idx2 == leader2_len && idx1 == leader1_len); | |
4684 } | |
4685 #endif | |
4686 | |
4687 /* | |
3252 | 4688 * Implementation of the format operator 'gq'. |
7 | 4689 */ |
4690 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4691 op_format( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4692 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4693 int keep_cursor) /* keep cursor on same text char */ |
7 | 4694 { |
4695 long old_line_count = curbuf->b_ml.ml_line_count; | |
4696 | |
4697 /* Place the cursor where the "gq" or "gw" command was given, so that "u" | |
4698 * can put it back there. */ | |
4699 curwin->w_cursor = oap->cursor_start; | |
4700 | |
4701 if (u_save((linenr_T)(oap->start.lnum - 1), | |
4702 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
4703 return; | |
4704 curwin->w_cursor = oap->start; | |
4705 | |
4706 if (oap->is_VIsual) | |
4707 /* When there is no change: need to remove the Visual selection */ | |
4708 redraw_curbuf_later(INVERTED); | |
4709 | |
4710 /* Set '[ mark at the start of the formatted area */ | |
4711 curbuf->b_op_start = oap->start; | |
4712 | |
4713 /* For "gw" remember the cursor position and put it back below (adjusted | |
4714 * for joined and split lines). */ | |
4715 if (keep_cursor) | |
4716 saved_cursor = oap->cursor_start; | |
4717 | |
1563 | 4718 format_lines(oap->line_count, keep_cursor); |
7 | 4719 |
4720 /* | |
4721 * Leave the cursor at the first non-blank of the last formatted line. | |
4722 * If the cursor was moved one line back (e.g. with "Q}") go to the next | |
4723 * line, so "." will do the next lines. | |
4724 */ | |
4725 if (oap->end_adjusted && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
4726 ++curwin->w_cursor.lnum; | |
4727 beginline(BL_WHITE | BL_FIX); | |
4728 old_line_count = curbuf->b_ml.ml_line_count - old_line_count; | |
4729 msgmore(old_line_count); | |
4730 | |
4731 /* put '] mark on the end of the formatted area */ | |
4732 curbuf->b_op_end = curwin->w_cursor; | |
4733 | |
4734 if (keep_cursor) | |
4735 { | |
4736 curwin->w_cursor = saved_cursor; | |
4737 saved_cursor.lnum = 0; | |
4738 } | |
4739 | |
4740 if (oap->is_VIsual) | |
4741 { | |
4742 win_T *wp; | |
4743 | |
4744 FOR_ALL_WINDOWS(wp) | |
4745 { | |
4746 if (wp->w_old_cursor_lnum != 0) | |
4747 { | |
4748 /* When lines have been inserted or deleted, adjust the end of | |
4749 * the Visual area to be redrawn. */ | |
4750 if (wp->w_old_cursor_lnum > wp->w_old_visual_lnum) | |
4751 wp->w_old_cursor_lnum += old_line_count; | |
4752 else | |
4753 wp->w_old_visual_lnum += old_line_count; | |
4754 } | |
4755 } | |
4756 } | |
4757 } | |
4758 | |
667 | 4759 #if defined(FEAT_EVAL) || defined(PROTO) |
4760 /* | |
4761 * Implementation of the format operator 'gq' for when using 'formatexpr'. | |
4762 */ | |
4763 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4764 op_formatexpr(oparg_T *oap) |
667 | 4765 { |
4766 if (oap->is_VIsual) | |
4767 /* When there is no change: need to remove the Visual selection */ | |
4768 redraw_curbuf_later(INVERTED); | |
4769 | |
2298
a3562a127cf6
When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
4770 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
|
4771 /* 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
|
4772 * internal formatting. */ |
a3562a127cf6
When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
4773 op_format(oap, FALSE); |
667 | 4774 } |
4775 | |
4776 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4777 fex_format( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4778 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4779 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4780 int c) /* character to be inserted */ |
667 | 4781 { |
681 | 4782 int use_sandbox = was_set_insecurely((char_u *)"formatexpr", |
4783 OPT_LOCAL); | |
667 | 4784 int r; |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4785 char_u *fex; |
667 | 4786 |
4787 /* | |
4788 * Set v:lnum to the first line number and v:count to the number of lines. | |
844 | 4789 * Set v:char to the character to be inserted (can be NUL). |
667 | 4790 */ |
4791 set_vim_var_nr(VV_LNUM, lnum); | |
4792 set_vim_var_nr(VV_COUNT, count); | |
1969 | 4793 set_vim_var_char(c); |
844 | 4794 |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4795 /* 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
|
4796 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
|
4797 if (fex == NULL) |
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4798 return 0; |
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4799 |
667 | 4800 /* |
4801 * Evaluate the function. | |
4802 */ | |
4803 if (use_sandbox) | |
4804 ++sandbox; | |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4805 r = (int)eval_to_number(fex); |
667 | 4806 if (use_sandbox) |
4807 --sandbox; | |
844 | 4808 |
4809 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
|
4810 vim_free(fex); |
844 | 4811 |
667 | 4812 return r; |
4813 } | |
4814 #endif | |
4815 | |
7 | 4816 /* |
4817 * Format "line_count" lines, starting at the cursor position. | |
4818 * When "line_count" is negative, format until the end of the paragraph. | |
4819 * Lines after the cursor line are saved for undo, caller must have saved the | |
4820 * first line. | |
4821 */ | |
4822 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4823 format_lines( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4824 linenr_T line_count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4825 int avoid_fex) /* don't use 'formatexpr' */ |
7 | 4826 { |
4827 int max_len; | |
4828 int is_not_par; /* current line not part of parag. */ | |
4829 int next_is_not_par; /* next line not part of paragraph */ | |
4830 int is_end_par; /* at end of paragraph */ | |
4831 int prev_is_end_par = FALSE;/* prev. line not part of parag. */ | |
4832 int next_is_start_par = FALSE; | |
4833 #ifdef FEAT_COMMENTS | |
4834 int leader_len = 0; /* leader len of current line */ | |
4835 int next_leader_len; /* leader len of next line */ | |
4836 char_u *leader_flags = NULL; /* flags for leader of current line */ | |
4837 char_u *next_leader_flags; /* flags for leader of next line */ | |
4838 int do_comments; /* format comments */ | |
3584 | 4839 int do_comments_list = 0; /* format comments with 'n' or '2' */ |
7 | 4840 #endif |
4841 int advance = TRUE; | |
3584 | 4842 int second_indent = -1; /* indent for second line (comment |
4843 * aware) */ | |
7 | 4844 int do_second_indent; |
4845 int do_number_indent; | |
4846 int do_trail_white; | |
4847 int first_par_line = TRUE; | |
4848 int smd_save; | |
4849 long count; | |
4850 int need_set_indent = TRUE; /* set indent of next paragraph */ | |
4851 int force_format = FALSE; | |
4852 int old_State = State; | |
4853 | |
4854 /* length of a line to force formatting: 3 * 'tw' */ | |
4855 max_len = comp_textwidth(TRUE) * 3; | |
4856 | |
4857 /* check for 'q', '2' and '1' in 'formatoptions' */ | |
4858 #ifdef FEAT_COMMENTS | |
4859 do_comments = has_format_option(FO_Q_COMS); | |
4860 #endif | |
4861 do_second_indent = has_format_option(FO_Q_SECOND); | |
4862 do_number_indent = has_format_option(FO_Q_NUMBER); | |
4863 do_trail_white = has_format_option(FO_WHITE_PAR); | |
4864 | |
4865 /* | |
4866 * Get info about the previous and current line. | |
4867 */ | |
4868 if (curwin->w_cursor.lnum > 1) | |
4869 is_not_par = fmt_check_par(curwin->w_cursor.lnum - 1 | |
4870 #ifdef FEAT_COMMENTS | |
4871 , &leader_len, &leader_flags, do_comments | |
4872 #endif | |
4873 ); | |
4874 else | |
4875 is_not_par = TRUE; | |
4876 next_is_not_par = fmt_check_par(curwin->w_cursor.lnum | |
4877 #ifdef FEAT_COMMENTS | |
4878 , &next_leader_len, &next_leader_flags, do_comments | |
4879 #endif | |
4880 ); | |
4881 is_end_par = (is_not_par || next_is_not_par); | |
4882 if (!is_end_par && do_trail_white) | |
4883 is_end_par = !ends_in_white(curwin->w_cursor.lnum - 1); | |
4884 | |
4885 curwin->w_cursor.lnum--; | |
4886 for (count = line_count; count != 0 && !got_int; --count) | |
4887 { | |
4888 /* | |
4889 * Advance to next paragraph. | |
4890 */ | |
4891 if (advance) | |
4892 { | |
4893 curwin->w_cursor.lnum++; | |
4894 prev_is_end_par = is_end_par; | |
4895 is_not_par = next_is_not_par; | |
4896 #ifdef FEAT_COMMENTS | |
4897 leader_len = next_leader_len; | |
4898 leader_flags = next_leader_flags; | |
4899 #endif | |
4900 } | |
4901 | |
4902 /* | |
4903 * The last line to be formatted. | |
4904 */ | |
4905 if (count == 1 || curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) | |
4906 { | |
4907 next_is_not_par = TRUE; | |
4908 #ifdef FEAT_COMMENTS | |
4909 next_leader_len = 0; | |
4910 next_leader_flags = NULL; | |
4911 #endif | |
4912 } | |
4913 else | |
4914 { | |
4915 next_is_not_par = fmt_check_par(curwin->w_cursor.lnum + 1 | |
4916 #ifdef FEAT_COMMENTS | |
4917 , &next_leader_len, &next_leader_flags, do_comments | |
4918 #endif | |
4919 ); | |
4920 if (do_number_indent) | |
4921 next_is_start_par = | |
4922 (get_number_indent(curwin->w_cursor.lnum + 1) > 0); | |
4923 } | |
4924 advance = TRUE; | |
4925 is_end_par = (is_not_par || next_is_not_par || next_is_start_par); | |
4926 if (!is_end_par && do_trail_white) | |
4927 is_end_par = !ends_in_white(curwin->w_cursor.lnum); | |
4928 | |
4929 /* | |
4930 * Skip lines that are not in a paragraph. | |
4931 */ | |
4932 if (is_not_par) | |
4933 { | |
4934 if (line_count < 0) | |
4935 break; | |
4936 } | |
4937 else | |
4938 { | |
4939 /* | |
4940 * For the first line of a paragraph, check indent of second line. | |
4941 * Don't do this for comments and empty lines. | |
4942 */ | |
4943 if (first_par_line | |
4944 && (do_second_indent || do_number_indent) | |
4945 && prev_is_end_par | |
3584 | 4946 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) |
4947 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
4948 if (do_second_indent && !LINEEMPTY(curwin->w_cursor.lnum + 1)) |
3584 | 4949 { |
4950 #ifdef FEAT_COMMENTS | |
4951 if (leader_len == 0 && next_leader_len == 0) | |
4952 { | |
4953 /* no comment found */ | |
4954 #endif | |
4955 second_indent = | |
4956 get_indent_lnum(curwin->w_cursor.lnum + 1); | |
7 | 4957 #ifdef FEAT_COMMENTS |
3584 | 4958 } |
4959 else | |
4960 { | |
4961 second_indent = next_leader_len; | |
4962 do_comments_list = 1; | |
4963 } | |
4964 #endif | |
4965 } | |
7 | 4966 else if (do_number_indent) |
3584 | 4967 { |
4968 #ifdef FEAT_COMMENTS | |
4969 if (leader_len == 0 && next_leader_len == 0) | |
4970 { | |
4971 /* no comment found */ | |
4972 #endif | |
4973 second_indent = | |
4974 get_number_indent(curwin->w_cursor.lnum); | |
4975 #ifdef FEAT_COMMENTS | |
4976 } | |
4977 else | |
4978 { | |
4979 /* get_number_indent() is now "comment aware"... */ | |
4980 second_indent = | |
4981 get_number_indent(curwin->w_cursor.lnum); | |
4982 do_comments_list = 1; | |
4983 } | |
4984 #endif | |
4985 } | |
7 | 4986 } |
4987 | |
4988 /* | |
4989 * When the comment leader changes, it's the end of the paragraph. | |
4990 */ | |
4991 if (curwin->w_cursor.lnum >= curbuf->b_ml.ml_line_count | |
4992 #ifdef FEAT_COMMENTS | |
4993 || !same_leader(curwin->w_cursor.lnum, | |
4994 leader_len, leader_flags, | |
4995 next_leader_len, next_leader_flags) | |
4996 #endif | |
4997 ) | |
4998 is_end_par = TRUE; | |
4999 | |
5000 /* | |
5001 * If we have got to the end of a paragraph, or the line is | |
5002 * getting long, format it. | |
5003 */ | |
5004 if (is_end_par || force_format) | |
5005 { | |
5006 if (need_set_indent) | |
5007 /* replace indent in first line with minimal number of | |
5008 * tabs and spaces, according to current options */ | |
5009 (void)set_indent(get_indent(), SIN_CHANGED); | |
5010 | |
5011 /* put cursor on last non-space */ | |
5012 State = NORMAL; /* don't go past end-of-line */ | |
5013 coladvance((colnr_T)MAXCOL); | |
5014 while (curwin->w_cursor.col && vim_isspace(gchar_cursor())) | |
5015 dec_cursor(); | |
5016 | |
5017 /* do the formatting, without 'showmode' */ | |
5018 State = INSERT; /* for open_line() */ | |
5019 smd_save = p_smd; | |
5020 p_smd = FALSE; | |
5021 insertchar(NUL, INSCHAR_FORMAT | |
5022 #ifdef FEAT_COMMENTS | |
5023 + (do_comments ? INSCHAR_DO_COM : 0) | |
3584 | 5024 + (do_comments && do_comments_list |
5025 ? INSCHAR_COM_LIST : 0) | |
7 | 5026 #endif |
1563 | 5027 + (avoid_fex ? INSCHAR_NO_FEX : 0), second_indent); |
7 | 5028 State = old_State; |
5029 p_smd = smd_save; | |
5030 second_indent = -1; | |
5031 /* at end of par.: need to set indent of next par. */ | |
5032 need_set_indent = is_end_par; | |
5033 if (is_end_par) | |
5034 { | |
5035 /* When called with a negative line count, break at the | |
5036 * end of the paragraph. */ | |
5037 if (line_count < 0) | |
5038 break; | |
5039 first_par_line = TRUE; | |
5040 } | |
5041 force_format = FALSE; | |
5042 } | |
5043 | |
5044 /* | |
5045 * When still in same paragraph, join the lines together. But | |
5403 | 5046 * first delete the leader from the second line. |
7 | 5047 */ |
5048 if (!is_end_par) | |
5049 { | |
5050 advance = FALSE; | |
5051 curwin->w_cursor.lnum++; | |
5052 curwin->w_cursor.col = 0; | |
5053 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
|
5054 break; |
7 | 5055 #ifdef FEAT_COMMENTS |
5056 if (next_leader_len > 0) | |
5403 | 5057 { |
5058 (void)del_bytes((long)next_leader_len, FALSE, FALSE); | |
7 | 5059 mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L, |
5060 (long)-next_leader_len); | |
5403 | 5061 } else |
5062 #endif | |
5063 if (second_indent > 0) /* the "leader" for FO_Q_SECOND */ | |
5064 { | |
5065 char_u *p = ml_get_curline(); | |
5415 | 5066 int indent = (int)(skipwhite(p) - p); |
5403 | 5067 |
5068 if (indent > 0) | |
5069 { | |
5070 (void)del_bytes(indent, FALSE, FALSE); | |
5071 mark_col_adjust(curwin->w_cursor.lnum, | |
5072 (colnr_T)0, 0L, (long)-indent); | |
5415 | 5073 } |
5403 | 5074 } |
7 | 5075 curwin->w_cursor.lnum--; |
5848 | 5076 if (do_join(2, TRUE, FALSE, FALSE, FALSE) == FAIL) |
7 | 5077 { |
5078 beep_flush(); | |
5079 break; | |
5080 } | |
5081 first_par_line = FALSE; | |
5082 /* If the line is getting long, format it next time */ | |
5083 if (STRLEN(ml_get_curline()) > (size_t)max_len) | |
5084 force_format = TRUE; | |
5085 else | |
5086 force_format = FALSE; | |
5087 } | |
5088 } | |
5089 line_breakcheck(); | |
5090 } | |
5091 } | |
5092 | |
5093 /* | |
5094 * Return TRUE if line "lnum" ends in a white character. | |
5095 */ | |
5096 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5097 ends_in_white(linenr_T lnum) |
7 | 5098 { |
5099 char_u *s = ml_get(lnum); | |
5100 size_t l; | |
5101 | |
5102 if (*s == NUL) | |
5103 return FALSE; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5104 /* Don't use STRLEN() inside VIM_ISWHITE(), SAS/C complains: "macro |
7 | 5105 * invocation may call function multiple times". */ |
5106 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
|
5107 return VIM_ISWHITE(s[l]); |
7 | 5108 } |
5109 | |
5110 /* | |
5111 * Blank lines, and lines containing only the comment leader, are left | |
5112 * untouched by the formatting. The function returns TRUE in this | |
5113 * case. It also returns TRUE when a line starts with the end of a comment | |
5114 * ('e' in comment flags), so that this line is skipped, and not joined to the | |
5115 * previous line. A new paragraph starts after a blank line, or when the | |
5116 * comment leader changes -- webb. | |
5117 */ | |
5118 #ifdef FEAT_COMMENTS | |
5119 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5120 fmt_check_par( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5121 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5122 int *leader_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5123 char_u **leader_flags, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5124 int do_comments) |
7 | 5125 { |
5126 char_u *flags = NULL; /* init for GCC */ | |
5127 char_u *ptr; | |
5128 | |
5129 ptr = ml_get(lnum); | |
5130 if (do_comments) | |
3562 | 5131 *leader_len = get_leader_len(ptr, leader_flags, FALSE, TRUE); |
7 | 5132 else |
5133 *leader_len = 0; | |
5134 | |
5135 if (*leader_len > 0) | |
5136 { | |
5137 /* | |
5138 * Search for 'e' flag in comment leader flags. | |
5139 */ | |
5140 flags = *leader_flags; | |
5141 while (*flags && *flags != ':' && *flags != COM_END) | |
5142 ++flags; | |
5143 } | |
5144 | |
5145 return (*skipwhite(ptr + *leader_len) == NUL | |
5146 || (*leader_len > 0 && *flags == COM_END) | |
5147 || startPS(lnum, NUL, FALSE)); | |
5148 } | |
5149 #else | |
5150 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5151 fmt_check_par(linenr_T lnum) |
7 | 5152 { |
5153 return (*skipwhite(ml_get(lnum)) == NUL || startPS(lnum, NUL, FALSE)); | |
5154 } | |
5155 #endif | |
5156 | |
5157 /* | |
5158 * Return TRUE when a paragraph starts in line "lnum". Return FALSE when the | |
5159 * previous line is in the same paragraph. Used for auto-formatting. | |
5160 */ | |
5161 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5162 paragraph_start(linenr_T lnum) |
7 | 5163 { |
5164 char_u *p; | |
5165 #ifdef FEAT_COMMENTS | |
5166 int leader_len = 0; /* leader len of current line */ | |
5167 char_u *leader_flags = NULL; /* flags for leader of current line */ | |
5168 int next_leader_len; /* leader len of next line */ | |
5169 char_u *next_leader_flags; /* flags for leader of next line */ | |
5170 int do_comments; /* format comments */ | |
5171 #endif | |
5172 | |
5173 if (lnum <= 1) | |
5174 return TRUE; /* start of the file */ | |
5175 | |
5176 p = ml_get(lnum - 1); | |
5177 if (*p == NUL) | |
5178 return TRUE; /* after empty line */ | |
5179 | |
5180 #ifdef FEAT_COMMENTS | |
5181 do_comments = has_format_option(FO_Q_COMS); | |
5182 #endif | |
5183 if (fmt_check_par(lnum - 1 | |
5184 #ifdef FEAT_COMMENTS | |
5185 , &leader_len, &leader_flags, do_comments | |
5186 #endif | |
5187 )) | |
5188 return TRUE; /* after non-paragraph line */ | |
5189 | |
5190 if (fmt_check_par(lnum | |
5191 #ifdef FEAT_COMMENTS | |
5192 , &next_leader_len, &next_leader_flags, do_comments | |
5193 #endif | |
5194 )) | |
5195 return TRUE; /* "lnum" is not a paragraph line */ | |
5196 | |
5197 if (has_format_option(FO_WHITE_PAR) && !ends_in_white(lnum - 1)) | |
5198 return TRUE; /* missing trailing space in previous line. */ | |
5199 | |
5200 if (has_format_option(FO_Q_NUMBER) && (get_number_indent(lnum) > 0)) | |
5201 return TRUE; /* numbered item starts in "lnum". */ | |
5202 | |
5203 #ifdef FEAT_COMMENTS | |
5204 if (!same_leader(lnum - 1, leader_len, leader_flags, | |
5205 next_leader_len, next_leader_flags)) | |
5206 return TRUE; /* change of comment leader. */ | |
5207 #endif | |
5208 | |
5209 return FALSE; | |
5210 } | |
5211 | |
5212 /* | |
5213 * prepare a few things for block mode yank/delete/tilde | |
5214 * | |
5215 * for delete: | |
5216 * - textlen includes the first/last char to be (partly) deleted | |
5217 * - start/endspaces is the number of columns that are taken by the | |
5218 * first/last deleted char minus the number of columns that have to be | |
1839 | 5219 * deleted. |
5220 * for yank and tilde: | |
7 | 5221 * - textlen includes the first/last char to be wholly yanked |
5222 * - start/endspaces is the number of columns of the first/last yanked char | |
5223 * that are to be yanked. | |
5224 */ | |
5225 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5226 block_prep( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5227 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5228 struct block_def *bdp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5229 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5230 int is_del) |
7 | 5231 { |
5232 int incr = 0; | |
5233 char_u *pend; | |
5234 char_u *pstart; | |
5235 char_u *line; | |
5236 char_u *prev_pstart; | |
5237 char_u *prev_pend; | |
5238 | |
5239 bdp->startspaces = 0; | |
5240 bdp->endspaces = 0; | |
5241 bdp->textlen = 0; | |
5242 bdp->start_vcol = 0; | |
5243 bdp->end_vcol = 0; | |
5244 #ifdef FEAT_VISUALEXTRA | |
5245 bdp->is_short = FALSE; | |
5246 bdp->is_oneChar = FALSE; | |
5247 bdp->pre_whitesp = 0; | |
5248 bdp->pre_whitesp_c = 0; | |
5249 bdp->end_char_vcols = 0; | |
5250 #endif | |
5251 bdp->start_char_vcols = 0; | |
5252 | |
5253 line = ml_get(lnum); | |
5254 pstart = line; | |
5255 prev_pstart = line; | |
5256 while (bdp->start_vcol < oap->start_vcol && *pstart) | |
5257 { | |
5258 /* Count a tab for what it's worth (if list mode not on) */ | |
5995 | 5259 incr = lbr_chartabsize(line, pstart, (colnr_T)bdp->start_vcol); |
7 | 5260 bdp->start_vcol += incr; |
5261 #ifdef FEAT_VISUALEXTRA | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5262 if (VIM_ISWHITE(*pstart)) |
7 | 5263 { |
5264 bdp->pre_whitesp += incr; | |
5265 bdp->pre_whitesp_c++; | |
5266 } | |
5267 else | |
5268 { | |
5269 bdp->pre_whitesp = 0; | |
5270 bdp->pre_whitesp_c = 0; | |
5271 } | |
5272 #endif | |
5273 prev_pstart = pstart; | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
5274 MB_PTR_ADV(pstart); |
7 | 5275 } |
5276 bdp->start_char_vcols = incr; | |
5277 if (bdp->start_vcol < oap->start_vcol) /* line too short */ | |
5278 { | |
5279 bdp->end_vcol = bdp->start_vcol; | |
5280 #ifdef FEAT_VISUALEXTRA | |
5281 bdp->is_short = TRUE; | |
5282 #endif | |
5283 if (!is_del || oap->op_type == OP_APPEND) | |
5284 bdp->endspaces = oap->end_vcol - oap->start_vcol + 1; | |
5285 } | |
5286 else | |
5287 { | |
5288 /* notice: this converts partly selected Multibyte characters to | |
5289 * spaces, too. */ | |
5290 bdp->startspaces = bdp->start_vcol - oap->start_vcol; | |
5291 if (is_del && bdp->startspaces) | |
5292 bdp->startspaces = bdp->start_char_vcols - bdp->startspaces; | |
5293 pend = pstart; | |
5294 bdp->end_vcol = bdp->start_vcol; | |
5295 if (bdp->end_vcol > oap->end_vcol) /* it's all in one character */ | |
5296 { | |
5297 #ifdef FEAT_VISUALEXTRA | |
5298 bdp->is_oneChar = TRUE; | |
5299 #endif | |
5300 if (oap->op_type == OP_INSERT) | |
5301 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces; | |
5302 else if (oap->op_type == OP_APPEND) | |
5303 { | |
5304 bdp->startspaces += oap->end_vcol - oap->start_vcol + 1; | |
5305 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces; | |
5306 } | |
5307 else | |
5308 { | |
5309 bdp->startspaces = oap->end_vcol - oap->start_vcol + 1; | |
5310 if (is_del && oap->op_type != OP_LSHIFT) | |
5311 { | |
5312 /* just putting the sum of those two into | |
5313 * bdp->startspaces doesn't work for Visual replace, | |
5314 * so we have to split the tab in two */ | |
5315 bdp->startspaces = bdp->start_char_vcols | |
5316 - (bdp->start_vcol - oap->start_vcol); | |
5317 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; | |
5318 } | |
5319 } | |
5320 } | |
5321 else | |
5322 { | |
5323 prev_pend = pend; | |
5324 while (bdp->end_vcol <= oap->end_vcol && *pend != NUL) | |
5325 { | |
5326 /* Count a tab for what it's worth (if list mode not on) */ | |
5327 prev_pend = pend; | |
6535 | 5328 incr = lbr_chartabsize_adv(line, &pend, (colnr_T)bdp->end_vcol); |
7 | 5329 bdp->end_vcol += incr; |
5330 } | |
5331 if (bdp->end_vcol <= oap->end_vcol | |
5332 && (!is_del | |
5333 || oap->op_type == OP_APPEND | |
5334 || oap->op_type == OP_REPLACE)) /* line too short */ | |
5335 { | |
5336 #ifdef FEAT_VISUALEXTRA | |
5337 bdp->is_short = TRUE; | |
5338 #endif | |
5339 /* Alternative: include spaces to fill up the block. | |
5340 * Disadvantage: can lead to trailing spaces when the line is | |
5341 * short where the text is put */ | |
5342 /* if (!is_del || oap->op_type == OP_APPEND) */ | |
5343 if (oap->op_type == OP_APPEND || virtual_op) | |
5344 bdp->endspaces = oap->end_vcol - bdp->end_vcol | |
593 | 5345 + oap->inclusive; |
7 | 5346 else |
5347 bdp->endspaces = 0; /* replace doesn't add characters */ | |
5348 } | |
5349 else if (bdp->end_vcol > oap->end_vcol) | |
5350 { | |
5351 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; | |
5352 if (!is_del && bdp->endspaces) | |
5353 { | |
5354 bdp->endspaces = incr - bdp->endspaces; | |
5355 if (pend != pstart) | |
5356 pend = prev_pend; | |
5357 } | |
5358 } | |
5359 } | |
5360 #ifdef FEAT_VISUALEXTRA | |
5361 bdp->end_char_vcols = incr; | |
5362 #endif | |
5363 if (is_del && bdp->startspaces) | |
5364 pstart = prev_pstart; | |
5365 bdp->textlen = (int)(pend - pstart); | |
5366 } | |
5367 bdp->textcol = (colnr_T) (pstart - line); | |
5368 bdp->textstart = pstart; | |
5369 } | |
5370 | |
5371 /* | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5372 * Handle the add/subtract operator. |
7 | 5373 */ |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5374 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5375 op_addsub( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5376 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5377 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
|
5378 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
|
5379 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5380 pos_T pos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5381 struct block_def bd; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5382 int change_cnt = 0; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5383 linenr_T amount = Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5384 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5385 if (!VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5386 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5387 pos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5388 if (u_save_cursor() == FAIL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5389 return; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5390 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
|
5391 if (change_cnt) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5392 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
|
5393 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5394 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5395 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5396 int one_change; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5397 int length; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5398 pos_T startpos; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5399 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5400 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
|
5401 (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
|
5402 return; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5403 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5404 pos = oap->start; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5405 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
|
5406 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5407 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
|
5408 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5409 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
|
5410 pos.col = bd.textcol; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5411 length = bd.textlen; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5412 } |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5413 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
|
5414 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5415 curwin->w_cursor.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5416 pos.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5417 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
|
5418 } |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5419 else /* oap->motion_type == MCHAR */ |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5420 { |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5421 if (!oap->inclusive) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5422 dec(&(oap->end)); |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5423 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
|
5424 pos.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5425 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
|
5426 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5427 pos.col += oap->start.col; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5428 length -= oap->start.col; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5429 } |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5430 if (pos.lnum == oap->end.lnum) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5431 { |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5432 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
|
5433 if (oap->end.col >= length) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5434 oap->end.col = length - 1; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5435 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
|
5436 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5437 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5438 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
|
5439 if (one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5440 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5441 /* 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
|
5442 if (change_cnt == 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5443 startpos = curbuf->b_op_start; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5444 ++change_cnt; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5445 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5446 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5447 #ifdef FEAT_NETBEANS_INTG |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5448 if (netbeans_active() && one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5449 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5450 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
|
5451 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5452 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
|
5453 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
|
5454 &ptr[pos.col], length); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5455 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5456 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5457 if (g_cmd && one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5458 amount += Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5459 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5460 if (change_cnt) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5461 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
|
5462 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5463 if (!change_cnt && oap->is_VIsual) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5464 /* 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
|
5465 redraw_curbuf_later(INVERTED); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5466 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5467 /* 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
|
5468 * position from do_addsub(). */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5469 if (change_cnt > 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5470 curbuf->b_op_start = startpos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5471 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5472 if (change_cnt > p_report) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5473 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5474 if (change_cnt == 1) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5475 MSG(_("1 line changed")); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5476 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5477 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
|
5478 } |
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 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5481 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5482 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5483 * 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
|
5484 * 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
|
5485 * |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5486 * 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
|
5487 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5488 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5489 do_addsub( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5490 int op_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5491 pos_T *pos, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5492 int length, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5493 linenr_T Prenum1) |
7 | 5494 { |
5495 int col; | |
5496 char_u *buf1; | |
5497 char_u buf2[NUMBUFLEN]; | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5498 int pre; /* 'X'/'x': hex; '0': octal; 'B'/'b': bin */ |
7 | 5499 static int hexupper = FALSE; /* 0xABC */ |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5500 uvarnumber_T n; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5501 uvarnumber_T oldn; |
7 | 5502 char_u *ptr; |
5503 int c; | |
5504 int todel; | |
5505 int dohex; | |
5506 int dooct; | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5507 int dobin; |
7 | 5508 int doalp; |
5509 int firstdigit; | |
5510 int subtract; | |
6868 | 5511 int negative = FALSE; |
6891 | 5512 int was_positive = TRUE; |
6868 | 5513 int visual = VIsual_active; |
6921 | 5514 int did_change = FALSE; |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5515 pos_T save_cursor = curwin->w_cursor; |
6927 | 5516 int maxlen = 0; |
7570
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5517 pos_T startpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5518 pos_T endpos; |
7 | 5519 |
5520 dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); /* "heX" */ | |
5521 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
|
5522 dobin = (vim_strchr(curbuf->b_p_nf, 'b') != NULL); /* "Bin" */ |
7 | 5523 doalp = (vim_strchr(curbuf->b_p_nf, 'p') != NULL); /* "alPha" */ |
5524 | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5525 curwin->w_cursor = *pos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5526 ptr = ml_get(pos->lnum); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5527 col = pos->col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5528 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5529 if (*ptr == NUL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5530 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5531 |
7 | 5532 /* |
5533 * First check if we are on a hexadecimal number, after the "0x". | |
5534 */ | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5535 if (!VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5536 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5537 if (dobin) |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5538 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
|
5539 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5540 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5541 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5542 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5543 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
|
5544 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5545 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5546 |
6868 | 5547 if (dohex) |
5548 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
|
5549 { |
6868 | 5550 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5551 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5552 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5553 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
|
5554 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5555 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5556 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5557 if ( dobin |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5558 && dohex |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5559 && ! ((col > 0 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5560 && (ptr[col] == 'X' |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5561 || ptr[col] == 'x') |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5562 && ptr[col - 1] == '0' |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5563 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5564 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5565 !(*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
|
5566 #endif |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5567 && vim_isxdigit(ptr[col + 1])))) |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5568 { |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5569 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5570 /* 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
|
5571 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5572 col = pos->col; |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5573 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5574 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
|
5575 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5576 col--; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5577 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5578 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5579 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
|
5580 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5581 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5582 } |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5583 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5584 if (( dohex |
6868 | 5585 && col > 0 |
5586 && (ptr[col] == 'X' | |
5587 || ptr[col] == 'x') | |
5588 && ptr[col - 1] == '0' | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5589 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5590 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5591 !(*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
|
5592 #endif |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5593 && vim_isxdigit(ptr[col + 1])) || |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5594 ( dobin |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5595 && col > 0 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5596 && (ptr[col] == 'B' |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5597 || ptr[col] == 'b') |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5598 && ptr[col - 1] == '0' |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5599 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5600 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5601 !(*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
|
5602 #endif |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5603 && vim_isbdigit(ptr[col + 1]))) |
6868 | 5604 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5605 /* Found hexadecimal or binary number, move to its start. */ |
7 | 5606 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5607 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5608 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5609 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
|
5610 #endif |
6868 | 5611 } |
5612 else | |
7 | 5613 { |
6868 | 5614 /* |
5615 * Search forward and then backward to find the start of number. | |
5616 */ | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5617 col = pos->col; |
6868 | 5618 |
5619 while (ptr[col] != NUL | |
5620 && !vim_isdigit(ptr[col]) | |
5621 && !(doalp && ASCII_ISALPHA(ptr[col]))) | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5622 col += MB_PTR2LEN(ptr + col); |
6868 | 5623 |
5624 while (col > 0 | |
5625 && vim_isdigit(ptr[col - 1]) | |
5626 && !(doalp && ASCII_ISALPHA(ptr[col]))) | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5627 { |
6868 | 5628 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5629 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5630 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5631 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
|
5632 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5633 } |
6868 | 5634 } |
5635 } | |
5636 | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5637 if (visual) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5638 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5639 while (ptr[col] != NUL && length > 0 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5640 && !vim_isdigit(ptr[col]) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5641 && !(doalp && ASCII_ISALPHA(ptr[col]))) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5642 { |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5643 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
|
5644 |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5645 col += mb_len; |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5646 length -= mb_len; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5647 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5648 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5649 if (length == 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5650 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5651 |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5652 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
|
5653 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5654 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5655 !(*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
|
5656 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5657 ) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5658 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5659 negative = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5660 was_positive = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5661 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5662 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5663 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5664 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5665 * 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
|
5666 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5667 firstdigit = ptr[col]; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5668 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
|
5669 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5670 beep_flush(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5671 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5672 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5673 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5674 if (doalp && ASCII_ISALPHA(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5675 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5676 /* decrement or increment alphabetic character */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5677 if (op_type == OP_NR_SUB) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5678 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5679 if (CharOrd(firstdigit) < Prenum1) |
6927 | 5680 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5681 if (isupper(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5682 firstdigit = 'A'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5683 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5684 firstdigit = 'a'; |
6927 | 5685 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5686 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5687 #ifdef EBCDIC |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5688 firstdigit = EBCDIC_CHAR_ADD(firstdigit, -Prenum1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5689 #else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5690 firstdigit -= Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5691 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5692 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5693 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5694 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5695 if (26 - CharOrd(firstdigit) - 1 < Prenum1) |
6927 | 5696 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5697 if (isupper(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5698 firstdigit = 'Z'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5699 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5700 firstdigit = 'z'; |
6927 | 5701 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5702 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5703 #ifdef EBCDIC |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5704 firstdigit = EBCDIC_CHAR_ADD(firstdigit, Prenum1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5705 #else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5706 firstdigit += Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5707 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5708 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5709 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5710 if (!did_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5711 startpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5712 did_change = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5713 (void)del_char(FALSE); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5714 ins_char(firstdigit); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5715 endpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5716 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5717 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5718 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5719 { |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5720 if (col > 0 && ptr[col - 1] == '-' |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5721 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5722 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5723 !(*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
|
5724 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5725 && !visual) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5726 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5727 /* negative number */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5728 --col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5729 negative = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5730 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5731 /* get the number value (unsigned) */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5732 if (visual && VIsual_mode != 'V') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5733 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
|
5734 ? (int)STRLEN(ptr) - col |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5735 : length); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5736 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5737 vim_str2nr(ptr + col, &pre, &length, |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5738 0 + (dobin ? STR2NR_BIN : 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5739 + (dooct ? STR2NR_OCT : 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5740 + (dohex ? STR2NR_HEX : 0), |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5741 NULL, &n, maxlen); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5742 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5743 /* 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
|
5744 if (pre && negative) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5745 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5746 ++col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5747 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5748 negative = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5749 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5750 /* add or subtract */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5751 subtract = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5752 if (op_type == OP_NR_SUB) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5753 subtract ^= TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5754 if (negative) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5755 subtract ^= TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5756 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5757 oldn = n; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5758 if (subtract) |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5759 n -= (uvarnumber_T)Prenum1; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5760 else |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5761 n += (uvarnumber_T)Prenum1; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5762 /* handle wraparound for decimal numbers */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5763 if (!pre) |
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 (subtract) |
6927 | 5766 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5767 if (n > oldn) |
6868 | 5768 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5769 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
|
5770 negative ^= TRUE; |
6868 | 5771 } |
7 | 5772 } |
5773 else | |
6868 | 5774 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5775 /* add */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5776 if (n < oldn) |
6868 | 5777 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5778 n = (n ^ (uvarnumber_T)-1); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5779 negative ^= TRUE; |
6868 | 5780 } |
6927 | 5781 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5782 if (n == 0) |
6868 | 5783 negative = FALSE; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5784 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5785 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5786 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
|
5787 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5788 /* need to remove the '-' */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5789 col--; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5790 length++; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5791 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5792 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5793 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5794 * Delete the old number. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5795 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5796 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5797 if (!did_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5798 startpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5799 did_change = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5800 todel = length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5801 c = gchar_cursor(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5802 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5803 * 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
|
5804 * 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
|
5805 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5806 if (c == '-') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5807 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5808 while (todel-- > 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5809 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5810 if (c < 0x100 && isalpha(c)) |
6868 | 5811 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5812 if (isupper(c)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5813 hexupper = TRUE; |
6868 | 5814 else |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5815 hexupper = FALSE; |
6891 | 5816 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5817 /* 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
|
5818 (void)del_char(FALSE); |
6868 | 5819 c = gchar_cursor(); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5820 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5821 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5822 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5823 * Prepare the leading characters in buf1[]. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5824 * 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
|
5825 * Allocate a bit too much. |
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 buf1 = alloc((unsigned)length + NUMBUFLEN); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5828 if (buf1 == NULL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5829 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5830 ptr = buf1; |
8989
e600e696c0a1
commit https://github.com/vim/vim/commit/dc633cf82758f67f656cda7fa8ccc30414ee53f8
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
5831 if (negative && (!visual || was_positive)) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5832 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5833 *ptr++ = '-'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5834 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5835 if (pre) |
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 *ptr++ = '0'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5838 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5839 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5840 if (pre == 'b' || pre == 'B' || |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5841 pre == 'x' || pre == 'X') |
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 *ptr++ = pre; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5844 --length; |
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 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5847 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5848 * Put the number characters in buf2[]. |
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 if (pre == 'b' || pre == 'B') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5851 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5852 int i; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5853 int bit = 0; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5854 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
|
5855 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5856 /* leading zeros */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5857 for (bit = bits; bit > 0; bit--) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5858 if ((n >> (bit - 1)) & 0x1) break; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5859 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5860 for (i = 0; bit > 0; bit--) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5861 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
|
5862 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5863 buf2[i] = '\0'; |
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 else if (pre == 0) |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5866 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
|
5867 else if (pre == '0') |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5868 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
|
5869 else if (pre && hexupper) |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5870 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
|
5871 else |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5872 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
|
5873 length -= (int)STRLEN(buf2); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5874 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5875 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5876 * 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
|
5877 * 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
|
5878 * Don't do this when |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5879 * 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
|
5880 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5881 if (firstdigit == '0' && !(dooct && pre == 0)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5882 while (length-- > 0) |
6868 | 5883 *ptr++ = '0'; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5884 *ptr = NUL; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5885 STRCAT(buf1, buf2); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5886 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
|
5887 vim_free(buf1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5888 endpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5889 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
|
5890 --curwin->w_cursor.col; |
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 |
7570
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5893 if (did_change) |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5894 { |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5895 /* set the '[ and '] marks */ |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5896 curbuf->b_op_start = startpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5897 curbuf->b_op_end = endpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5898 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
|
5899 --curbuf->b_op_end.col; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5900 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5901 |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5902 theend: |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5903 if (visual) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5904 curwin->w_cursor = save_cursor; |
8690
6a1becf4f282
commit https://github.com/vim/vim/commit/8e08125d3a9afd0b16cd84454ae9ddad0abaaab0
Christian Brabandt <cb@256bit.org>
parents:
8399
diff
changeset
|
5905 else if (did_change) |
6a1becf4f282
commit https://github.com/vim/vim/commit/8e08125d3a9afd0b16cd84454ae9ddad0abaaab0
Christian Brabandt <cb@256bit.org>
parents:
8399
diff
changeset
|
5906 curwin->w_set_curswant = TRUE; |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5907 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5908 return did_change; |
7 | 5909 } |
5910 | |
5911 #ifdef FEAT_VIMINFO | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5912 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5913 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
|
5914 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5915 #define REG_PREVIOUS 1 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5916 #define REG_EXEC 2 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5917 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5918 /* |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5919 * 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
|
5920 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5921 void |
9282
9f97a6290c63
commit https://github.com/vim/vim/commit/cf089463492fab53b2a5d81517829d22f882f82e
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
5922 prepare_viminfo_registers(void) |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5923 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5924 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
|
5925 * (int)sizeof(yankreg_T)); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5926 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5927 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5928 void |
9282
9f97a6290c63
commit https://github.com/vim/vim/commit/cf089463492fab53b2a5d81517829d22f882f82e
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
5929 finish_viminfo_registers(void) |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5930 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5931 int i; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5932 int j; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5933 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5934 if (y_read_regs != NULL) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5935 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5936 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
|
5937 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
|
5938 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5939 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
|
5940 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
|
5941 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
|
5942 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5943 vim_free(y_read_regs); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5944 y_read_regs = NULL; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5945 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5946 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5947 |
7 | 5948 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5949 read_viminfo_register(vir_T *virp, int force) |
7 | 5950 { |
5951 int eof; | |
5952 int do_it = TRUE; | |
5953 int size; | |
5954 int limit; | |
5955 int i; | |
5956 int set_prev = FALSE; | |
5957 char_u *str; | |
5958 char_u **array = NULL; | |
6508 | 5959 int new_type = MCHAR; /* init to shut up compiler */ |
5960 colnr_T new_width = 0; /* init to shut up compiler */ | |
7 | 5961 |
5962 /* We only get here (hopefully) if line[0] == '"' */ | |
5963 str = virp->vir_line + 1; | |
1893 | 5964 |
5965 /* If the line starts with "" this is the y_previous register. */ | |
7 | 5966 if (*str == '"') |
5967 { | |
5968 set_prev = TRUE; | |
5969 str++; | |
5970 } | |
1893 | 5971 |
7 | 5972 if (!ASCII_ISALNUM(*str) && *str != '-') |
5973 { | |
5974 if (viminfo_error("E577: ", _("Illegal register name"), virp->vir_line)) | |
5975 return TRUE; /* too many errors, pretend end-of-file */ | |
5976 do_it = FALSE; | |
5977 } | |
5978 get_yank_register(*str++, FALSE); | |
5979 if (!force && y_current->y_array != NULL) | |
5980 do_it = FALSE; | |
1893 | 5981 |
5982 if (*str == '@') | |
5983 { | |
5984 /* "x@: register x used for @@ */ | |
5985 if (force || execreg_lastc == NUL) | |
5986 execreg_lastc = str[-1]; | |
5987 } | |
5988 | |
7 | 5989 size = 0; |
5990 limit = 100; /* Optimized for registers containing <= 100 lines */ | |
5991 if (do_it) | |
5992 { | |
6462 | 5993 /* |
5994 * Build the new register in array[]. | |
5995 * y_array is kept as-is until done. | |
5996 * The "do_it" flag is reset when something is wrong, in which case | |
5997 * array[] needs to be freed. | |
5998 */ | |
7 | 5999 if (set_prev) |
6000 y_previous = y_current; | |
6462 | 6001 array = (char_u **)alloc((unsigned)(limit * sizeof(char_u *))); |
1893 | 6002 str = skipwhite(skiptowhite(str)); |
7 | 6003 if (STRNCMP(str, "CHAR", 4) == 0) |
6462 | 6004 new_type = MCHAR; |
7 | 6005 else if (STRNCMP(str, "BLOCK", 5) == 0) |
6462 | 6006 new_type = MBLOCK; |
7 | 6007 else |
6462 | 6008 new_type = MLINE; |
7 | 6009 /* get the block width; if it's missing we get a zero, which is OK */ |
6010 str = skipwhite(skiptowhite(str)); | |
6462 | 6011 new_width = getdigits(&str); |
7 | 6012 } |
6013 | |
6014 while (!(eof = viminfo_readline(virp)) | |
6015 && (virp->vir_line[0] == TAB || virp->vir_line[0] == '<')) | |
6016 { | |
6017 if (do_it) | |
6018 { | |
6462 | 6019 if (size == limit) |
7 | 6020 { |
6462 | 6021 char_u **new_array = (char_u **) |
7 | 6022 alloc((unsigned)(limit * 2 * sizeof(char_u *))); |
6462 | 6023 |
6024 if (new_array == NULL) | |
6025 { | |
6026 do_it = FALSE; | |
6027 break; | |
6028 } | |
7 | 6029 for (i = 0; i < limit; i++) |
6462 | 6030 new_array[i] = array[i]; |
7 | 6031 vim_free(array); |
6462 | 6032 array = new_array; |
7 | 6033 limit *= 2; |
6034 } | |
6035 str = viminfo_readstring(virp, 1, TRUE); | |
6036 if (str != NULL) | |
6037 array[size++] = str; | |
6038 else | |
6462 | 6039 /* error, don't store the result */ |
7 | 6040 do_it = FALSE; |
6041 } | |
6042 } | |
6508 | 6043 |
7 | 6044 if (do_it) |
6045 { | |
6462 | 6046 /* free y_array[] */ |
6047 for (i = 0; i < y_current->y_size; i++) | |
6048 vim_free(y_current->y_array[i]); | |
6049 vim_free(y_current->y_array); | |
6050 | |
6051 y_current->y_type = new_type; | |
6052 y_current->y_width = new_width; | |
6053 y_current->y_size = size; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6054 y_current->y_time_set = 0; |
7 | 6055 if (size == 0) |
6056 { | |
6057 y_current->y_array = NULL; | |
6058 } | |
6462 | 6059 else |
7 | 6060 { |
6462 | 6061 /* Move the lines from array[] to y_array[]. */ |
7 | 6062 y_current->y_array = |
6063 (char_u **)alloc((unsigned)(size * sizeof(char_u *))); | |
6064 for (i = 0; i < size; i++) | |
6462 | 6065 { |
6066 if (y_current->y_array == NULL) | |
6067 vim_free(array[i]); | |
6068 else | |
6069 y_current->y_array[i] = array[i]; | |
6070 } | |
7 | 6071 } |
6462 | 6072 } |
6073 else | |
6074 { | |
6075 /* Free array[] if it was filled. */ | |
6076 for (i = 0; i < size; i++) | |
6077 vim_free(array[i]); | |
6078 } | |
6079 vim_free(array); | |
6080 | |
7 | 6081 return eof; |
6082 } | |
6083 | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6084 /* |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6085 * 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
|
6086 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6087 void |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6088 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
|
6089 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6090 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
|
6091 int flags; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6092 int name; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6093 int type; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6094 int linecount; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6095 int width; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6096 time_t timestamp; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6097 yankreg_T *y_ptr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6098 int i; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6099 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6100 /* Check the format: |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6101 * |{bartype},{flags},{name},{type}, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6102 * {linecount},{width},{timestamp},"line1","line2" |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6103 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6104 if (values->ga_len < 6 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6105 || vp[0].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6106 || vp[1].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6107 || vp[2].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6108 || vp[3].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6109 || vp[4].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6110 || vp[5].bv_type != BVAL_NR) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6111 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6112 flags = vp[0].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6113 name = vp[1].bv_nr; |
9307
eb52a2670c96
commit https://github.com/vim/vim/commit/67e3720a9ddd8a9d2e8344358c28fa1f4196db0d
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
6114 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
|
6115 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6116 type = vp[2].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6117 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
|
6118 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6119 linecount = vp[3].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6120 if (values->ga_len < 6 + linecount) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6121 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6122 width = vp[4].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6123 if (width < 0) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6124 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6125 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6126 if (y_read_regs != NULL) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6127 /* 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
|
6128 * 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
|
6129 y_ptr = &y_read_regs[name]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6130 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6131 y_ptr = &y_regs[name]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6132 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6133 /* 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
|
6134 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
|
6135 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
|
6136 && (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
|
6137 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6138 |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
6139 if (y_ptr->y_array != NULL) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
6140 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
|
6141 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
|
6142 vim_free(y_ptr->y_array); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6143 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6144 if (y_read_regs == NULL) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6145 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6146 if (flags & REG_PREVIOUS) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6147 y_previous = y_ptr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6148 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
|
6149 execreg_lastc = get_register_name(name); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6150 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6151 y_ptr->y_type = type; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6152 y_ptr->y_width = width; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6153 y_ptr->y_size = linecount; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6154 y_ptr->y_time_set = timestamp; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6155 if (linecount == 0) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6156 y_ptr->y_array = NULL; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6157 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6158 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6159 y_ptr->y_array = |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6160 (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
|
6161 for (i = 0; i < linecount; i++) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6162 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6163 if (vp[i + 6].bv_allocated) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6164 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6165 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
|
6166 vp[i + 6].bv_string = NULL; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6167 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6168 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6169 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
|
6170 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6171 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6172 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6173 |
7 | 6174 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6175 write_viminfo_registers(FILE *fp) |
7 | 6176 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6177 int i, j; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6178 char_u *type; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6179 char_u c; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6180 int num_lines; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6181 int max_num_lines; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6182 int max_kbyte; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6183 long len; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6184 yankreg_T *y_ptr; |
7 | 6185 |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
6186 fputs(_("\n# Registers:\n"), fp); |
7 | 6187 |
6188 /* Get '<' value, use old '"' value if '<' is not found. */ | |
6189 max_num_lines = get_viminfo_parameter('<'); | |
6190 if (max_num_lines < 0) | |
6191 max_num_lines = get_viminfo_parameter('"'); | |
6192 if (max_num_lines == 0) | |
6193 return; | |
6194 max_kbyte = get_viminfo_parameter('s'); | |
6195 if (max_kbyte == 0) | |
6196 return; | |
1893 | 6197 |
7 | 6198 for (i = 0; i < NUM_REGISTERS; i++) |
6199 { | |
6200 #ifdef FEAT_CLIPBOARD | |
6201 /* Skip '*'/'+' register, we don't want them back next time */ | |
6202 if (i == STAR_REGISTER || i == PLUS_REGISTER) | |
6203 continue; | |
6204 #endif | |
6205 #ifdef FEAT_DND | |
6206 /* Neither do we want the '~' register */ | |
6207 if (i == TILDE_REGISTER) | |
6208 continue; | |
6209 #endif | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6210 /* 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
|
6211 * viminfo if it's newer. */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6212 if (y_read_regs != NULL |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6213 && 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
|
6214 && (y_regs[i].y_array == NULL || |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6215 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
|
6216 y_ptr = &y_read_regs[i]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6217 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
|
6218 continue; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6219 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6220 y_ptr = &y_regs[i]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6221 |
55 | 6222 /* Skip empty registers. */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6223 num_lines = y_ptr->y_size; |
55 | 6224 if (num_lines == 0 |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6225 || (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
|
6226 && *y_ptr->y_array[0] == NUL)) |
55 | 6227 continue; |
6228 | |
7 | 6229 if (max_kbyte > 0) |
6230 { | |
6231 /* Skip register if there is more text than the maximum size. */ | |
6232 len = 0; | |
6233 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
|
6234 len += (long)STRLEN(y_ptr->y_array[j]) + 1L; |
7 | 6235 if (len > (long)max_kbyte * 1024L) |
6236 continue; | |
6237 } | |
6238 | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6239 switch (y_ptr->y_type) |
7 | 6240 { |
6241 case MLINE: | |
6242 type = (char_u *)"LINE"; | |
6243 break; | |
6244 case MCHAR: | |
6245 type = (char_u *)"CHAR"; | |
6246 break; | |
6247 case MBLOCK: | |
6248 type = (char_u *)"BLOCK"; | |
6249 break; | |
6250 default: | |
6251 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
|
6252 y_ptr->y_type); |
7 | 6253 emsg(IObuff); |
6254 type = (char_u *)"LINE"; | |
6255 break; | |
6256 } | |
6257 if (y_previous == &y_regs[i]) | |
6258 fprintf(fp, "\""); | |
6259 c = get_register_name(i); | |
1893 | 6260 fprintf(fp, "\"%c", c); |
6261 if (c == execreg_lastc) | |
6262 fprintf(fp, "@"); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6263 fprintf(fp, "\t%s\t%d\n", type, (int)y_ptr->y_width); |
7 | 6264 |
6265 /* If max_num_lines < 0, then we save ALL the lines in the register */ | |
6266 if (max_num_lines > 0 && num_lines > max_num_lines) | |
6267 num_lines = max_num_lines; | |
6268 for (j = 0; j < num_lines; j++) | |
6269 { | |
6270 putc('\t', fp); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6271 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
|
6272 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6273 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6274 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6275 int flags = 0; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6276 int remaining; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6277 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6278 /* 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
|
6279 * |{bartype},{flags},{name},{type}, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6280 * {linecount},{width},{timestamp},"line1","line2" |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6281 * flags: REG_PREVIOUS - register is y_previous |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6282 * REG_EXEC - used for @@ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6283 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6284 if (y_previous == &y_regs[i]) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6285 flags |= REG_PREVIOUS; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6286 if (c == execreg_lastc) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6287 flags |= REG_EXEC; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6288 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
|
6289 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
|
6290 (long)y_ptr->y_time_set); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6291 /* 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
|
6292 remaining = LSIZE - 71; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6293 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
|
6294 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6295 putc(',', fp); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6296 --remaining; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6297 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
|
6298 remaining); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6299 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6300 putc('\n', fp); |
7 | 6301 } |
6302 } | |
6303 } | |
6304 #endif /* FEAT_VIMINFO */ | |
6305 | |
6306 #if defined(FEAT_CLIPBOARD) || defined(PROTO) | |
6307 /* | |
6308 * SELECTION / PRIMARY ('*') | |
6309 * | |
6310 * Text selection stuff that uses the GUI selection register '*'. When using a | |
6311 * GUI this may be text from another window, otherwise it is the last text we | |
6312 * had highlighted with VIsual mode. With mouse support, clicking the middle | |
6313 * button performs the paste, otherwise you will need to do <"*p>. " | |
6314 * If not under X, it is synonymous with the clipboard register '+'. | |
6315 * | |
6316 * X CLIPBOARD ('+') | |
6317 * | |
6318 * Text selection stuff that uses the GUI clipboard register '+'. | |
6319 * Under X, this matches the standard cut/paste buffer CLIPBOARD selection. | |
6320 * It will be used for unnamed cut/pasting is 'clipboard' contains "unnamed", | |
6321 * otherwise you will need to do <"+p>. " | |
6322 * If not under X, it is synonymous with the selection register '*'. | |
6323 */ | |
6324 | |
6325 /* | |
6326 * 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
|
6327 * so that the text is still available after Vim has exited. X selections |
7 | 6328 * only exist while the owning application exists, so we write to the |
6329 * permanent (while X runs) store CUT_BUFFER0. | |
6330 * Dump the CLIPBOARD selection if we own it (it's logically the more | |
6331 * 'permanent' of the two), otherwise the PRIMARY one. | |
6332 * For now, use a hard-coded sanity limit of 1Mb of data. | |
6333 */ | |
9834
80ace3687eec
commit https://github.com/vim/vim/commit/a6b7a08ae04a3cd4d9c45c906bb7a197e2135179
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
6334 #if (defined(FEAT_X11) && defined(FEAT_CLIPBOARD)) || defined(PROTO) |
7 | 6335 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6336 x11_export_final_selection(void) |
7 | 6337 { |
6338 Display *dpy; | |
6339 char_u *str = NULL; | |
6340 long_u len = 0; | |
6341 int motion_type = -1; | |
6342 | |
6343 # ifdef FEAT_GUI | |
6344 if (gui.in_use) | |
6345 dpy = X_DISPLAY; | |
6346 else | |
6347 # endif | |
6348 # ifdef FEAT_XCLIPBOARD | |
6349 dpy = xterm_dpy; | |
6350 # else | |
6351 return; | |
6352 # endif | |
6353 | |
6354 /* Get selection to export */ | |
6355 if (clip_plus.owned) | |
6356 motion_type = clip_convert_selection(&str, &len, &clip_plus); | |
6357 else if (clip_star.owned) | |
6358 motion_type = clip_convert_selection(&str, &len, &clip_star); | |
6359 | |
6360 /* Check it's OK */ | |
6361 if (dpy != NULL && str != NULL && motion_type >= 0 | |
6362 && len < 1024*1024 && len > 0) | |
6363 { | |
1924 | 6364 #ifdef FEAT_MBYTE |
4201 | 6365 int ok = TRUE; |
6366 | |
1924 | 6367 /* The CUT_BUFFER0 is supposed to always contain latin1. Convert from |
6368 * 'enc' when it is a multi-byte encoding. When 'enc' is an 8-bit | |
6369 * encoding conversion usually doesn't work, so keep the text as-is. | |
6370 */ | |
6371 if (has_mbyte) | |
6372 { | |
6373 vimconv_T vc; | |
6374 | |
6375 vc.vc_type = CONV_NONE; | |
6376 if (convert_setup(&vc, p_enc, (char_u *)"latin1") == OK) | |
6377 { | |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2007
diff
changeset
|
6378 int intlen = len; |
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2007
diff
changeset
|
6379 char_u *conv_str; |
2007 | 6380 |
4201 | 6381 vc.vc_fail = TRUE; |
2007 | 6382 conv_str = string_convert(&vc, str, &intlen); |
6383 len = intlen; | |
1924 | 6384 if (conv_str != NULL) |
6385 { | |
6386 vim_free(str); | |
6387 str = conv_str; | |
6388 } | |
4201 | 6389 else |
6390 { | |
6391 ok = FALSE; | |
6392 } | |
1924 | 6393 convert_setup(&vc, NULL, NULL); |
6394 } | |
4201 | 6395 else |
6396 { | |
6397 ok = FALSE; | |
6398 } | |
1924 | 6399 } |
4201 | 6400 |
6401 /* Do not store the string if conversion failed. Better to use any | |
6402 * other selection than garbled text. */ | |
6403 if (ok) | |
6404 #endif | |
6405 { | |
6406 XStoreBuffer(dpy, (char *)str, (int)len, 0); | |
6407 XFlush(dpy); | |
6408 } | |
7 | 6409 } |
6410 | |
6411 vim_free(str); | |
6412 } | |
6413 #endif | |
6414 | |
6415 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6416 clip_free_selection(VimClipboard *cbd) |
7 | 6417 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6418 yankreg_T *y_ptr = y_current; |
7 | 6419 |
6420 if (cbd == &clip_plus) | |
6421 y_current = &y_regs[PLUS_REGISTER]; | |
6422 else | |
6423 y_current = &y_regs[STAR_REGISTER]; | |
6424 free_yank_all(); | |
6425 y_current->y_size = 0; | |
6426 y_current = y_ptr; | |
6427 } | |
6428 | |
6429 /* | |
6430 * Get the selected text and put it in the gui selection register '*' or '+'. | |
6431 */ | |
6432 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6433 clip_get_selection(VimClipboard *cbd) |
7 | 6434 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6435 yankreg_T *old_y_previous, *old_y_current; |
7 | 6436 pos_T old_cursor; |
6437 pos_T old_visual; | |
6438 int old_visual_mode; | |
6439 colnr_T old_curswant; | |
6440 int old_set_curswant; | |
6441 pos_T old_op_start, old_op_end; | |
6442 oparg_T oa; | |
6443 cmdarg_T ca; | |
6444 | |
6445 if (cbd->owned) | |
6446 { | |
6447 if ((cbd == &clip_plus && y_regs[PLUS_REGISTER].y_array != NULL) | |
6448 || (cbd == &clip_star && y_regs[STAR_REGISTER].y_array != NULL)) | |
6449 return; | |
6450 | |
6451 /* Get the text between clip_star.start & clip_star.end */ | |
6452 old_y_previous = y_previous; | |
6453 old_y_current = y_current; | |
6454 old_cursor = curwin->w_cursor; | |
6455 old_curswant = curwin->w_curswant; | |
6456 old_set_curswant = curwin->w_set_curswant; | |
6457 old_op_start = curbuf->b_op_start; | |
6458 old_op_end = curbuf->b_op_end; | |
6459 old_visual = VIsual; | |
6460 old_visual_mode = VIsual_mode; | |
6461 clear_oparg(&oa); | |
6462 oa.regname = (cbd == &clip_plus ? '+' : '*'); | |
6463 oa.op_type = OP_YANK; | |
6464 vim_memset(&ca, 0, sizeof(ca)); | |
6465 ca.oap = &oa; | |
6466 ca.cmdchar = 'y'; | |
6467 ca.count1 = 1; | |
6468 ca.retval = CA_NO_ADJ_OP_END; | |
6469 do_pending_operator(&ca, 0, TRUE); | |
6470 y_previous = old_y_previous; | |
6471 y_current = old_y_current; | |
6472 curwin->w_cursor = old_cursor; | |
688 | 6473 changed_cline_bef_curs(); /* need to update w_virtcol et al */ |
7 | 6474 curwin->w_curswant = old_curswant; |
6475 curwin->w_set_curswant = old_set_curswant; | |
6476 curbuf->b_op_start = old_op_start; | |
6477 curbuf->b_op_end = old_op_end; | |
6478 VIsual = old_visual; | |
6479 VIsual_mode = old_visual_mode; | |
6480 } | |
11273
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
6481 else if (!is_clipboard_needs_update()) |
7 | 6482 { |
6483 clip_free_selection(cbd); | |
6484 | |
6485 /* Try to get selected text from another window */ | |
6486 clip_gen_request_selection(cbd); | |
6487 } | |
6488 } | |
6489 | |
2896 | 6490 /* |
6491 * Convert from the GUI selection string into the '*'/'+' register. | |
6492 */ | |
7 | 6493 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6494 clip_yank_selection( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6495 int type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6496 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6497 long len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6498 VimClipboard *cbd) |
7 | 6499 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6500 yankreg_T *y_ptr; |
7 | 6501 |
6502 if (cbd == &clip_plus) | |
6503 y_ptr = &y_regs[PLUS_REGISTER]; | |
6504 else | |
6505 y_ptr = &y_regs[STAR_REGISTER]; | |
6506 | |
6507 clip_free_selection(cbd); | |
6508 | |
5798 | 6509 str_to_reg(y_ptr, type, str, len, 0L, FALSE); |
7 | 6510 } |
6511 | |
6512 /* | |
6513 * Convert the '*'/'+' register into a GUI selection string returned in *str | |
6514 * with length *len. | |
6515 * Returns the motion type, or -1 for failure. | |
6516 */ | |
6517 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6518 clip_convert_selection(char_u **str, long_u *len, VimClipboard *cbd) |
7 | 6519 { |
6520 char_u *p; | |
6521 int lnum; | |
6522 int i, j; | |
6523 int_u eolsize; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6524 yankreg_T *y_ptr; |
7 | 6525 |
6526 if (cbd == &clip_plus) | |
6527 y_ptr = &y_regs[PLUS_REGISTER]; | |
6528 else | |
6529 y_ptr = &y_regs[STAR_REGISTER]; | |
6530 | |
6531 #ifdef USE_CRNL | |
6532 eolsize = 2; | |
6533 #else | |
6534 eolsize = 1; | |
6535 #endif | |
6536 | |
6537 *str = NULL; | |
6538 *len = 0; | |
6539 if (y_ptr->y_array == NULL) | |
6540 return -1; | |
6541 | |
6542 for (i = 0; i < y_ptr->y_size; i++) | |
6543 *len += (long_u)STRLEN(y_ptr->y_array[i]) + eolsize; | |
6544 | |
6545 /* | |
6546 * Don't want newline character at end of last line if we're in MCHAR mode. | |
6547 */ | |
6548 if (y_ptr->y_type == MCHAR && *len >= eolsize) | |
6549 *len -= eolsize; | |
6550 | |
6551 p = *str = lalloc(*len + 1, TRUE); /* add one to avoid zero */ | |
6552 if (p == NULL) | |
6553 return -1; | |
6554 lnum = 0; | |
6555 for (i = 0, j = 0; i < (int)*len; i++, j++) | |
6556 { | |
6557 if (y_ptr->y_array[lnum][j] == '\n') | |
6558 p[i] = NUL; | |
6559 else if (y_ptr->y_array[lnum][j] == NUL) | |
6560 { | |
6561 #ifdef USE_CRNL | |
6562 p[i++] = '\r'; | |
6563 #endif | |
6564 #ifdef USE_CR | |
6565 p[i] = '\r'; | |
6566 #else | |
6567 p[i] = '\n'; | |
6568 #endif | |
6569 lnum++; | |
6570 j = -1; | |
6571 } | |
6572 else | |
6573 p[i] = y_ptr->y_array[lnum][j]; | |
6574 } | |
6575 return y_ptr->y_type; | |
6576 } | |
6577 | |
6578 | |
6579 /* | |
6580 * If we have written to a clipboard register, send the text to the clipboard. | |
6581 */ | |
6582 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6583 may_set_selection(void) |
7 | 6584 { |
6585 if (y_current == &(y_regs[STAR_REGISTER]) && clip_star.available) | |
6586 { | |
6587 clip_own_selection(&clip_star); | |
6588 clip_gen_set_selection(&clip_star); | |
6589 } | |
6590 else if (y_current == &(y_regs[PLUS_REGISTER]) && clip_plus.available) | |
6591 { | |
6592 clip_own_selection(&clip_plus); | |
6593 clip_gen_set_selection(&clip_plus); | |
6594 } | |
6595 } | |
6596 | |
6597 #endif /* FEAT_CLIPBOARD || PROTO */ | |
6598 | |
6599 | |
6600 #if defined(FEAT_DND) || defined(PROTO) | |
6601 /* | |
6602 * Replace the contents of the '~' register with str. | |
6603 */ | |
6604 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6605 dnd_yank_drag_data(char_u *str, long len) |
7 | 6606 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6607 yankreg_T *curr; |
7 | 6608 |
6609 curr = y_current; | |
6610 y_current = &y_regs[TILDE_REGISTER]; | |
6611 free_yank_all(); | |
5798 | 6612 str_to_reg(y_current, MCHAR, str, len, 0L, FALSE); |
7 | 6613 y_current = curr; |
6614 } | |
6615 #endif | |
6616 | |
6617 | |
6618 #if defined(FEAT_EVAL) || defined(PROTO) | |
6619 /* | |
6620 * Return the type of a register. | |
6621 * Used for getregtype() | |
6622 * Returns MAUTO for error. | |
6623 */ | |
6624 char_u | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6625 get_reg_type(int regname, long *reglen) |
7 | 6626 { |
6627 switch (regname) | |
6628 { | |
6629 case '%': /* file name */ | |
6630 case '#': /* alternate file name */ | |
6631 case '=': /* expression */ | |
6632 case ':': /* last command line */ | |
6633 case '/': /* last search-pattern */ | |
6634 case '.': /* last inserted text */ | |
6635 #ifdef FEAT_SEARCHPATH | |
6636 case Ctrl_F: /* Filename under cursor */ | |
6637 case Ctrl_P: /* Path under cursor, expand via "path" */ | |
6638 #endif | |
6639 case Ctrl_W: /* word under cursor */ | |
6640 case Ctrl_A: /* WORD (mnemonic All) under cursor */ | |
6641 case '_': /* black hole: always empty */ | |
6642 return MCHAR; | |
6643 } | |
6644 | |
6645 #ifdef FEAT_CLIPBOARD | |
6646 regname = may_get_selection(regname); | |
6647 #endif | |
6648 | |
5596 | 6649 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
|
6650 return MAUTO; |
5596 | 6651 |
7 | 6652 get_yank_register(regname, FALSE); |
6653 | |
6654 if (y_current->y_array != NULL) | |
6655 { | |
6656 if (reglen != NULL && y_current->y_type == MBLOCK) | |
6657 *reglen = y_current->y_width; | |
6658 return y_current->y_type; | |
6659 } | |
6660 return MAUTO; | |
6661 } | |
6662 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
6663 static char_u *getreg_wrap_one_line(char_u *s, int flags); |
5796 | 6664 |
6665 /* | |
6666 * When "flags" has GREG_LIST return a list with text "s". | |
6667 * Otherwise just return "s". | |
6668 */ | |
6669 static char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6670 getreg_wrap_one_line(char_u *s, int flags) |
5796 | 6671 { |
6672 if (flags & GREG_LIST) | |
6673 { | |
6674 list_T *list = list_alloc(); | |
6675 | |
6676 if (list != NULL) | |
6677 { | |
6678 if (list_append_string(list, NULL, -1) == FAIL) | |
6679 { | |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8690
diff
changeset
|
6680 list_free(list); |
5796 | 6681 return NULL; |
6682 } | |
6683 list->lv_first->li_tv.vval.v_string = s; | |
6684 } | |
6685 return (char_u *)list; | |
6686 } | |
6687 return s; | |
6688 } | |
6689 | |
7 | 6690 /* |
6691 * Return the contents of a register as a single allocated string. | |
6692 * Used for "@r" in expressions and for getreg(). | |
6693 * Returns NULL for error. | |
5796 | 6694 * Flags: |
6695 * GREG_NO_EXPR Do not allow expression register | |
6696 * GREG_EXPR_SRC For the expression register: return expression itself, | |
6697 * not the result of its evaluation. | |
6698 * GREG_LIST Return a list of lines in place of a single string. | |
7 | 6699 */ |
6700 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6701 get_reg_contents(int regname, int flags) |
7 | 6702 { |
6703 long i; | |
6704 char_u *retval; | |
6705 int allocated; | |
6706 long len; | |
6707 | |
6708 /* Don't allow using an expression register inside an expression */ | |
6709 if (regname == '=') | |
6710 { | |
5796 | 6711 if (flags & GREG_NO_EXPR) |
6712 return NULL; | |
6713 if (flags & GREG_EXPR_SRC) | |
6714 return getreg_wrap_one_line(get_expr_line_src(), flags); | |
6715 return getreg_wrap_one_line(get_expr_line(), flags); | |
7 | 6716 } |
6717 | |
6718 if (regname == '@') /* "@@" is used for unnamed register */ | |
6719 regname = '"'; | |
6720 | |
6721 /* check for valid regname */ | |
6722 if (regname != NUL && !valid_yank_reg(regname, FALSE)) | |
6723 return NULL; | |
6724 | |
6725 #ifdef FEAT_CLIPBOARD | |
6726 regname = may_get_selection(regname); | |
6727 #endif | |
6728 | |
6729 if (get_spec_reg(regname, &retval, &allocated, FALSE)) | |
6730 { | |
6731 if (retval == NULL) | |
6732 return NULL; | |
5796 | 6733 if (allocated) |
6734 return getreg_wrap_one_line(retval, flags); | |
6735 return getreg_wrap_one_line(vim_strsave(retval), flags); | |
7 | 6736 } |
6737 | |
6738 get_yank_register(regname, FALSE); | |
6739 if (y_current->y_array == NULL) | |
6740 return NULL; | |
6741 | |
5796 | 6742 if (flags & GREG_LIST) |
6743 { | |
6744 list_T *list = list_alloc(); | |
6745 int error = FALSE; | |
6746 | |
6747 if (list == NULL) | |
6748 return NULL; | |
6749 for (i = 0; i < y_current->y_size; ++i) | |
6750 if (list_append_string(list, y_current->y_array[i], -1) == FAIL) | |
6751 error = TRUE; | |
6752 if (error) | |
6753 { | |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8690
diff
changeset
|
6754 list_free(list); |
5796 | 6755 return NULL; |
6756 } | |
6757 return (char_u *)list; | |
6758 } | |
6759 | |
7 | 6760 /* |
6761 * Compute length of resulting string. | |
6762 */ | |
6763 len = 0; | |
6764 for (i = 0; i < y_current->y_size; ++i) | |
6765 { | |
6766 len += (long)STRLEN(y_current->y_array[i]); | |
6767 /* | |
6768 * Insert a newline between lines and after last line if | |
6769 * y_type is MLINE. | |
6770 */ | |
6771 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | |
6772 ++len; | |
6773 } | |
6774 | |
6775 retval = lalloc(len + 1, TRUE); | |
6776 | |
6777 /* | |
6778 * Copy the lines of the yank register into the string. | |
6779 */ | |
6780 if (retval != NULL) | |
6781 { | |
6782 len = 0; | |
6783 for (i = 0; i < y_current->y_size; ++i) | |
6784 { | |
6785 STRCPY(retval + len, y_current->y_array[i]); | |
6786 len += (long)STRLEN(retval + len); | |
6787 | |
6788 /* | |
6789 * Insert a NL between lines and after the last line if y_type is | |
6790 * MLINE. | |
6791 */ | |
6792 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | |
6793 retval[len++] = '\n'; | |
6794 } | |
6795 retval[len] = NUL; | |
6796 } | |
6797 | |
6798 return retval; | |
6799 } | |
6800 | |
5798 | 6801 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6802 init_write_reg( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6803 int name, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6804 yankreg_T **old_y_previous, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6805 yankreg_T **old_y_current, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6806 int must_append, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6807 int *yank_type UNUSED) |
5798 | 6808 { |
6809 if (!valid_yank_reg(name, TRUE)) /* check for valid reg name */ | |
6810 { | |
6811 emsg_invreg(name); | |
6812 return FAIL; | |
6813 } | |
6814 | |
6815 /* Don't want to change the current (unnamed) register */ | |
6816 *old_y_previous = y_previous; | |
6817 *old_y_current = y_current; | |
6818 | |
6819 get_yank_register(name, TRUE); | |
6820 if (!y_append && !must_append) | |
6821 free_yank_all(); | |
6822 return OK; | |
6823 } | |
6824 | |
6825 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6826 finish_write_reg( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6827 int name, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6828 yankreg_T *old_y_previous, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6829 yankreg_T *old_y_current) |
5798 | 6830 { |
6831 # ifdef FEAT_CLIPBOARD | |
6832 /* Send text of clipboard register to the clipboard. */ | |
6833 may_set_selection(); | |
6834 # endif | |
6835 | |
6836 /* ':let @" = "val"' should change the meaning of the "" register */ | |
6837 if (name != '"') | |
6838 y_previous = old_y_previous; | |
6839 y_current = old_y_current; | |
6840 } | |
6841 | |
7 | 6842 /* |
6843 * Store string "str" in register "name". | |
6844 * "maxlen" is the maximum number of bytes to use, -1 for all bytes. | |
6845 * If "must_append" is TRUE, always append to the register. Otherwise append | |
6846 * if "name" is an uppercase letter. | |
6847 * Note: "maxlen" and "must_append" don't work for the "/" register. | |
6848 * Careful: 'str' is modified, you may have to use a copy! | |
6849 * If "str" ends in '\n' or '\r', use linewise, otherwise use characterwise. | |
6850 */ | |
6851 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6852 write_reg_contents( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6853 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6854 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6855 int maxlen, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6856 int must_append) |
7 | 6857 { |
6858 write_reg_contents_ex(name, str, maxlen, must_append, MAUTO, 0L); | |
6859 } | |
6860 | |
6861 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6862 write_reg_contents_lst( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6863 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6864 char_u **strings, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6865 int maxlen UNUSED, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6866 int must_append, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6867 int yank_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6868 long block_len) |
5798 | 6869 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6870 yankreg_T *old_y_previous, *old_y_current; |
5798 | 6871 |
6872 if (name == '/' | |
6873 #ifdef FEAT_EVAL | |
6874 || name == '=' | |
6875 #endif | |
6876 ) | |
6877 { | |
6878 char_u *s; | |
6879 | |
6880 if (strings[0] == NULL) | |
6881 s = (char_u *)""; | |
6882 else if (strings[1] != NULL) | |
6883 { | |
6884 EMSG(_("E883: search pattern and expression register may not " | |
6885 "contain two or more lines")); | |
6886 return; | |
6887 } | |
6888 else | |
6889 s = strings[0]; | |
6890 write_reg_contents_ex(name, s, -1, must_append, yank_type, block_len); | |
6891 return; | |
6892 } | |
6893 | |
6894 if (name == '_') /* black hole: nothing to do */ | |
6895 return; | |
6896 | |
6897 if (init_write_reg(name, &old_y_previous, &old_y_current, must_append, | |
6898 &yank_type) == FAIL) | |
6899 return; | |
6900 | |
6901 str_to_reg(y_current, yank_type, (char_u *) strings, -1, block_len, TRUE); | |
6902 | |
6903 finish_write_reg(name, old_y_previous, old_y_current); | |
6904 } | |
6905 | |
6906 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6907 write_reg_contents_ex( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6908 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6909 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6910 int maxlen, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6911 int must_append, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6912 int yank_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6913 long block_len) |
7 | 6914 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6915 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
|
6916 long len; |
7 | 6917 |
336 | 6918 if (maxlen >= 0) |
6919 len = maxlen; | |
6920 else | |
6921 len = (long)STRLEN(str); | |
6922 | |
7 | 6923 /* Special case: '/' search pattern */ |
6924 if (name == '/') | |
6925 { | |
6926 set_last_search_pat(str, RE_SEARCH, TRUE, TRUE); | |
6927 return; | |
6928 } | |
6929 | |
6557 | 6930 if (name == '#') |
6931 { | |
6932 buf_T *buf; | |
6933 | |
6934 if (VIM_ISDIGIT(*str)) | |
6935 { | |
6936 int num = atoi((char *)str); | |
6937 | |
6938 buf = buflist_findnr(num); | |
6939 if (buf == NULL) | |
6940 EMSGN(_(e_nobufnr), (long)num); | |
6941 } | |
6942 else | |
6943 buf = buflist_findnr(buflist_findpat(str, str + STRLEN(str), | |
6944 TRUE, FALSE, FALSE)); | |
6945 if (buf == NULL) | |
6946 return; | |
6947 curwin->w_alt_fnum = buf->b_fnum; | |
6948 return; | |
6949 } | |
6950 | |
336 | 6951 #ifdef FEAT_EVAL |
6952 if (name == '=') | |
6953 { | |
6954 char_u *p, *s; | |
6955 | |
6956 p = vim_strnsave(str, (int)len); | |
6957 if (p == NULL) | |
6958 return; | |
6959 if (must_append) | |
6960 { | |
6961 s = concat_str(get_expr_line_src(), p); | |
6962 vim_free(p); | |
6963 p = s; | |
6964 } | |
6965 set_expr_line(p); | |
6966 return; | |
6967 } | |
6968 #endif | |
6969 | |
7 | 6970 if (name == '_') /* black hole: nothing to do */ |
6971 return; | |
6972 | |
5798 | 6973 if (init_write_reg(name, &old_y_previous, &old_y_current, must_append, |
6974 &yank_type) == FAIL) | |
6975 return; | |
6976 | |
6977 str_to_reg(y_current, yank_type, str, len, block_len, FALSE); | |
6978 | |
6979 finish_write_reg(name, old_y_previous, old_y_current); | |
7 | 6980 } |
6981 #endif /* FEAT_EVAL */ | |
6982 | |
6983 #if defined(FEAT_CLIPBOARD) || defined(FEAT_EVAL) | |
6984 /* | |
6985 * Put a string into a register. When the register is not empty, the string | |
6986 * is appended. | |
6987 */ | |
6988 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6989 str_to_reg( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6990 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
|
6991 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
|
6992 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
|
6993 long len, /* length of string */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6994 long blocklen, /* width of Visual block */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6995 int str_list) /* TRUE if str is char_u ** */ |
7 | 6996 { |
2896 | 6997 int type; /* MCHAR, MLINE or MBLOCK */ |
7 | 6998 int lnum; |
6999 long start; | |
7000 long i; | |
7001 int extra; | |
7002 int newlines; /* number of lines added */ | |
7003 int extraline = 0; /* extra line at the end */ | |
7004 int append = FALSE; /* append to last line in register */ | |
7005 char_u *s; | |
5798 | 7006 char_u **ss; |
7 | 7007 char_u **pp; |
7008 long maxlen; | |
7009 | |
2000 | 7010 if (y_ptr->y_array == NULL) /* NULL means empty register */ |
7 | 7011 y_ptr->y_size = 0; |
7012 | |
2896 | 7013 if (yank_type == MAUTO) |
5798 | 7014 type = ((str_list || (len > 0 && (str[len - 1] == NL |
7015 || str[len - 1] == CAR))) | |
2896 | 7016 ? MLINE : MCHAR); |
7017 else | |
7018 type = yank_type; | |
7019 | |
7 | 7020 /* |
7021 * Count the number of lines within the string | |
7022 */ | |
7023 newlines = 0; | |
5798 | 7024 if (str_list) |
7025 { | |
7026 for (ss = (char_u **) str; *ss != NULL; ++ss) | |
7 | 7027 ++newlines; |
5798 | 7028 } |
7029 else | |
7030 { | |
7031 for (i = 0; i < len; i++) | |
7032 if (str[i] == '\n') | |
7033 ++newlines; | |
7034 if (type == MCHAR || len == 0 || str[len - 1] != '\n') | |
7035 { | |
7036 extraline = 1; | |
7037 ++newlines; /* count extra newline at the end */ | |
7038 } | |
7039 if (y_ptr->y_size > 0 && y_ptr->y_type == MCHAR) | |
7040 { | |
7041 append = TRUE; | |
7042 --newlines; /* uncount newline when appending first line */ | |
7043 } | |
7 | 7044 } |
7045 | |
6807 | 7046 /* Without any lines make the register empty. */ |
7047 if (y_ptr->y_size + newlines == 0) | |
7048 { | |
7049 vim_free(y_ptr->y_array); | |
7050 y_ptr->y_array = NULL; | |
7051 return; | |
7052 } | |
7053 | |
7 | 7054 /* |
7055 * Allocate an array to hold the pointers to the new register lines. | |
7056 * If the register was not empty, move the existing lines to the new array. | |
7057 */ | |
7058 pp = (char_u **)lalloc_clear((y_ptr->y_size + newlines) | |
7059 * sizeof(char_u *), TRUE); | |
7060 if (pp == NULL) /* out of memory */ | |
7061 return; | |
7062 for (lnum = 0; lnum < y_ptr->y_size; ++lnum) | |
7063 pp[lnum] = y_ptr->y_array[lnum]; | |
7064 vim_free(y_ptr->y_array); | |
7065 y_ptr->y_array = pp; | |
7066 maxlen = 0; | |
7067 | |
7068 /* | |
7069 * Find the end of each line and save it into the array. | |
7070 */ | |
5798 | 7071 if (str_list) |
7072 { | |
7073 for (ss = (char_u **) str; *ss != NULL; ++ss, ++lnum) | |
7 | 7074 { |
5856 | 7075 i = (long)STRLEN(*ss); |
5798 | 7076 pp[lnum] = vim_strnsave(*ss, i); |
7077 if (i > maxlen) | |
7078 maxlen = i; | |
7 | 7079 } |
5798 | 7080 } |
7081 else | |
7082 { | |
7083 for (start = 0; start < len + extraline; start += i + 1) | |
7 | 7084 { |
5798 | 7085 for (i = start; i < len; ++i) /* find the end of the line */ |
7086 if (str[i] == '\n') | |
7087 break; | |
7088 i -= start; /* i is now length of line */ | |
7089 if (i > maxlen) | |
7090 maxlen = i; | |
7091 if (append) | |
7092 { | |
7093 --lnum; | |
7094 extra = (int)STRLEN(y_ptr->y_array[lnum]); | |
7095 } | |
7096 else | |
7097 extra = 0; | |
7098 s = alloc((unsigned)(i + extra + 1)); | |
7099 if (s == NULL) | |
7100 break; | |
7101 if (extra) | |
7102 mch_memmove(s, y_ptr->y_array[lnum], (size_t)extra); | |
7103 if (append) | |
7104 vim_free(y_ptr->y_array[lnum]); | |
7105 if (i) | |
7106 mch_memmove(s + extra, str + start, (size_t)i); | |
7107 extra += i; | |
7108 s[extra] = NUL; | |
7109 y_ptr->y_array[lnum++] = s; | |
7110 while (--extra >= 0) | |
7111 { | |
7112 if (*s == NUL) | |
7113 *s = '\n'; /* replace NUL with newline */ | |
7114 ++s; | |
7115 } | |
7116 append = FALSE; /* only first line is appended */ | |
7 | 7117 } |
7118 } | |
7119 y_ptr->y_type = type; | |
7120 y_ptr->y_size = lnum; | |
7121 if (type == MBLOCK) | |
7122 y_ptr->y_width = (blocklen < 0 ? maxlen - 1 : blocklen); | |
7123 else | |
7124 y_ptr->y_width = 0; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7125 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7126 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
|
7127 #endif |
7 | 7128 } |
7129 #endif /* FEAT_CLIPBOARD || FEAT_EVAL || PROTO */ | |
7130 | |
7131 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7132 clear_oparg(oparg_T *oap) |
7 | 7133 { |
7134 vim_memset(oap, 0, sizeof(oparg_T)); | |
7135 } | |
7136 | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7137 static varnumber_T line_count_info(char_u *line, varnumber_T *wc, varnumber_T *cc, varnumber_T limit, int eol_size); |
7 | 7138 |
7139 /* | |
161 | 7140 * Count the number of bytes, characters and "words" in a line. |
7 | 7141 * |
7142 * "Words" are counted by looking for boundaries between non-space and | |
7143 * space characters. (it seems to produce results that match 'wc'.) | |
7144 * | |
161 | 7145 * Return value is byte count; word count for the line is added to "*wc". |
7146 * Char count is added to "*cc". | |
7 | 7147 * |
7148 * The function will only examine the first "limit" characters in the | |
7149 * line, stopping if it encounters an end-of-line (NUL byte). In that | |
7150 * case, eol_size will be added to the character count to account for | |
7151 * the size of the EOL character. | |
7152 */ | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7153 static varnumber_T |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7154 line_count_info( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7155 char_u *line, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7156 varnumber_T *wc, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7157 varnumber_T *cc, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7158 varnumber_T limit, |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7159 int eol_size) |
7 | 7160 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7161 varnumber_T i; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7162 varnumber_T words = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7163 varnumber_T chars = 0; |
7 | 7164 int is_word = 0; |
7165 | |
3626 | 7166 for (i = 0; i < limit && line[i] != NUL; ) |
7 | 7167 { |
7168 if (is_word) | |
7169 { | |
7170 if (vim_isspace(line[i])) | |
7171 { | |
7172 words++; | |
7173 is_word = 0; | |
7174 } | |
7175 } | |
7176 else if (!vim_isspace(line[i])) | |
7177 is_word = 1; | |
161 | 7178 ++chars; |
7179 #ifdef FEAT_MBYTE | |
474 | 7180 i += (*mb_ptr2len)(line + i); |
161 | 7181 #else |
7182 ++i; | |
7183 #endif | |
7 | 7184 } |
7185 | |
7186 if (is_word) | |
7187 words++; | |
7188 *wc += words; | |
7189 | |
7190 /* Add eol_size if the end of line was reached before hitting limit. */ | |
2996 | 7191 if (i < limit && line[i] == NUL) |
161 | 7192 { |
7 | 7193 i += eol_size; |
161 | 7194 chars += eol_size; |
7195 } | |
7196 *cc += chars; | |
7 | 7197 return i; |
7198 } | |
7199 | |
7200 /* | |
7201 * Give some info about the position of the cursor (for "g CTRL-G"). | |
7202 * In Visual mode, give some info about the selected region. (In this case, | |
7203 * 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
|
7204 * When "dict" is not NULL store the info there instead of showing it. |
7 | 7205 */ |
7206 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7207 cursor_pos_info(dict_T *dict) |
7 | 7208 { |
7209 char_u *p; | |
274 | 7210 char_u buf1[50]; |
7211 char_u buf2[40]; | |
7 | 7212 linenr_T lnum; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7213 varnumber_T byte_count = 0; |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7214 #ifdef FEAT_MBYTE |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7215 varnumber_T bom_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7216 #endif |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7217 varnumber_T byte_count_cursor = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7218 varnumber_T char_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7219 varnumber_T char_count_cursor = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7220 varnumber_T word_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7221 varnumber_T word_count_cursor = 0; |
7 | 7222 int eol_size; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7223 varnumber_T last_check = 100000L; |
7 | 7224 long line_count_selected = 0; |
7225 pos_T min_pos, max_pos; | |
7226 oparg_T oparg; | |
7227 struct block_def bd; | |
7228 | |
7229 /* | |
7230 * Compute the length of the file in characters. | |
7231 */ | |
7232 if (curbuf->b_ml.ml_flags & ML_EMPTY) | |
7233 { | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7234 if (dict == NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7235 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7236 MSG(_(no_lines_msg)); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7237 return; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7238 } |
7 | 7239 } |
7240 else | |
7241 { | |
7242 if (get_fileformat(curbuf) == EOL_DOS) | |
7243 eol_size = 2; | |
7244 else | |
7245 eol_size = 1; | |
7246 | |
7247 if (VIsual_active) | |
7248 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
7249 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 7250 { |
7251 min_pos = VIsual; | |
7252 max_pos = curwin->w_cursor; | |
7253 } | |
7254 else | |
7255 { | |
7256 min_pos = curwin->w_cursor; | |
7257 max_pos = VIsual; | |
7258 } | |
7259 if (*p_sel == 'e' && max_pos.col > 0) | |
7260 --max_pos.col; | |
7261 | |
7262 if (VIsual_mode == Ctrl_V) | |
7263 { | |
1866 | 7264 #ifdef FEAT_LINEBREAK |
7265 char_u * saved_sbr = p_sbr; | |
7266 | |
7267 /* Make 'sbr' empty for a moment to get the correct size. */ | |
7268 p_sbr = empty_option; | |
7269 #endif | |
7 | 7270 oparg.is_VIsual = 1; |
7271 oparg.block_mode = TRUE; | |
7272 oparg.op_type = OP_NOP; | |
7273 getvcols(curwin, &min_pos, &max_pos, | |
688 | 7274 &oparg.start_vcol, &oparg.end_vcol); |
1866 | 7275 #ifdef FEAT_LINEBREAK |
7276 p_sbr = saved_sbr; | |
7277 #endif | |
688 | 7278 if (curwin->w_curswant == MAXCOL) |
7279 oparg.end_vcol = MAXCOL; | |
7 | 7280 /* Swap the start, end vcol if needed */ |
7281 if (oparg.end_vcol < oparg.start_vcol) | |
7282 { | |
7283 oparg.end_vcol += oparg.start_vcol; | |
7284 oparg.start_vcol = oparg.end_vcol - oparg.start_vcol; | |
7285 oparg.end_vcol -= oparg.start_vcol; | |
7286 } | |
7287 } | |
7288 line_count_selected = max_pos.lnum - min_pos.lnum + 1; | |
7289 } | |
7290 | |
7291 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) | |
7292 { | |
7293 /* Check for a CTRL-C every 100000 characters. */ | |
161 | 7294 if (byte_count > last_check) |
7 | 7295 { |
7296 ui_breakcheck(); | |
7297 if (got_int) | |
7298 return; | |
161 | 7299 last_check = byte_count + 100000L; |
7 | 7300 } |
7301 | |
7302 /* Do extra processing for VIsual mode. */ | |
7303 if (VIsual_active | |
7304 && lnum >= min_pos.lnum && lnum <= max_pos.lnum) | |
7305 { | |
45 | 7306 char_u *s = NULL; |
7307 long len = 0L; | |
7308 | |
7 | 7309 switch (VIsual_mode) |
7310 { | |
7311 case Ctrl_V: | |
5735 | 7312 #ifdef FEAT_VIRTUALEDIT |
7 | 7313 virtual_op = virtual_active(); |
5735 | 7314 #endif |
7 | 7315 block_prep(&oparg, &bd, lnum, 0); |
5735 | 7316 #ifdef FEAT_VIRTUALEDIT |
7 | 7317 virtual_op = MAYBE; |
5735 | 7318 #endif |
45 | 7319 s = bd.textstart; |
7320 len = (long)bd.textlen; | |
7 | 7321 break; |
7322 case 'V': | |
45 | 7323 s = ml_get(lnum); |
7324 len = MAXCOL; | |
7 | 7325 break; |
7326 case 'v': | |
7327 { | |
7328 colnr_T start_col = (lnum == min_pos.lnum) | |
7329 ? min_pos.col : 0; | |
7330 colnr_T end_col = (lnum == max_pos.lnum) | |
7331 ? max_pos.col - start_col + 1 : MAXCOL; | |
7332 | |
45 | 7333 s = ml_get(lnum) + start_col; |
7334 len = end_col; | |
7 | 7335 } |
7336 break; | |
7337 } | |
45 | 7338 if (s != NULL) |
7339 { | |
161 | 7340 byte_count_cursor += line_count_info(s, &word_count_cursor, |
7341 &char_count_cursor, len, eol_size); | |
45 | 7342 if (lnum == curbuf->b_ml.ml_line_count |
7343 && !curbuf->b_p_eol | |
6933 | 7344 && (curbuf->b_p_bin || !curbuf->b_p_fixeol) |
50 | 7345 && (long)STRLEN(s) < len) |
161 | 7346 byte_count_cursor -= eol_size; |
45 | 7347 } |
7 | 7348 } |
7349 else | |
7350 { | |
7351 /* In non-visual mode, check for the line the cursor is on */ | |
7352 if (lnum == curwin->w_cursor.lnum) | |
7353 { | |
7354 word_count_cursor += word_count; | |
161 | 7355 char_count_cursor += char_count; |
7356 byte_count_cursor = byte_count + | |
7357 line_count_info(ml_get(lnum), | |
7358 &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
|
7359 (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
|
7360 eol_size); |
7 | 7361 } |
7362 } | |
7363 /* Add to the running totals */ | |
161 | 7364 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
|
7365 &char_count, (varnumber_T)MAXCOL, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7366 eol_size); |
7 | 7367 } |
7368 | |
7369 /* Correction for when last line doesn't have an EOL. */ | |
6933 | 7370 if (!curbuf->b_p_eol && (curbuf->b_p_bin || !curbuf->b_p_fixeol)) |
161 | 7371 byte_count -= eol_size; |
7 | 7372 |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7373 if (dict == NULL) |
7 | 7374 { |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7375 if (VIsual_active) |
7 | 7376 { |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7377 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
|
7378 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7379 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
|
7380 &max_pos.col); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7381 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
|
7382 (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
|
7383 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7384 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7385 buf1[0] = NUL; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7386 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7387 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
|
7388 && char_count == byte_count) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7389 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7390 _("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
|
7391 buf1, line_count_selected, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7392 (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
|
7393 word_count_cursor, word_count, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7394 byte_count_cursor, byte_count); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7395 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7396 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7397 _("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
|
7398 buf1, line_count_selected, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7399 (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
|
7400 word_count_cursor, word_count, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7401 char_count_cursor, char_count, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7402 byte_count_cursor, byte_count); |
7 | 7403 } |
7404 else | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7405 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7406 p = ml_get_curline(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7407 validate_virtcol(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7408 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
|
7409 (int)curwin->w_virtcol + 1); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7410 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
|
7411 linetabsize(p)); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7412 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7413 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
|
7414 && char_count == byte_count) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7415 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7416 _("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
|
7417 (char *)buf1, (char *)buf2, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7418 (long)curwin->w_cursor.lnum, |
7 | 7419 (long)curbuf->b_ml.ml_line_count, |
7420 word_count_cursor, word_count, | |
161 | 7421 byte_count_cursor, byte_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7422 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7423 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7424 _("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
|
7425 (char *)buf1, (char *)buf2, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7426 (long)curwin->w_cursor.lnum, |
161 | 7427 (long)curbuf->b_ml.ml_line_count, |
7428 word_count_cursor, word_count, | |
7429 char_count_cursor, char_count, | |
7430 byte_count_cursor, byte_count); | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7431 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7432 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7433 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7434 #ifdef FEAT_MBYTE |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7435 bom_count = bomb_size(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7436 if (bom_count > 0) |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7437 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
|
7438 _("(+%ld for BOM)"), bom_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7439 #endif |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7440 if (dict == NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7441 { |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7442 /* 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
|
7443 p = p_shm; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7444 p_shm = (char_u *)""; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7445 msg(IObuff); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7446 p_shm = p; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7447 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7448 } |
7484
1fe988587423
commit https://github.com/vim/vim/commit/718272a7e13c71095ce07eb3b3d5e1f9790a6991
Christian Brabandt <cb@256bit.org>
parents:
7480
diff
changeset
|
7449 #if defined(FEAT_EVAL) |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7450 if (dict != NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7451 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7452 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
|
7453 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
|
7454 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
|
7455 # ifdef FEAT_MBYTE |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7456 + bom_count |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7457 # endif |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7458 , NULL); |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7459 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
|
7460 byte_count_cursor, NULL); |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7461 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
|
7462 char_count_cursor, NULL); |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7463 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
|
7464 word_count_cursor, NULL); |
7 | 7465 } |
7484
1fe988587423
commit https://github.com/vim/vim/commit/718272a7e13c71095ce07eb3b3d5e1f9790a6991
Christian Brabandt <cb@256bit.org>
parents:
7480
diff
changeset
|
7466 #endif |
7 | 7467 } |