comparison src/edit.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 dd2e0b83a660
children 2d941023bd2f
comparison
equal deleted inserted replaced
15635:c51d2a06f5f9 15636:6f1c7e9a6393
1070 #endif 1070 #endif
1071 if (echeck_abbr(Ctrl_O + ABBR_OFF)) 1071 if (echeck_abbr(Ctrl_O + ABBR_OFF))
1072 break; 1072 break;
1073 ins_ctrl_o(); 1073 ins_ctrl_o();
1074 1074
1075 #ifdef FEAT_VIRTUALEDIT
1076 /* don't move the cursor left when 'virtualedit' has "onemore". */ 1075 /* don't move the cursor left when 'virtualedit' has "onemore". */
1077 if (ve_flags & VE_ONEMORE) 1076 if (ve_flags & VE_ONEMORE)
1078 { 1077 {
1079 ins_at_eol = FALSE; 1078 ins_at_eol = FALSE;
1080 nomove = TRUE; 1079 nomove = TRUE;
1081 } 1080 }
1082 #endif
1083 count = 0; 1081 count = 0;
1084 goto doESCkey; 1082 goto doESCkey;
1085 1083
1086 case K_INS: /* toggle insert/replace mode */ 1084 case K_INS: /* toggle insert/replace mode */
1087 case K_KINS: 1085 case K_KINS:
7123 7121
7124 if (VIM_ISWHITE(cc)) 7122 if (VIM_ISWHITE(cc))
7125 { 7123 {
7126 if (gchar_cursor() != NUL) 7124 if (gchar_cursor() != NUL)
7127 inc_cursor(); 7125 inc_cursor();
7128 #ifdef FEAT_VIRTUALEDIT 7126 // If the cursor is still at the same character, also keep
7129 /* If the cursor is still at the same character, also keep 7127 // the "coladd".
7130 * the "coladd". */
7131 if (gchar_cursor() == NUL 7128 if (gchar_cursor() == NUL
7132 && curwin->w_cursor.lnum == tpos.lnum 7129 && curwin->w_cursor.lnum == tpos.lnum
7133 && curwin->w_cursor.col == tpos.col) 7130 && curwin->w_cursor.col == tpos.col)
7134 curwin->w_cursor.coladd = tpos.coladd; 7131 curwin->w_cursor.coladd = tpos.coladd;
7135 #endif
7136 } 7132 }
7137 } 7133 }
7138 7134
7139 /* If a space was inserted for auto-formatting, remove it now. */ 7135 /* If a space was inserted for auto-formatting, remove it now. */
7140 check_auto_format(TRUE); 7136 check_auto_format(TRUE);
7180 int len = (int)STRLEN(ml_get_curline()); 7176 int len = (int)STRLEN(ml_get_curline());
7181 7177
7182 if (VIsual.col > len) 7178 if (VIsual.col > len)
7183 { 7179 {
7184 VIsual.col = len; 7180 VIsual.col = len;
7185 #ifdef FEAT_VIRTUALEDIT
7186 VIsual.coladd = 0; 7181 VIsual.coladd = 0;
7187 #endif
7188 } 7182 }
7189 } 7183 }
7190 } 7184 }
7191 } 7185 }
7192 did_ai = FALSE; 7186 did_ai = FALSE;
7291 if ((flags & BL_SOL) && !p_sol) 7285 if ((flags & BL_SOL) && !p_sol)
7292 coladvance(curwin->w_curswant); 7286 coladvance(curwin->w_curswant);
7293 else 7287 else
7294 { 7288 {
7295 curwin->w_cursor.col = 0; 7289 curwin->w_cursor.col = 0;
7296 #ifdef FEAT_VIRTUALEDIT
7297 curwin->w_cursor.coladd = 0; 7290 curwin->w_cursor.coladd = 0;
7298 #endif
7299 7291
7300 if (flags & (BL_WHITE | BL_SOL)) 7292 if (flags & (BL_WHITE | BL_SOL))
7301 { 7293 {
7302 char_u *ptr; 7294 char_u *ptr;
7303 7295
7321 oneright(void) 7313 oneright(void)
7322 { 7314 {
7323 char_u *ptr; 7315 char_u *ptr;
7324 int l; 7316 int l;
7325 7317
7326 #ifdef FEAT_VIRTUALEDIT
7327 if (virtual_active()) 7318 if (virtual_active())
7328 { 7319 {
7329 pos_T prevpos = curwin->w_cursor; 7320 pos_T prevpos = curwin->w_cursor;
7330 7321
7331 /* Adjust for multi-wide char (excluding TAB) */ 7322 /* Adjust for multi-wide char (excluding TAB) */
7336 curwin->w_set_curswant = TRUE; 7327 curwin->w_set_curswant = TRUE;
7337 /* Return OK if the cursor moved, FAIL otherwise (at window edge). */ 7328 /* Return OK if the cursor moved, FAIL otherwise (at window edge). */
7338 return (prevpos.col != curwin->w_cursor.col 7329 return (prevpos.col != curwin->w_cursor.col
7339 || prevpos.coladd != curwin->w_cursor.coladd) ? OK : FAIL; 7330 || prevpos.coladd != curwin->w_cursor.coladd) ? OK : FAIL;
7340 } 7331 }
7341 #endif
7342 7332
7343 ptr = ml_get_cursor(); 7333 ptr = ml_get_cursor();
7344 if (*ptr == NUL) 7334 if (*ptr == NUL)
7345 return FAIL; /* already at the very end */ 7335 return FAIL; /* already at the very end */
7346 7336
7349 else 7339 else
7350 l = 1; 7340 l = 1;
7351 7341
7352 /* move "l" bytes right, but don't end up on the NUL, unless 'virtualedit' 7342 /* move "l" bytes right, but don't end up on the NUL, unless 'virtualedit'
7353 * contains "onemore". */ 7343 * contains "onemore". */
7354 if (ptr[l] == NUL 7344 if (ptr[l] == NUL && (ve_flags & VE_ONEMORE) == 0)
7355 #ifdef FEAT_VIRTUALEDIT
7356 && (ve_flags & VE_ONEMORE) == 0
7357 #endif
7358 )
7359 return FAIL; 7345 return FAIL;
7360 curwin->w_cursor.col += l; 7346 curwin->w_cursor.col += l;
7361 7347
7362 curwin->w_set_curswant = TRUE; 7348 curwin->w_set_curswant = TRUE;
7363 return OK; 7349 return OK;
7364 } 7350 }
7365 7351
7366 int 7352 int
7367 oneleft(void) 7353 oneleft(void)
7368 { 7354 {
7369 #ifdef FEAT_VIRTUALEDIT
7370 if (virtual_active()) 7355 if (virtual_active())
7371 { 7356 {
7372 # ifdef FEAT_LINEBREAK 7357 #ifdef FEAT_LINEBREAK
7373 int width; 7358 int width;
7374 # endif 7359 #endif
7375 int v = getviscol(); 7360 int v = getviscol();
7376 7361
7377 if (v == 0) 7362 if (v == 0)
7378 return FAIL; 7363 return FAIL;
7379 7364
7380 # ifdef FEAT_LINEBREAK 7365 #ifdef FEAT_LINEBREAK
7381 /* We might get stuck on 'showbreak', skip over it. */ 7366 /* We might get stuck on 'showbreak', skip over it. */
7382 width = 1; 7367 width = 1;
7383 for (;;) 7368 for (;;)
7384 { 7369 {
7385 coladvance(v - width); 7370 coladvance(v - width);
7389 if ((*p_sbr == NUL && !curwin->w_p_bri 7374 if ((*p_sbr == NUL && !curwin->w_p_bri
7390 && !has_mbyte) || getviscol() < v) 7375 && !has_mbyte) || getviscol() < v)
7391 break; 7376 break;
7392 ++width; 7377 ++width;
7393 } 7378 }
7394 # else 7379 #else
7395 coladvance(v - 1); 7380 coladvance(v - 1);
7396 # endif 7381 #endif
7397 7382
7398 if (curwin->w_cursor.coladd == 1) 7383 if (curwin->w_cursor.coladd == 1)
7399 { 7384 {
7400 char_u *ptr; 7385 char_u *ptr;
7401 7386
7407 } 7392 }
7408 7393
7409 curwin->w_set_curswant = TRUE; 7394 curwin->w_set_curswant = TRUE;
7410 return OK; 7395 return OK;
7411 } 7396 }
7412 #endif
7413 7397
7414 if (curwin->w_cursor.col == 0) 7398 if (curwin->w_cursor.col == 0)
7415 return FAIL; 7399 return FAIL;
7416 7400
7417 curwin->w_set_curswant = TRUE; 7401 curwin->w_set_curswant = TRUE;
8663 * The cursor should end up on the last inserted character. 8647 * The cursor should end up on the last inserted character.
8664 * Don't do it for CTRL-O, unless past the end of the line. 8648 * Don't do it for CTRL-O, unless past the end of the line.
8665 */ 8649 */
8666 if (!nomove 8650 if (!nomove
8667 && (curwin->w_cursor.col != 0 8651 && (curwin->w_cursor.col != 0
8668 #ifdef FEAT_VIRTUALEDIT 8652 || curwin->w_cursor.coladd > 0)
8669 || curwin->w_cursor.coladd > 0
8670 #endif
8671 )
8672 && (restart_edit == NUL 8653 && (restart_edit == NUL
8673 || (gchar_cursor() == NUL && !VIsual_active)) 8654 || (gchar_cursor() == NUL && !VIsual_active))
8674 #ifdef FEAT_RIGHTLEFT 8655 #ifdef FEAT_RIGHTLEFT
8675 && !revins_on 8656 && !revins_on
8676 #endif 8657 #endif
8677 ) 8658 )
8678 { 8659 {
8679 #ifdef FEAT_VIRTUALEDIT
8680 if (curwin->w_cursor.coladd > 0 || ve_flags == VE_ALL) 8660 if (curwin->w_cursor.coladd > 0 || ve_flags == VE_ALL)
8681 { 8661 {
8682 oneleft(); 8662 oneleft();
8683 if (restart_edit != NUL) 8663 if (restart_edit != NUL)
8684 ++curwin->w_cursor.coladd; 8664 ++curwin->w_cursor.coladd;
8685 } 8665 }
8686 else 8666 else
8687 #endif
8688 { 8667 {
8689 --curwin->w_cursor.col; 8668 --curwin->w_cursor.col;
8690 /* Correct cursor for multi-byte character. */ 8669 /* Correct cursor for multi-byte character. */
8691 if (has_mbyte) 8670 if (has_mbyte)
8692 mb_adjust_cursor(); 8671 mb_adjust_cursor();
8872 else 8851 else
8873 if (State & REPLACE_FLAG) 8852 if (State & REPLACE_FLAG)
8874 restart_edit = 'R'; 8853 restart_edit = 'R';
8875 else 8854 else
8876 restart_edit = 'I'; 8855 restart_edit = 'I';
8877 #ifdef FEAT_VIRTUALEDIT
8878 if (virtual_active()) 8856 if (virtual_active())
8879 ins_at_eol = FALSE; /* cursor always keeps its column */ 8857 ins_at_eol = FALSE; /* cursor always keeps its column */
8880 else 8858 else
8881 #endif
8882 ins_at_eol = (gchar_cursor() == NUL); 8859 ins_at_eol = (gchar_cursor() == NUL);
8883 } 8860 }
8884 8861
8885 /* 8862 /*
8886 * If the cursor is on an indent, ^T/^D insert/delete one 8863 * If the cursor is on an indent, ^T/^D insert/delete one
9038 #ifdef FEAT_RIGHTLEFT 9015 #ifdef FEAT_RIGHTLEFT
9039 if (revins_on) /* put cursor after last inserted char */ 9016 if (revins_on) /* put cursor after last inserted char */
9040 inc_cursor(); 9017 inc_cursor();
9041 #endif 9018 #endif
9042 9019
9043 #ifdef FEAT_VIRTUALEDIT
9044 /* Virtualedit: 9020 /* Virtualedit:
9045 * BACKSPACE_CHAR eats a virtual space 9021 * BACKSPACE_CHAR eats a virtual space
9046 * BACKSPACE_WORD eats all coladd 9022 * BACKSPACE_WORD eats all coladd
9047 * BACKSPACE_LINE eats all coladd and keeps going 9023 * BACKSPACE_LINE eats all coladd and keeps going
9048 */ 9024 */
9058 curwin->w_cursor.coladd = 0; 9034 curwin->w_cursor.coladd = 0;
9059 return TRUE; 9035 return TRUE;
9060 } 9036 }
9061 curwin->w_cursor.coladd = 0; 9037 curwin->w_cursor.coladd = 0;
9062 } 9038 }
9063 #endif
9064 9039
9065 /* 9040 /*
9066 * Delete newline! 9041 * Delete newline!
9067 */ 9042 */
9068 if (curwin->w_cursor.col == 0) 9043 if (curwin->w_cursor.col == 0)
9742 undisplay_dollar(); 9717 undisplay_dollar();
9743 tpos = curwin->w_cursor; 9718 tpos = curwin->w_cursor;
9744 if (c == K_C_HOME) 9719 if (c == K_C_HOME)
9745 curwin->w_cursor.lnum = 1; 9720 curwin->w_cursor.lnum = 1;
9746 curwin->w_cursor.col = 0; 9721 curwin->w_cursor.col = 0;
9747 #ifdef FEAT_VIRTUALEDIT
9748 curwin->w_cursor.coladd = 0; 9722 curwin->w_cursor.coladd = 0;
9749 #endif
9750 curwin->w_curswant = 0; 9723 curwin->w_curswant = 0;
9751 start_arrow(&tpos); 9724 start_arrow(&tpos);
9752 } 9725 }
9753 9726
9754 static void 9727 static void
9795 #ifdef FEAT_FOLDING 9768 #ifdef FEAT_FOLDING
9796 if ((fdo_flags & FDO_HOR) && KeyTyped) 9769 if ((fdo_flags & FDO_HOR) && KeyTyped)
9797 foldOpenCursor(); 9770 foldOpenCursor();
9798 #endif 9771 #endif
9799 undisplay_dollar(); 9772 undisplay_dollar();
9800 if (gchar_cursor() != NUL 9773 if (gchar_cursor() != NUL || virtual_active())
9801 #ifdef FEAT_VIRTUALEDIT
9802 || virtual_active()
9803 #endif
9804 )
9805 { 9774 {
9806 start_arrow_with_change(&curwin->w_cursor, end_change); 9775 start_arrow_with_change(&curwin->w_cursor, end_change);
9807 if (!end_change) 9776 if (!end_change)
9808 AppendCharToRedobuff(K_RIGHT); 9777 AppendCharToRedobuff(K_RIGHT);
9809 curwin->w_set_curswant = TRUE; 9778 curwin->w_set_curswant = TRUE;
9810 #ifdef FEAT_VIRTUALEDIT
9811 if (virtual_active()) 9779 if (virtual_active())
9812 oneright(); 9780 oneright();
9813 else 9781 else
9814 #endif
9815 { 9782 {
9816 if (has_mbyte) 9783 if (has_mbyte)
9817 curwin->w_cursor.col += (*mb_ptr2len)(ml_get_cursor()); 9784 curwin->w_cursor.col += (*mb_ptr2len)(ml_get_cursor());
9818 else 9785 else
9819 ++curwin->w_cursor.col; 9786 ++curwin->w_cursor.col;
10266 * replacing the next line, so we push all of the characters left on the 10233 * replacing the next line, so we push all of the characters left on the
10267 * line onto the replace stack. This is not done here though, it is done 10234 * line onto the replace stack. This is not done here though, it is done
10268 * in open_line(). 10235 * in open_line().
10269 */ 10236 */
10270 10237
10271 #ifdef FEAT_VIRTUALEDIT
10272 /* Put cursor on NUL if on the last char and coladd is 1 (happens after 10238 /* Put cursor on NUL if on the last char and coladd is 1 (happens after
10273 * CTRL-O). */ 10239 * CTRL-O). */
10274 if (virtual_active() && curwin->w_cursor.coladd > 0) 10240 if (virtual_active() && curwin->w_cursor.coladd > 0)
10275 coladvance(getviscol()); 10241 coladvance(getviscol());
10276 #endif
10277 10242
10278 #ifdef FEAT_RIGHTLEFT 10243 #ifdef FEAT_RIGHTLEFT
10279 # ifdef FEAT_FKMAP 10244 # ifdef FEAT_FKMAP
10280 if (p_altkeymap && p_fkmap) 10245 if (p_altkeymap && p_fkmap)
10281 fkmap(NL); 10246 fkmap(NL);