Mercurial > vim
comparison src/misc2.c @ 15636:6f1c7e9a6393 v8.1.0826
patch 8.1.0826: too many #ifdefs
commit https://github.com/vim/vim/commit/29ddebef4038d2d2b3bc9d8d3b0109f4046d6fbf
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 26 17:28:26 2019 +0100
patch 8.1.0826: too many #ifdefs
Problem: Too many #ifdefs.
Solution: Graduate FEAT_VIRTUALEDIT. Adds about 10Kbyte to the code.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 26 Jan 2019 17:30:15 +0100 |
parents | 536dd2bc5ac9 |
children | 0a4dfbb312ce |
comparison
equal
deleted
inserted
replaced
15635:c51d2a06f5f9 | 15636:6f1c7e9a6393 |
---|---|
14 | 14 |
15 static char_u *username = NULL; /* cached result of mch_get_user_name() */ | 15 static char_u *username = NULL; /* cached result of mch_get_user_name() */ |
16 | 16 |
17 static char_u *ff_expand_buffer = NULL; /* used for expanding filenames */ | 17 static char_u *ff_expand_buffer = NULL; /* used for expanding filenames */ |
18 | 18 |
19 #if defined(FEAT_VIRTUALEDIT) || defined(PROTO) | |
20 static int coladvance2(pos_T *pos, int addspaces, int finetune, colnr_T wcol); | 19 static int coladvance2(pos_T *pos, int addspaces, int finetune, colnr_T wcol); |
21 | 20 |
22 /* | 21 /* |
23 * Return TRUE if in the current mode we need to use virtual. | 22 * Return TRUE if in the current mode we need to use virtual. |
24 */ | 23 */ |
65 curwin->w_valid |= VALID_VIRTCOL; | 64 curwin->w_valid |= VALID_VIRTCOL; |
66 curwin->w_virtcol = wcol; | 65 curwin->w_virtcol = wcol; |
67 } | 66 } |
68 return rc; | 67 return rc; |
69 } | 68 } |
70 #endif | |
71 | 69 |
72 /* | 70 /* |
73 * Get the screen position of character col with a coladd in the cursor line. | 71 * Get the screen position of character col with a coladd in the cursor line. |
74 */ | 72 */ |
75 int | 73 int |
78 colnr_T x; | 76 colnr_T x; |
79 pos_T pos; | 77 pos_T pos; |
80 | 78 |
81 pos.lnum = curwin->w_cursor.lnum; | 79 pos.lnum = curwin->w_cursor.lnum; |
82 pos.col = col; | 80 pos.col = col; |
83 #ifdef FEAT_VIRTUALEDIT | |
84 pos.coladd = coladd; | 81 pos.coladd = coladd; |
85 #endif | |
86 getvvcol(curwin, &pos, &x, NULL, NULL); | 82 getvvcol(curwin, &pos, &x, NULL, NULL); |
87 return (int)x; | 83 return (int)x; |
88 } | 84 } |
89 | 85 |
90 /* | 86 /* |
117 * return OK if desired column is reached, FAIL if not | 113 * return OK if desired column is reached, FAIL if not |
118 */ | 114 */ |
119 int | 115 int |
120 getvpos(pos_T *pos, colnr_T wcol) | 116 getvpos(pos_T *pos, colnr_T wcol) |
121 { | 117 { |
122 #ifdef FEAT_VIRTUALEDIT | |
123 return coladvance2(pos, FALSE, virtual_active(), wcol); | 118 return coladvance2(pos, FALSE, virtual_active(), wcol); |
124 } | 119 } |
125 | 120 |
126 static int | 121 static int |
127 coladvance2( | 122 coladvance2( |
128 pos_T *pos, | 123 pos_T *pos, |
129 int addspaces, /* change the text to achieve our goal? */ | 124 int addspaces, /* change the text to achieve our goal? */ |
130 int finetune, /* change char offset for the exact column */ | 125 int finetune, /* change char offset for the exact column */ |
131 colnr_T wcol) /* column to move to */ | 126 colnr_T wcol) /* column to move to */ |
132 { | 127 { |
133 #endif | |
134 int idx; | 128 int idx; |
135 char_u *ptr; | 129 char_u *ptr; |
136 char_u *line; | 130 char_u *line; |
137 colnr_T col = 0; | 131 colnr_T col = 0; |
138 int csize = 0; | 132 int csize = 0; |
142 #endif | 136 #endif |
143 | 137 |
144 one_more = (State & INSERT) | 138 one_more = (State & INSERT) |
145 || restart_edit != NUL | 139 || restart_edit != NUL |
146 || (VIsual_active && *p_sel != 'o') | 140 || (VIsual_active && *p_sel != 'o') |
147 #ifdef FEAT_VIRTUALEDIT | 141 || ((ve_flags & VE_ONEMORE) && wcol < MAXCOL) ; |
148 || ((ve_flags & VE_ONEMORE) && wcol < MAXCOL) | |
149 #endif | |
150 ; | |
151 line = ml_get_buf(curbuf, pos->lnum, FALSE); | 142 line = ml_get_buf(curbuf, pos->lnum, FALSE); |
152 | 143 |
153 if (wcol >= MAXCOL) | 144 if (wcol >= MAXCOL) |
154 { | 145 { |
155 idx = (int)STRLEN(line) - 1 + one_more; | 146 idx = (int)STRLEN(line) - 1 + one_more; |
156 col = wcol; | 147 col = wcol; |
157 | 148 |
158 #ifdef FEAT_VIRTUALEDIT | |
159 if ((addspaces || finetune) && !VIsual_active) | 149 if ((addspaces || finetune) && !VIsual_active) |
160 { | 150 { |
161 curwin->w_curswant = linetabsize(line) + one_more; | 151 curwin->w_curswant = linetabsize(line) + one_more; |
162 if (curwin->w_curswant > 0) | 152 if (curwin->w_curswant > 0) |
163 --curwin->w_curswant; | 153 --curwin->w_curswant; |
164 } | 154 } |
165 #endif | |
166 } | 155 } |
167 else | 156 else |
168 { | 157 { |
169 #ifdef FEAT_VIRTUALEDIT | |
170 int width = curwin->w_width - win_col_off(curwin); | 158 int width = curwin->w_width - win_col_off(curwin); |
171 | 159 |
172 if (finetune | 160 if (finetune |
173 && curwin->w_p_wrap | 161 && curwin->w_p_wrap |
174 && curwin->w_width != 0 | 162 && curwin->w_width != 0 |
186 * the last character (like what happens when typing and | 174 * the last character (like what happens when typing and |
187 * reaching the right window edge). */ | 175 * reaching the right window edge). */ |
188 wcol = (csize / width + 1) * width - 1; | 176 wcol = (csize / width + 1) * width - 1; |
189 } | 177 } |
190 } | 178 } |
191 #endif | |
192 | 179 |
193 ptr = line; | 180 ptr = line; |
194 while (col <= wcol && *ptr != NUL) | 181 while (col <= wcol && *ptr != NUL) |
195 { | 182 { |
196 /* Count a tab for what it's worth (if list mode not on) */ | 183 /* Count a tab for what it's worth (if list mode not on) */ |
217 csize -= head; | 204 csize -= head; |
218 # endif | 205 # endif |
219 col -= csize; | 206 col -= csize; |
220 } | 207 } |
221 | 208 |
222 #ifdef FEAT_VIRTUALEDIT | |
223 if (virtual_active() | 209 if (virtual_active() |
224 && addspaces | 210 && addspaces |
225 && ((col != wcol && col != wcol + 1) || csize > 1)) | 211 && ((col != wcol && col != wcol + 1) || csize > 1)) |
226 { | 212 { |
227 /* 'virtualedit' is set: The difference between wcol and col is | 213 /* 'virtualedit' is set: The difference between wcol and col is |
281 changed_bytes(pos->lnum, idx); | 267 changed_bytes(pos->lnum, idx); |
282 idx += (csize - 1 + correct); | 268 idx += (csize - 1 + correct); |
283 col += correct; | 269 col += correct; |
284 } | 270 } |
285 } | 271 } |
286 #endif | |
287 } | 272 } |
288 | 273 |
289 if (idx < 0) | 274 if (idx < 0) |
290 pos->col = 0; | 275 pos->col = 0; |
291 else | 276 else |
292 pos->col = idx; | 277 pos->col = idx; |
293 | 278 |
294 #ifdef FEAT_VIRTUALEDIT | |
295 pos->coladd = 0; | 279 pos->coladd = 0; |
296 | 280 |
297 if (finetune) | 281 if (finetune) |
298 { | 282 { |
299 if (wcol == MAXCOL) | 283 if (wcol == MAXCOL) |
316 pos->coladd = b; | 300 pos->coladd = b; |
317 | 301 |
318 col += b; | 302 col += b; |
319 } | 303 } |
320 } | 304 } |
321 #endif | |
322 | 305 |
323 /* prevent from moving onto a trail byte */ | 306 /* prevent from moving onto a trail byte */ |
324 if (has_mbyte) | 307 if (has_mbyte) |
325 mb_adjustpos(curbuf, pos); | 308 mb_adjustpos(curbuf, pos); |
326 | 309 |
362 | 345 |
363 lp->col += l; | 346 lp->col += l; |
364 return ((p[l] != NUL) ? 0 : 2); | 347 return ((p[l] != NUL) ? 0 : 2); |
365 } | 348 } |
366 lp->col++; | 349 lp->col++; |
367 #ifdef FEAT_VIRTUALEDIT | |
368 lp->coladd = 0; | 350 lp->coladd = 0; |
369 #endif | |
370 return ((p[1] != NUL) ? 0 : 2); | 351 return ((p[1] != NUL) ? 0 : 2); |
371 } | 352 } |
372 } | 353 } |
373 if (lp->lnum != curbuf->b_ml.ml_line_count) /* there is a next line */ | 354 if (lp->lnum != curbuf->b_ml.ml_line_count) /* there is a next line */ |
374 { | 355 { |
375 lp->col = 0; | 356 lp->col = 0; |
376 lp->lnum++; | 357 lp->lnum++; |
377 #ifdef FEAT_VIRTUALEDIT | |
378 lp->coladd = 0; | 358 lp->coladd = 0; |
379 #endif | |
380 return 1; | 359 return 1; |
381 } | 360 } |
382 return -1; | 361 return -1; |
383 } | 362 } |
384 | 363 |
410 int | 389 int |
411 dec(pos_T *lp) | 390 dec(pos_T *lp) |
412 { | 391 { |
413 char_u *p; | 392 char_u *p; |
414 | 393 |
415 #ifdef FEAT_VIRTUALEDIT | |
416 lp->coladd = 0; | 394 lp->coladd = 0; |
417 #endif | |
418 if (lp->col == MAXCOL) | 395 if (lp->col == MAXCOL) |
419 { | 396 { |
420 /* past end of line */ | 397 /* past end of line */ |
421 p = ml_get(lp->lnum); | 398 p = ml_get(lp->lnum); |
422 lp->col = (colnr_T)STRLEN(p); | 399 lp->col = (colnr_T)STRLEN(p); |
572 */ | 549 */ |
573 void | 550 void |
574 check_cursor_col_win(win_T *win) | 551 check_cursor_col_win(win_T *win) |
575 { | 552 { |
576 colnr_T len; | 553 colnr_T len; |
577 #ifdef FEAT_VIRTUALEDIT | |
578 colnr_T oldcol = win->w_cursor.col; | 554 colnr_T oldcol = win->w_cursor.col; |
579 colnr_T oldcoladd = win->w_cursor.col + win->w_cursor.coladd; | 555 colnr_T oldcoladd = win->w_cursor.col + win->w_cursor.coladd; |
580 #endif | |
581 | 556 |
582 len = (colnr_T)STRLEN(ml_get_buf(win->w_buffer, win->w_cursor.lnum, FALSE)); | 557 len = (colnr_T)STRLEN(ml_get_buf(win->w_buffer, win->w_cursor.lnum, FALSE)); |
583 if (len == 0) | 558 if (len == 0) |
584 win->w_cursor.col = 0; | 559 win->w_cursor.col = 0; |
585 else if (win->w_cursor.col >= len) | 560 else if (win->w_cursor.col >= len) |
588 * - in Insert mode or restarting Insert mode | 563 * - in Insert mode or restarting Insert mode |
589 * - in Visual mode and 'selection' isn't "old" | 564 * - in Visual mode and 'selection' isn't "old" |
590 * - 'virtualedit' is set */ | 565 * - 'virtualedit' is set */ |
591 if ((State & INSERT) || restart_edit | 566 if ((State & INSERT) || restart_edit |
592 || (VIsual_active && *p_sel != 'o') | 567 || (VIsual_active && *p_sel != 'o') |
593 #ifdef FEAT_VIRTUALEDIT | |
594 || (ve_flags & VE_ONEMORE) | 568 || (ve_flags & VE_ONEMORE) |
595 #endif | |
596 || virtual_active()) | 569 || virtual_active()) |
597 win->w_cursor.col = len; | 570 win->w_cursor.col = len; |
598 else | 571 else |
599 { | 572 { |
600 win->w_cursor.col = len - 1; | 573 win->w_cursor.col = len - 1; |
604 } | 577 } |
605 } | 578 } |
606 else if (win->w_cursor.col < 0) | 579 else if (win->w_cursor.col < 0) |
607 win->w_cursor.col = 0; | 580 win->w_cursor.col = 0; |
608 | 581 |
609 #ifdef FEAT_VIRTUALEDIT | |
610 /* If virtual editing is on, we can leave the cursor on the old position, | 582 /* If virtual editing is on, we can leave the cursor on the old position, |
611 * only we must set it to virtual. But don't do it when at the end of the | 583 * only we must set it to virtual. But don't do it when at the end of the |
612 * line. */ | 584 * line. */ |
613 if (oldcol == MAXCOL) | 585 if (oldcol == MAXCOL) |
614 win->w_cursor.coladd = 0; | 586 win->w_cursor.coladd = 0; |
632 } | 604 } |
633 else | 605 else |
634 /* avoid weird number when there is a miscalculation or overflow */ | 606 /* avoid weird number when there is a miscalculation or overflow */ |
635 win->w_cursor.coladd = 0; | 607 win->w_cursor.coladd = 0; |
636 } | 608 } |
637 #endif | |
638 } | 609 } |
639 | 610 |
640 /* | 611 /* |
641 * make sure curwin->w_cursor in on a valid character | 612 * make sure curwin->w_cursor in on a valid character |
642 */ | 613 */ |
2170 } | 2141 } |
2171 } | 2142 } |
2172 #endif | 2143 #endif |
2173 | 2144 |
2174 /* | 2145 /* |
2175 * Concatenate a string to a growarray which contains characters. | 2146 * Concatenate a string to a growarray which contains bytes. |
2176 * When "s" is NULL does not do anything. | 2147 * When "s" is NULL does not do anything. |
2177 * Note: Does NOT copy the NUL at the end! | 2148 * Note: Does NOT copy the NUL at the end! |
2178 */ | 2149 */ |
2179 void | 2150 void |
2180 ga_concat(garray_T *gap, char_u *s) | 2151 ga_concat(garray_T *gap, char_u *s) |