comparison src/normal.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 b7a88676e81c
comparison
equal deleted inserted replaced
15635:c51d2a06f5f9 15636:6f1c7e9a6393
1338 static int redo_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */ 1338 static int redo_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */
1339 static linenr_T redo_VIsual_line_count; /* number of lines */ 1339 static linenr_T redo_VIsual_line_count; /* number of lines */
1340 static colnr_T redo_VIsual_vcol; /* number of cols or end column */ 1340 static colnr_T redo_VIsual_vcol; /* number of cols or end column */
1341 static long redo_VIsual_count; /* count for Visual operator */ 1341 static long redo_VIsual_count; /* count for Visual operator */
1342 static int redo_VIsual_arg; /* extra argument */ 1342 static int redo_VIsual_arg; /* extra argument */
1343 #ifdef FEAT_VIRTUALEDIT
1344 int include_line_break = FALSE; 1343 int include_line_break = FALSE;
1345 #endif
1346 1344
1347 #if defined(FEAT_CLIPBOARD) 1345 #if defined(FEAT_CLIPBOARD)
1348 /* 1346 /*
1349 * Yank the visual area into the GUI selection register before we operate 1347 * Yank the visual area into the GUI selection register before we operate
1350 * on it and lose it forever. 1348 * on it and lose it forever.
1525 VIsual_mode = 'v'; 1523 VIsual_mode = 'v';
1526 } 1524 }
1527 /* If 'selection' is "exclusive", backup one character for 1525 /* If 'selection' is "exclusive", backup one character for
1528 * charwise selections. */ 1526 * charwise selections. */
1529 else if (VIsual_mode == 'v') 1527 else if (VIsual_mode == 'v')
1530 { 1528 include_line_break = unadjust_for_sel();
1531 # ifdef FEAT_VIRTUALEDIT
1532 include_line_break =
1533 # endif
1534 unadjust_for_sel();
1535 }
1536 1529
1537 oap->start = VIsual; 1530 oap->start = VIsual;
1538 if (VIsual_mode == 'V') 1531 if (VIsual_mode == 'V')
1539 { 1532 {
1540 oap->start.col = 0; 1533 oap->start.col = 0;
1541 # ifdef FEAT_VIRTUALEDIT
1542 oap->start.coladd = 0; 1534 oap->start.coladd = 0;
1543 # endif
1544 } 1535 }
1545 } 1536 }
1546 1537
1547 /* 1538 /*
1548 * Set oap->start to the first position of the operated text, oap->end 1539 * Set oap->start to the first position of the operated text, oap->end
1588 1579
1589 /* Just in case lines were deleted that make the position invalid. */ 1580 /* Just in case lines were deleted that make the position invalid. */
1590 check_pos(curwin->w_buffer, &oap->end); 1581 check_pos(curwin->w_buffer, &oap->end);
1591 oap->line_count = oap->end.lnum - oap->start.lnum + 1; 1582 oap->line_count = oap->end.lnum - oap->start.lnum + 1;
1592 1583
1593 #ifdef FEAT_VIRTUALEDIT
1594 /* Set "virtual_op" before resetting VIsual_active. */ 1584 /* Set "virtual_op" before resetting VIsual_active. */
1595 virtual_op = virtual_active(); 1585 virtual_op = virtual_active();
1596 #endif
1597 1586
1598 if (VIsual_active || redo_VIsual_busy) 1587 if (VIsual_active || redo_VIsual_busy)
1599 { 1588 {
1600 get_op_vcol(oap, redo_VIsual_vcol, TRUE); 1589 get_op_vcol(oap, redo_VIsual_vcol, TRUE);
1601 1590
1683 oap->motion_type = MLINE; 1672 oap->motion_type = MLINE;
1684 else 1673 else
1685 { 1674 {
1686 oap->motion_type = MCHAR; 1675 oap->motion_type = MCHAR;
1687 if (VIsual_mode != Ctrl_V && *ml_get_pos(&(oap->end)) == NUL 1676 if (VIsual_mode != Ctrl_V && *ml_get_pos(&(oap->end)) == NUL
1688 #ifdef FEAT_VIRTUALEDIT 1677 && (include_line_break || !virtual_op))
1689 && (include_line_break || !virtual_op)
1690 #endif
1691 )
1692 { 1678 {
1693 oap->inclusive = FALSE; 1679 oap->inclusive = FALSE;
1694 /* Try to include the newline, unless it's an operator 1680 /* Try to include the newline, unless it's an operator
1695 * that works on lines only. */ 1681 * that works on lines only. */
1696 if (*p_sel != 'o' 1682 if (*p_sel != 'o'
1697 && !op_on_lines(oap->op_type) 1683 && !op_on_lines(oap->op_type)
1698 && oap->end.lnum < curbuf->b_ml.ml_line_count) 1684 && oap->end.lnum < curbuf->b_ml.ml_line_count)
1699 { 1685 {
1700 ++oap->end.lnum; 1686 ++oap->end.lnum;
1701 oap->end.col = 0; 1687 oap->end.col = 0;
1702 #ifdef FEAT_VIRTUALEDIT
1703 oap->end.coladd = 0; 1688 oap->end.coladd = 0;
1704 #endif
1705 ++oap->line_count; 1689 ++oap->line_count;
1706 } 1690 }
1707 } 1691 }
1708 } 1692 }
1709 1693
1757 oap->empty = (oap->motion_type == MCHAR 1741 oap->empty = (oap->motion_type == MCHAR
1758 && (!oap->inclusive 1742 && (!oap->inclusive
1759 || (oap->op_type == OP_YANK 1743 || (oap->op_type == OP_YANK
1760 && gchar_pos(&oap->end) == NUL)) 1744 && gchar_pos(&oap->end) == NUL))
1761 && EQUAL_POS(oap->start, oap->end) 1745 && EQUAL_POS(oap->start, oap->end)
1762 #ifdef FEAT_VIRTUALEDIT 1746 && !(virtual_op && oap->start.coladd != oap->end.coladd));
1763 && !(virtual_op && oap->start.coladd != oap->end.coladd)
1764 #endif
1765 );
1766 /* 1747 /*
1767 * For delete, change and yank, it's an error to operate on an 1748 * For delete, change and yank, it's an error to operate on an
1768 * empty region, when 'E' included in 'cpoptions' (Vi compatible). 1749 * empty region, when 'E' included in 'cpoptions' (Vi compatible).
1769 */ 1750 */
1770 empty_region_error = (oap->empty 1751 empty_region_error = (oap->empty
2095 check_cursor_col(); 2076 check_cursor_col();
2096 break; 2077 break;
2097 default: 2078 default:
2098 clearopbeep(oap); 2079 clearopbeep(oap);
2099 } 2080 }
2100 #ifdef FEAT_VIRTUALEDIT
2101 virtual_op = MAYBE; 2081 virtual_op = MAYBE;
2102 #endif
2103 if (!gui_yank) 2082 if (!gui_yank)
2104 { 2083 {
2105 /* 2084 /*
2106 * if 'sol' not set, go back to old column for some commands 2085 * if 'sol' not set, go back to old column for some commands
2107 */ 2086 */
2196 static void 2175 static void
2197 op_function(oparg_T *oap UNUSED) 2176 op_function(oparg_T *oap UNUSED)
2198 { 2177 {
2199 #ifdef FEAT_EVAL 2178 #ifdef FEAT_EVAL
2200 typval_T argv[2]; 2179 typval_T argv[2];
2201 # ifdef FEAT_VIRTUALEDIT
2202 int save_virtual_op = virtual_op; 2180 int save_virtual_op = virtual_op;
2203 # endif
2204 2181
2205 if (*p_opfunc == NUL) 2182 if (*p_opfunc == NUL)
2206 emsg(_("E774: 'operatorfunc' is empty")); 2183 emsg(_("E774: 'operatorfunc' is empty"));
2207 else 2184 else
2208 { 2185 {
2220 argv[0].vval.v_string = (char_u *)"line"; 2197 argv[0].vval.v_string = (char_u *)"line";
2221 else 2198 else
2222 argv[0].vval.v_string = (char_u *)"char"; 2199 argv[0].vval.v_string = (char_u *)"char";
2223 argv[1].v_type = VAR_UNKNOWN; 2200 argv[1].v_type = VAR_UNKNOWN;
2224 2201
2225 # ifdef FEAT_VIRTUALEDIT
2226 /* Reset virtual_op so that 'virtualedit' can be changed in the 2202 /* Reset virtual_op so that 'virtualedit' can be changed in the
2227 * function. */ 2203 * function. */
2228 virtual_op = MAYBE; 2204 virtual_op = MAYBE;
2229 # endif
2230 2205
2231 (void)call_func_retnr(p_opfunc, 1, argv); 2206 (void)call_func_retnr(p_opfunc, 1, argv);
2232 2207
2233 # ifdef FEAT_VIRTUALEDIT
2234 virtual_op = save_virtual_op; 2208 virtual_op = save_virtual_op;
2235 # endif
2236 } 2209 }
2237 #else 2210 #else
2238 emsg(_("E775: Eval feature not available")); 2211 emsg(_("E775: Eval feature not available"));
2239 #endif 2212 #endif
2240 } 2213 }
3288 curbuf->b_visual.vi_end = curwin->w_cursor; 3261 curbuf->b_visual.vi_end = curwin->w_cursor;
3289 curbuf->b_visual.vi_curswant = curwin->w_curswant; 3262 curbuf->b_visual.vi_curswant = curwin->w_curswant;
3290 #ifdef FEAT_EVAL 3263 #ifdef FEAT_EVAL
3291 curbuf->b_visual_mode_eval = VIsual_mode; 3264 curbuf->b_visual_mode_eval = VIsual_mode;
3292 #endif 3265 #endif
3293 #ifdef FEAT_VIRTUALEDIT
3294 if (!virtual_active()) 3266 if (!virtual_active())
3295 curwin->w_cursor.coladd = 0; 3267 curwin->w_cursor.coladd = 0;
3296 #endif
3297 may_clear_cmdline(); 3268 may_clear_cmdline();
3298 3269
3299 adjust_cursor_eol(); 3270 adjust_cursor_eol();
3300 } 3271 }
3301 3272
5942 5913
5943 cap->oap->motion_type = MCHAR; 5914 cap->oap->motion_type = MCHAR;
5944 cap->oap->inclusive = FALSE; 5915 cap->oap->inclusive = FALSE;
5945 past_line = (VIsual_active && *p_sel != 'o'); 5916 past_line = (VIsual_active && *p_sel != 'o');
5946 5917
5947 #ifdef FEAT_VIRTUALEDIT
5948 /* 5918 /*
5949 * In virtual edit mode, there's no such thing as "past_line", as lines 5919 * In virtual edit mode, there's no such thing as "past_line", as lines
5950 * are (theoretically) infinitely long. 5920 * are (theoretically) infinitely long.
5951 */ 5921 */
5952 if (virtual_active()) 5922 if (virtual_active())
5953 past_line = 0; 5923 past_line = 0;
5954 #endif
5955 5924
5956 for (n = cap->count1; n > 0; --n) 5925 for (n = cap->count1; n > 0; --n)
5957 { 5926 {
5958 if ((!past_line && oneright() == FAIL) 5927 if ((!past_line && oneright() == FAIL)
5959 || (past_line && *ml_get_cursor() == NUL) 5928 || (past_line && *ml_get_cursor() == NUL)
5981 cap->oap->inclusive = TRUE; 5950 cap->oap->inclusive = TRUE;
5982 else 5951 else
5983 { 5952 {
5984 ++curwin->w_cursor.lnum; 5953 ++curwin->w_cursor.lnum;
5985 curwin->w_cursor.col = 0; 5954 curwin->w_cursor.col = 0;
5986 #ifdef FEAT_VIRTUALEDIT
5987 curwin->w_cursor.coladd = 0; 5955 curwin->w_cursor.coladd = 0;
5988 #endif
5989 curwin->w_set_curswant = TRUE; 5956 curwin->w_set_curswant = TRUE;
5990 cap->oap->inclusive = FALSE; 5957 cap->oap->inclusive = FALSE;
5991 } 5958 }
5992 continue; 5959 continue;
5993 } 5960 }
6005 break; 5972 break;
6006 } 5973 }
6007 else if (past_line) 5974 else if (past_line)
6008 { 5975 {
6009 curwin->w_set_curswant = TRUE; 5976 curwin->w_set_curswant = TRUE;
6010 #ifdef FEAT_VIRTUALEDIT
6011 if (virtual_active()) 5977 if (virtual_active())
6012 oneright(); 5978 oneright();
6013 else 5979 else
6014 #endif
6015 { 5980 {
6016 if (has_mbyte) 5981 if (has_mbyte)
6017 curwin->w_cursor.col += 5982 curwin->w_cursor.col +=
6018 (*mb_ptr2len)(ml_get_cursor()); 5983 (*mb_ptr2len)(ml_get_cursor());
6019 else 5984 else
6240 static void 6205 static void
6241 nv_dollar(cmdarg_T *cap) 6206 nv_dollar(cmdarg_T *cap)
6242 { 6207 {
6243 cap->oap->motion_type = MCHAR; 6208 cap->oap->motion_type = MCHAR;
6244 cap->oap->inclusive = TRUE; 6209 cap->oap->inclusive = TRUE;
6245 #ifdef FEAT_VIRTUALEDIT
6246 /* In virtual mode when off the edge of a line and an operator 6210 /* In virtual mode when off the edge of a line and an operator
6247 * is pending (whew!) keep the cursor where it is. 6211 * is pending (whew!) keep the cursor where it is.
6248 * Otherwise, send it to the end of the line. */ 6212 * Otherwise, send it to the end of the line. */
6249 if (!virtual_active() || gchar_cursor() != NUL 6213 if (!virtual_active() || gchar_cursor() != NUL
6250 || cap->oap->op_type == OP_NOP) 6214 || cap->oap->op_type == OP_NOP)
6251 #endif
6252 curwin->w_curswant = MAXCOL; /* so we stay at the end */ 6215 curwin->w_curswant = MAXCOL; /* so we stay at the end */
6253 if (cursor_down((long)(cap->count1 - 1), 6216 if (cursor_down((long)(cap->count1 - 1),
6254 cap->oap->op_type == OP_NOP) == FAIL) 6217 cap->oap->op_type == OP_NOP) == FAIL)
6255 clearopbeep(cap->oap); 6218 clearopbeep(cap->oap);
6256 #ifdef FEAT_FOLDING 6219 #ifdef FEAT_FOLDING
6339 clearop(cap->oap); 6302 clearop(cap->oap);
6340 else 6303 else
6341 { 6304 {
6342 if (i == 2) 6305 if (i == 2)
6343 cap->oap->motion_type = MLINE; 6306 cap->oap->motion_type = MLINE;
6344 #ifdef FEAT_VIRTUALEDIT
6345 curwin->w_cursor.coladd = 0; 6307 curwin->w_cursor.coladd = 0;
6346 #endif
6347 #ifdef FEAT_FOLDING 6308 #ifdef FEAT_FOLDING
6348 if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) 6309 if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped)
6349 foldOpenCursor(); 6310 foldOpenCursor();
6350 #endif 6311 #endif
6351 } 6312 }
6376 if (IS_SPECIAL(cap->nchar) || searchc(cap, t_cmd) == FAIL) 6337 if (IS_SPECIAL(cap->nchar) || searchc(cap, t_cmd) == FAIL)
6377 clearopbeep(cap->oap); 6338 clearopbeep(cap->oap);
6378 else 6339 else
6379 { 6340 {
6380 curwin->w_set_curswant = TRUE; 6341 curwin->w_set_curswant = TRUE;
6381 #ifdef FEAT_VIRTUALEDIT
6382 /* Include a Tab for "tx" and for "dfx". */ 6342 /* Include a Tab for "tx" and for "dfx". */
6383 if (gchar_cursor() == TAB && virtual_active() && cap->arg == FORWARD 6343 if (gchar_cursor() == TAB && virtual_active() && cap->arg == FORWARD
6384 && (t_cmd || cap->oap->op_type != OP_NOP)) 6344 && (t_cmd || cap->oap->op_type != OP_NOP))
6385 { 6345 {
6386 colnr_T scol, ecol; 6346 colnr_T scol, ecol;
6388 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); 6348 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol);
6389 curwin->w_cursor.coladd = ecol - scol; 6349 curwin->w_cursor.coladd = ecol - scol;
6390 } 6350 }
6391 else 6351 else
6392 curwin->w_cursor.coladd = 0; 6352 curwin->w_cursor.coladd = 0;
6393 #endif
6394 adjust_for_sel(cap); 6353 adjust_for_sel(cap);
6395 #ifdef FEAT_FOLDING 6354 #ifdef FEAT_FOLDING
6396 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) 6355 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP)
6397 foldOpenCursor(); 6356 foldOpenCursor();
6398 #endif 6357 #endif
6404 * cap->arg is BACKWARD for "[" and FORWARD for "]". 6363 * cap->arg is BACKWARD for "[" and FORWARD for "]".
6405 */ 6364 */
6406 static void 6365 static void
6407 nv_brackets(cmdarg_T *cap) 6366 nv_brackets(cmdarg_T *cap)
6408 { 6367 {
6409 pos_T new_pos = INIT_POS_T(0, 0, 0); 6368 pos_T new_pos = {0, 0, 0};
6410 pos_T prev_pos; 6369 pos_T prev_pos;
6411 pos_T *pos = NULL; /* init for GCC */ 6370 pos_T *pos = NULL; /* init for GCC */
6412 pos_T old_pos; /* cursor position before command */ 6371 pos_T old_pos; /* cursor position before command */
6413 int flag; 6372 int flag;
6414 long n; 6373 long n;
6416 int c; 6375 int c;
6417 6376
6418 cap->oap->motion_type = MCHAR; 6377 cap->oap->motion_type = MCHAR;
6419 cap->oap->inclusive = FALSE; 6378 cap->oap->inclusive = FALSE;
6420 old_pos = curwin->w_cursor; 6379 old_pos = curwin->w_cursor;
6421 #ifdef FEAT_VIRTUALEDIT
6422 curwin->w_cursor.coladd = 0; // TODO: don't do this for an error. 6380 curwin->w_cursor.coladd = 0; // TODO: don't do this for an error.
6423 #endif
6424 6381
6425 #ifdef FEAT_SEARCHPATH 6382 #ifdef FEAT_SEARCHPATH
6426 /* 6383 /*
6427 * "[f" or "]f" : Edit file under the cursor (same as "gf") 6384 * "[f" or "]f" : Edit file under the cursor (same as "gf")
6428 */ 6385 */
6813 else 6770 else
6814 { 6771 {
6815 setpcmark(); 6772 setpcmark();
6816 curwin->w_cursor = *pos; 6773 curwin->w_cursor = *pos;
6817 curwin->w_set_curswant = TRUE; 6774 curwin->w_set_curswant = TRUE;
6818 #ifdef FEAT_VIRTUALEDIT
6819 curwin->w_cursor.coladd = 0; 6775 curwin->w_cursor.coladd = 0;
6820 #endif
6821 adjust_for_sel(cap); 6776 adjust_for_sel(cap);
6822 } 6777 }
6823 } 6778 }
6824 #ifdef FEAT_FOLDING 6779 #ifdef FEAT_FOLDING
6825 if (cap->oap->op_type == OP_NOP 6780 if (cap->oap->op_type == OP_NOP
6847 clearopbeep(cap->oap); 6802 clearopbeep(cap->oap);
6848 else 6803 else
6849 { 6804 {
6850 /* Don't leave the cursor on the NUL past end of line. */ 6805 /* Don't leave the cursor on the NUL past end of line. */
6851 adjust_cursor(cap->oap); 6806 adjust_cursor(cap->oap);
6852 #ifdef FEAT_VIRTUALEDIT
6853 curwin->w_cursor.coladd = 0; 6807 curwin->w_cursor.coladd = 0;
6854 #endif
6855 #ifdef FEAT_FOLDING 6808 #ifdef FEAT_FOLDING
6856 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) 6809 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP)
6857 foldOpenCursor(); 6810 foldOpenCursor();
6858 #endif 6811 #endif
6859 } 6812 }
6885 curwin->w_set_curswant = TRUE; 6838 curwin->w_set_curswant = TRUE;
6886 if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, NUL, FALSE)) 6839 if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, NUL, FALSE))
6887 clearopbeep(cap->oap); 6840 clearopbeep(cap->oap);
6888 else 6841 else
6889 { 6842 {
6890 #ifdef FEAT_VIRTUALEDIT
6891 curwin->w_cursor.coladd = 0; 6843 curwin->w_cursor.coladd = 0;
6892 #endif
6893 #ifdef FEAT_FOLDING 6844 #ifdef FEAT_FOLDING
6894 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) 6845 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP)
6895 foldOpenCursor(); 6846 foldOpenCursor();
6896 #endif 6847 #endif
6897 } 6848 }
6989 } 6940 }
6990 nv_operator(cap); 6941 nv_operator(cap);
6991 return; 6942 return;
6992 } 6943 }
6993 6944
6994 #ifdef FEAT_VIRTUALEDIT
6995 /* Break tabs, etc. */ 6945 /* Break tabs, etc. */
6996 if (virtual_active()) 6946 if (virtual_active())
6997 { 6947 {
6998 if (u_save_cursor() == FAIL) 6948 if (u_save_cursor() == FAIL)
6999 return; 6949 return;
7004 curwin->w_cursor.col -= cap->count1; 6954 curwin->w_cursor.col -= cap->count1;
7005 } 6955 }
7006 else if (gchar_cursor() == TAB) 6956 else if (gchar_cursor() == TAB)
7007 coladvance_force(getviscol()); 6957 coladvance_force(getviscol());
7008 } 6958 }
7009 #endif
7010 6959
7011 /* Abort if not enough characters to replace. */ 6960 /* Abort if not enough characters to replace. */
7012 ptr = ml_get_cursor(); 6961 ptr = ml_get_cursor();
7013 if (STRLEN(ptr) < (unsigned)cap->count1 6962 if (STRLEN(ptr) < (unsigned)cap->count1
7014 || (has_mbyte && mb_charlen(ptr) < cap->count1)) 6963 || (has_mbyte && mb_charlen(ptr) < cap->count1))
7170 * right one column */ 7119 * right one column */
7171 if (old_cursor.lnum >= VIsual.lnum && *p_sel == 'e') 7120 if (old_cursor.lnum >= VIsual.lnum && *p_sel == 'e')
7172 ++curwin->w_curswant; 7121 ++curwin->w_curswant;
7173 coladvance(curwin->w_curswant); 7122 coladvance(curwin->w_curswant);
7174 if (curwin->w_cursor.col == old_cursor.col 7123 if (curwin->w_cursor.col == old_cursor.col
7175 #ifdef FEAT_VIRTUALEDIT
7176 && (!virtual_active() 7124 && (!virtual_active()
7177 || curwin->w_cursor.coladd == old_cursor.coladd) 7125 || curwin->w_cursor.coladd == old_cursor.coladd))
7178 #endif
7179 )
7180 { 7126 {
7181 curwin->w_cursor.lnum = VIsual.lnum; 7127 curwin->w_cursor.lnum = VIsual.lnum;
7182 if (old_cursor.lnum <= VIsual.lnum && *p_sel == 'e') 7128 if (old_cursor.lnum <= VIsual.lnum && *p_sel == 'e')
7183 ++right; 7129 ++right;
7184 coladvance(right); 7130 coladvance(right);
7216 { 7162 {
7217 if (!curbuf->b_p_ma) 7163 if (!curbuf->b_p_ma)
7218 emsg(_(e_modifiable)); 7164 emsg(_(e_modifiable));
7219 else 7165 else
7220 { 7166 {
7221 #ifdef FEAT_VIRTUALEDIT
7222 if (virtual_active()) 7167 if (virtual_active())
7223 coladvance(getviscol()); 7168 coladvance(getviscol());
7224 #endif
7225 invoke_edit(cap, FALSE, cap->arg ? 'V' : 'R', FALSE); 7169 invoke_edit(cap, FALSE, cap->arg ? 'V' : 'R', FALSE);
7226 } 7170 }
7227 } 7171 }
7228 } 7172 }
7229 7173
7247 { 7191 {
7248 if (cap->extra_char == Ctrl_V) /* get another character */ 7192 if (cap->extra_char == Ctrl_V) /* get another character */
7249 cap->extra_char = get_literal(); 7193 cap->extra_char = get_literal();
7250 stuffcharReadbuff(cap->extra_char); 7194 stuffcharReadbuff(cap->extra_char);
7251 stuffcharReadbuff(ESC); 7195 stuffcharReadbuff(ESC);
7252 #ifdef FEAT_VIRTUALEDIT
7253 if (virtual_active()) 7196 if (virtual_active())
7254 coladvance(getviscol()); 7197 coladvance(getviscol());
7255 #endif
7256 invoke_edit(cap, TRUE, 'v', FALSE); 7198 invoke_edit(cap, TRUE, 'v', FALSE);
7257 } 7199 }
7258 } 7200 }
7259 } 7201 }
7260 7202
7522 check_cursor(); 7464 check_cursor();
7523 } 7465 }
7524 else 7466 else
7525 nv_cursormark(cap, cap->arg, pos); 7467 nv_cursormark(cap, cap->arg, pos);
7526 7468
7527 #ifdef FEAT_VIRTUALEDIT
7528 /* May need to clear the coladd that a mark includes. */ 7469 /* May need to clear the coladd that a mark includes. */
7529 if (!virtual_active()) 7470 if (!virtual_active())
7530 curwin->w_cursor.coladd = 0; 7471 curwin->w_cursor.coladd = 0;
7531 #endif
7532 check_cursor_col(); 7472 check_cursor_col();
7533 #ifdef FEAT_FOLDING 7473 #ifdef FEAT_FOLDING
7534 if (cap->oap->op_type == OP_NOP 7474 if (cap->oap->op_type == OP_NOP
7535 && pos != NULL 7475 && pos != NULL
7536 && (pos == (pos_T *)-1 || !EQUAL_POS(old_cursor, *pos)) 7476 && (pos == (pos_T *)-1 || !EQUAL_POS(old_cursor, *pos))
7759 #endif 7699 #endif
7760 7700
7761 VIsual_mode = c; 7701 VIsual_mode = c;
7762 VIsual_active = TRUE; 7702 VIsual_active = TRUE;
7763 VIsual_reselect = TRUE; 7703 VIsual_reselect = TRUE;
7764 #ifdef FEAT_VIRTUALEDIT 7704
7765 /* Corner case: the 0 position in a tab may change when going into 7705 // Corner case: the 0 position in a tab may change when going into
7766 * virtualedit. Recalculate curwin->w_cursor to avoid bad hilighting. 7706 // virtualedit. Recalculate curwin->w_cursor to avoid bad hilighting.
7767 */
7768 if (c == Ctrl_V && (ve_flags & VE_BLOCK) && gchar_cursor() == TAB) 7707 if (c == Ctrl_V && (ve_flags & VE_BLOCK) && gchar_cursor() == TAB)
7769 { 7708 {
7770 validate_virtcol(); 7709 validate_virtcol();
7771 coladvance(curwin->w_virtcol); 7710 coladvance(curwin->w_virtcol);
7772 } 7711 }
7773 #endif
7774 VIsual = curwin->w_cursor; 7712 VIsual = curwin->w_cursor;
7775 7713
7776 #ifdef FEAT_FOLDING 7714 #ifdef FEAT_FOLDING
7777 foldAdjustVisual(); 7715 foldAdjustVisual();
7778 #endif 7716 #endif
8210 curwin->w_cursor = curbuf->b_last_insert; 8148 curwin->w_cursor = curbuf->b_last_insert;
8211 check_cursor_lnum(); 8149 check_cursor_lnum();
8212 i = (int)STRLEN(ml_get_curline()); 8150 i = (int)STRLEN(ml_get_curline());
8213 if (curwin->w_cursor.col > (colnr_T)i) 8151 if (curwin->w_cursor.col > (colnr_T)i)
8214 { 8152 {
8215 #ifdef FEAT_VIRTUALEDIT
8216 if (virtual_active()) 8153 if (virtual_active())
8217 curwin->w_cursor.coladd += curwin->w_cursor.col - i; 8154 curwin->w_cursor.coladd += curwin->w_cursor.col - i;
8218 #endif
8219 curwin->w_cursor.col = i; 8155 curwin->w_cursor.col = i;
8220 } 8156 }
8221 } 8157 }
8222 cap->cmdchar = 'i'; 8158 cap->cmdchar = 'i';
8223 nv_edit(cap); 8159 nv_edit(cap);
8771 * - not in Visual mode or 'selection' is "o" 8707 * - not in Visual mode or 'selection' is "o"
8772 * - 'virtualedit' is not "all" and not "onemore". 8708 * - 'virtualedit' is not "all" and not "onemore".
8773 */ 8709 */
8774 if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL 8710 if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL
8775 && (!VIsual_active || *p_sel == 'o') 8711 && (!VIsual_active || *p_sel == 'o')
8776 #ifdef FEAT_VIRTUALEDIT 8712 && !virtual_active() && (ve_flags & VE_ONEMORE) == 0)
8777 && !virtual_active() && (ve_flags & VE_ONEMORE) == 0
8778 #endif
8779 )
8780 { 8713 {
8781 --curwin->w_cursor.col; 8714 --curwin->w_cursor.col;
8782 /* prevent cursor from moving on the trail byte */ 8715 /* prevent cursor from moving on the trail byte */
8783 if (has_mbyte) 8716 if (has_mbyte)
8784 mb_adjust_cursor(); 8717 mb_adjust_cursor();
8835 { 8768 {
8836 if (LT_POS(VIsual, curwin->w_cursor)) 8769 if (LT_POS(VIsual, curwin->w_cursor))
8837 pp = &curwin->w_cursor; 8770 pp = &curwin->w_cursor;
8838 else 8771 else
8839 pp = &VIsual; 8772 pp = &VIsual;
8840 #ifdef FEAT_VIRTUALEDIT
8841 if (pp->coladd > 0) 8773 if (pp->coladd > 0)
8842 --pp->coladd; 8774 --pp->coladd;
8843 else 8775 else
8844 #endif
8845 if (pp->col > 0) 8776 if (pp->col > 0)
8846 { 8777 {
8847 --pp->col; 8778 --pp->col;
8848 mb_adjustpos(curbuf, pp); 8779 mb_adjustpos(curbuf, pp);
8849 } 8780 }
9075 { 9006 {
9076 switch (cap->cmdchar) 9007 switch (cap->cmdchar)
9077 { 9008 {
9078 case 'A': /* "A"ppend after the line */ 9009 case 'A': /* "A"ppend after the line */
9079 curwin->w_set_curswant = TRUE; 9010 curwin->w_set_curswant = TRUE;
9080 #ifdef FEAT_VIRTUALEDIT
9081 if (ve_flags == VE_ALL) 9011 if (ve_flags == VE_ALL)
9082 { 9012 {
9083 int save_State = State; 9013 int save_State = State;
9084 9014
9085 /* Pretend Insert mode here to allow the cursor on the 9015 /* Pretend Insert mode here to allow the cursor on the
9087 State = INSERT; 9017 State = INSERT;
9088 coladvance((colnr_T)MAXCOL); 9018 coladvance((colnr_T)MAXCOL);
9089 State = save_State; 9019 State = save_State;
9090 } 9020 }
9091 else 9021 else
9092 #endif
9093 curwin->w_cursor.col += (colnr_T)STRLEN(ml_get_cursor()); 9022 curwin->w_cursor.col += (colnr_T)STRLEN(ml_get_cursor());
9094 break; 9023 break;
9095 9024
9096 case 'I': /* "I"nsert before the first non-blank */ 9025 case 'I': /* "I"nsert before the first non-blank */
9097 if (vim_strchr(p_cpo, CPO_INSEND) == NULL) 9026 if (vim_strchr(p_cpo, CPO_INSEND) == NULL)
9106 if (curwin->w_cursor.col == 0) 9035 if (curwin->w_cursor.col == 0)
9107 break; 9036 break;
9108 /* FALLTHROUGH */ 9037 /* FALLTHROUGH */
9109 9038
9110 case 'a': /* "a"ppend is like "i"nsert on the next character. */ 9039 case 'a': /* "a"ppend is like "i"nsert on the next character. */
9111 #ifdef FEAT_VIRTUALEDIT
9112 /* increment coladd when in virtual space, increment the 9040 /* increment coladd when in virtual space, increment the
9113 * column otherwise, also to append after an unprintable char */ 9041 * column otherwise, also to append after an unprintable char */
9114 if (virtual_active() 9042 if (virtual_active()
9115 && (curwin->w_cursor.coladd > 0 9043 && (curwin->w_cursor.coladd > 0
9116 || *ml_get_cursor() == NUL 9044 || *ml_get_cursor() == NUL
9117 || *ml_get_cursor() == TAB)) 9045 || *ml_get_cursor() == TAB))
9118 curwin->w_cursor.coladd++; 9046 curwin->w_cursor.coladd++;
9119 else 9047 else if (*ml_get_cursor() != NUL)
9120 #endif
9121 if (*ml_get_cursor() != NUL)
9122 inc_cursor(); 9048 inc_cursor();
9123 break; 9049 break;
9124 } 9050 }
9125 9051
9126 #ifdef FEAT_VIRTUALEDIT
9127 if (curwin->w_cursor.coladd && cap->cmdchar != 'A') 9052 if (curwin->w_cursor.coladd && cap->cmdchar != 'A')
9128 { 9053 {
9129 int save_State = State; 9054 int save_State = State;
9130 9055
9131 /* Pretend Insert mode here to allow the cursor on the 9056 /* Pretend Insert mode here to allow the cursor on the
9132 * character past the end of the line */ 9057 * character past the end of the line */
9133 State = INSERT; 9058 State = INSERT;
9134 coladvance(getviscol()); 9059 coladvance(getviscol());
9135 State = save_State; 9060 State = save_State;
9136 } 9061 }
9137 #endif
9138 9062
9139 invoke_edit(cap, FALSE, cap->cmdchar, FALSE); 9063 invoke_edit(cap, FALSE, cap->cmdchar, FALSE);
9140 } 9064 }
9141 else if (cap->cmdchar == K_PS) 9065 else if (cap->cmdchar == K_PS)
9142 /* drop the pasted text */ 9066 /* drop the pasted text */