Mercurial > hg > RemoteEditor > vim7
comparison src/normal.c @ 48:67300faee616 v7-3-618
v7-3-618
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 01 Aug 2012 18:08:28 +0900 |
parents | c16898406ff2 |
children |
comparison
equal
deleted
inserted
replaced
47:6c0584ec21b1 | 48:67300faee616 |
---|---|
18 /* | 18 /* |
19 * The Visual area is remembered for reselection. | 19 * The Visual area is remembered for reselection. |
20 */ | 20 */ |
21 static int resel_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */ | 21 static int resel_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */ |
22 static linenr_T resel_VIsual_line_count; /* number of lines */ | 22 static linenr_T resel_VIsual_line_count; /* number of lines */ |
23 static colnr_T resel_VIsual_col; /* nr of cols or end col */ | 23 static colnr_T resel_VIsual_vcol; /* nr of cols or end col */ |
24 | 24 |
25 static int restart_VIsual_select = 0; | 25 static int restart_VIsual_select = 0; |
26 #endif | 26 #endif |
27 | 27 |
28 #ifdef FEAT_EVAL | |
29 static void set_vcount_ca __ARGS((cmdarg_T *cap, int *set_prevcount)); | |
30 #endif | |
28 static int | 31 static int |
29 # ifdef __BORLANDC__ | 32 #ifdef __BORLANDC__ |
30 _RTLENTRYF | 33 _RTLENTRYF |
31 # endif | 34 #endif |
32 nv_compare __ARGS((const void *s1, const void *s2)); | 35 nv_compare __ARGS((const void *s1, const void *s2)); |
33 static int find_command __ARGS((int cmdchar)); | 36 static int find_command __ARGS((int cmdchar)); |
34 static void op_colon __ARGS((oparg_T *oap)); | 37 static void op_colon __ARGS((oparg_T *oap)); |
35 static void op_function __ARGS((oparg_T *oap)); | 38 static void op_function __ARGS((oparg_T *oap)); |
36 #if defined(FEAT_MOUSE) && defined(FEAT_VISUAL) | 39 #if defined(FEAT_MOUSE) && defined(FEAT_VISUAL) |
646 State = NORMAL_BUSY; | 649 State = NORMAL_BUSY; |
647 #ifdef USE_ON_FLY_SCROLL | 650 #ifdef USE_ON_FLY_SCROLL |
648 dont_scroll = FALSE; /* allow scrolling here */ | 651 dont_scroll = FALSE; /* allow scrolling here */ |
649 #endif | 652 #endif |
650 | 653 |
654 #ifdef FEAT_EVAL | |
655 /* Set v:count here, when called from main() and not a stuffed | |
656 * command, so that v:count can be used in an expression mapping | |
657 * when there is no count. */ | |
658 if (toplevel && stuff_empty()) | |
659 set_vcount_ca(&ca, &set_prevcount); | |
660 #endif | |
661 | |
651 /* | 662 /* |
652 * Get the command character from the user. | 663 * Get the command character from the user. |
653 */ | 664 */ |
654 c = safe_vgetc(); | 665 c = safe_vgetc(); |
655 LANGMAP_ADJUST(c, TRUE); | 666 LANGMAP_ADJUST(c, TRUE); |
723 #ifdef FEAT_EVAL | 734 #ifdef FEAT_EVAL |
724 /* Set v:count here, when called from main() and not a stuffed | 735 /* Set v:count here, when called from main() and not a stuffed |
725 * command, so that v:count can be used in an expression mapping | 736 * command, so that v:count can be used in an expression mapping |
726 * right after the count. */ | 737 * right after the count. */ |
727 if (toplevel && stuff_empty()) | 738 if (toplevel && stuff_empty()) |
728 { | 739 set_vcount_ca(&ca, &set_prevcount); |
729 long count = ca.count0; | |
730 | |
731 /* multiply with ca.opcount the same way as below */ | |
732 if (ca.opcount != 0) | |
733 count = ca.opcount * (count == 0 ? 1 : count); | |
734 set_vcount(count, count == 0 ? 1 : count, set_prevcount); | |
735 set_prevcount = FALSE; /* only set v:prevcount once */ | |
736 } | |
737 #endif | 740 #endif |
738 if (ctrl_w) | 741 if (ctrl_w) |
739 { | 742 { |
740 ++no_mapping; | 743 ++no_mapping; |
741 ++allow_keys; /* no mapping for nchar, but keys */ | 744 ++allow_keys; /* no mapping for nchar, but keys */ |
1197 && !oap->op_type | 1200 && !oap->op_type |
1198 && (idx < 0 || !(nv_cmds[idx].cmd_flags & NV_KEEPREG))) | 1201 && (idx < 0 || !(nv_cmds[idx].cmd_flags & NV_KEEPREG))) |
1199 { | 1202 { |
1200 clearop(oap); | 1203 clearop(oap); |
1201 #ifdef FEAT_EVAL | 1204 #ifdef FEAT_EVAL |
1202 set_reg_var('"'); | 1205 { |
1206 int regname = 0; | |
1207 | |
1208 /* Adjust the register according to 'clipboard', so that when | |
1209 * "unnamed" is present it becomes '*' or '+' instead of '"'. */ | |
1210 # ifdef FEAT_CLIPBOARD | |
1211 adjust_clip_reg(®name); | |
1212 # endif | |
1213 set_reg_var(regname); | |
1214 } | |
1203 #endif | 1215 #endif |
1204 } | 1216 } |
1205 | 1217 |
1206 #ifdef FEAT_VISUAL | 1218 #ifdef FEAT_VISUAL |
1207 /* Get the length of mapped chars again after typing a count, second | 1219 /* Get the length of mapped chars again after typing a count, second |
1384 | 1396 |
1385 /* Save count before an operator for next time. */ | 1397 /* Save count before an operator for next time. */ |
1386 opcount = ca.opcount; | 1398 opcount = ca.opcount; |
1387 } | 1399 } |
1388 | 1400 |
1401 #ifdef FEAT_EVAL | |
1402 /* | |
1403 * Set v:count and v:count1 according to "cap". | |
1404 * Set v:prevcount only when "set_prevcount" is TRUE. | |
1405 */ | |
1406 static void | |
1407 set_vcount_ca(cap, set_prevcount) | |
1408 cmdarg_T *cap; | |
1409 int *set_prevcount; | |
1410 { | |
1411 long count = cap->count0; | |
1412 | |
1413 /* multiply with cap->opcount the same way as above */ | |
1414 if (cap->opcount != 0) | |
1415 count = cap->opcount * (count == 0 ? 1 : count); | |
1416 set_vcount(count, count == 0 ? 1 : count, *set_prevcount); | |
1417 *set_prevcount = FALSE; /* only set v:prevcount once */ | |
1418 } | |
1419 #endif | |
1420 | |
1389 /* | 1421 /* |
1390 * Handle an operator after visual mode or when the movement is finished | 1422 * Handle an operator after visual mode or when the movement is finished |
1391 */ | 1423 */ |
1392 void | 1424 void |
1393 do_pending_operator(cap, old_col, gui_yank) | 1425 do_pending_operator(cap, old_col, gui_yank) |
1402 | 1434 |
1403 #ifdef FEAT_VISUAL | 1435 #ifdef FEAT_VISUAL |
1404 /* The visual area is remembered for redo */ | 1436 /* The visual area is remembered for redo */ |
1405 static int redo_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */ | 1437 static int redo_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */ |
1406 static linenr_T redo_VIsual_line_count; /* number of lines */ | 1438 static linenr_T redo_VIsual_line_count; /* number of lines */ |
1407 static colnr_T redo_VIsual_col; /* number of cols or end column */ | 1439 static colnr_T redo_VIsual_vcol; /* number of cols or end column */ |
1408 static long redo_VIsual_count; /* count for Visual operator */ | 1440 static long redo_VIsual_count; /* count for Visual operator */ |
1409 # ifdef FEAT_VIRTUALEDIT | 1441 # ifdef FEAT_VIRTUALEDIT |
1410 int include_line_break = FALSE; | 1442 int include_line_break = FALSE; |
1411 # endif | 1443 # endif |
1412 #endif | 1444 #endif |
1417 * on it and lose it forever. | 1449 * on it and lose it forever. |
1418 * Don't do it if a specific register was specified, so that ""x"*P works. | 1450 * Don't do it if a specific register was specified, so that ""x"*P works. |
1419 * This could call do_pending_operator() recursively, but that's OK | 1451 * This could call do_pending_operator() recursively, but that's OK |
1420 * because gui_yank will be TRUE for the nested call. | 1452 * because gui_yank will be TRUE for the nested call. |
1421 */ | 1453 */ |
1422 if (clip_star.available | 1454 if ((clip_star.available || clip_plus.available) |
1423 && oap->op_type != OP_NOP | 1455 && oap->op_type != OP_NOP |
1424 && !gui_yank | 1456 && !gui_yank |
1425 # ifdef FEAT_VISUAL | 1457 # ifdef FEAT_VISUAL |
1426 && VIsual_active | 1458 && VIsual_active |
1427 && !redo_VIsual_busy | 1459 && !redo_VIsual_busy |
1515 } | 1547 } |
1516 | 1548 |
1517 #ifdef FEAT_VISUAL | 1549 #ifdef FEAT_VISUAL |
1518 if (redo_VIsual_busy) | 1550 if (redo_VIsual_busy) |
1519 { | 1551 { |
1552 /* Redo of an operation on a Visual area. Use the same size from | |
1553 * redo_VIsual_line_count and redo_VIsual_vcol. */ | |
1520 oap->start = curwin->w_cursor; | 1554 oap->start = curwin->w_cursor; |
1521 curwin->w_cursor.lnum += redo_VIsual_line_count - 1; | 1555 curwin->w_cursor.lnum += redo_VIsual_line_count - 1; |
1522 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | 1556 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) |
1523 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | 1557 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; |
1524 VIsual_mode = redo_VIsual_mode; | 1558 VIsual_mode = redo_VIsual_mode; |
1525 if (VIsual_mode == 'v') | 1559 if (redo_VIsual_vcol == MAXCOL || VIsual_mode == 'v') |
1526 { | 1560 { |
1527 if (redo_VIsual_line_count <= 1) | 1561 if (VIsual_mode == 'v') |
1528 curwin->w_cursor.col += redo_VIsual_col - 1; | 1562 { |
1563 if (redo_VIsual_line_count <= 1) | |
1564 { | |
1565 validate_virtcol(); | |
1566 curwin->w_curswant = | |
1567 curwin->w_virtcol + redo_VIsual_vcol - 1; | |
1568 } | |
1569 else | |
1570 curwin->w_curswant = redo_VIsual_vcol; | |
1571 } | |
1529 else | 1572 else |
1530 curwin->w_cursor.col = redo_VIsual_col; | 1573 { |
1531 } | 1574 curwin->w_curswant = MAXCOL; |
1532 if (redo_VIsual_col == MAXCOL) | 1575 } |
1533 { | 1576 coladvance(curwin->w_curswant); |
1534 curwin->w_curswant = MAXCOL; | |
1535 coladvance((colnr_T)MAXCOL); | |
1536 } | 1577 } |
1537 cap->count0 = redo_VIsual_count; | 1578 cap->count0 = redo_VIsual_count; |
1538 if (redo_VIsual_count != 0) | 1579 if (redo_VIsual_count != 0) |
1539 cap->count1 = redo_VIsual_count; | 1580 cap->count1 = redo_VIsual_count; |
1540 else | 1581 else |
1676 if (end > oap->end_vcol) | 1717 if (end > oap->end_vcol) |
1677 oap->end_vcol = end; | 1718 oap->end_vcol = end; |
1678 } | 1719 } |
1679 } | 1720 } |
1680 else if (redo_VIsual_busy) | 1721 else if (redo_VIsual_busy) |
1681 oap->end_vcol = oap->start_vcol + redo_VIsual_col - 1; | 1722 oap->end_vcol = oap->start_vcol + redo_VIsual_vcol - 1; |
1682 /* | 1723 /* |
1683 * Correct oap->end.col and oap->start.col to be the | 1724 * Correct oap->end.col and oap->start.col to be the |
1684 * upper-left and lower-right corner of the block area. | 1725 * upper-left and lower-right corner of the block area. |
1685 * | 1726 * |
1686 * (Actually, this does convert column positions into character | 1727 * (Actually, this does convert column positions into character |
1701 * Prepare to reselect and redo Visual: this is based on the | 1742 * Prepare to reselect and redo Visual: this is based on the |
1702 * size of the Visual text | 1743 * size of the Visual text |
1703 */ | 1744 */ |
1704 resel_VIsual_mode = VIsual_mode; | 1745 resel_VIsual_mode = VIsual_mode; |
1705 if (curwin->w_curswant == MAXCOL) | 1746 if (curwin->w_curswant == MAXCOL) |
1706 resel_VIsual_col = MAXCOL; | 1747 resel_VIsual_vcol = MAXCOL; |
1707 else if (VIsual_mode == Ctrl_V) | |
1708 resel_VIsual_col = oap->end_vcol - oap->start_vcol + 1; | |
1709 else if (oap->line_count > 1) | |
1710 resel_VIsual_col = oap->end.col; | |
1711 else | 1748 else |
1712 resel_VIsual_col = oap->end.col - oap->start.col + 1; | 1749 { |
1750 if (VIsual_mode != Ctrl_V) | |
1751 getvvcol(curwin, &(oap->end), | |
1752 NULL, NULL, &oap->end_vcol); | |
1753 if (VIsual_mode == Ctrl_V || oap->line_count <= 1) | |
1754 { | |
1755 if (VIsual_mode != Ctrl_V) | |
1756 getvvcol(curwin, &(oap->start), | |
1757 &oap->start_vcol, NULL, NULL); | |
1758 resel_VIsual_vcol = oap->end_vcol - oap->start_vcol + 1; | |
1759 } | |
1760 else | |
1761 resel_VIsual_vcol = oap->end_vcol; | |
1762 } | |
1713 resel_VIsual_line_count = oap->line_count; | 1763 resel_VIsual_line_count = oap->line_count; |
1714 } | 1764 } |
1715 | 1765 |
1716 /* can't redo yank (unless 'y' is in 'cpoptions') and ":" */ | 1766 /* can't redo yank (unless 'y' is in 'cpoptions') and ":" */ |
1717 if ((vim_strchr(p_cpo, CPO_YANK) != NULL || oap->op_type != OP_YANK) | 1767 if ((vim_strchr(p_cpo, CPO_YANK) != NULL || oap->op_type != OP_YANK) |
1728 && oap->motion_force == NUL | 1778 && oap->motion_force == NUL |
1729 ) | 1779 ) |
1730 { | 1780 { |
1731 /* Prepare for redoing. Only use the nchar field for "r", | 1781 /* Prepare for redoing. Only use the nchar field for "r", |
1732 * otherwise it might be the second char of the operator. */ | 1782 * otherwise it might be the second char of the operator. */ |
1733 prep_redo(oap->regname, 0L, NUL, 'v', | 1783 if (cap->cmdchar == 'g' && (cap->nchar == 'n' |
1734 get_op_char(oap->op_type), | 1784 || cap->nchar == 'N')) |
1735 get_extra_op_char(oap->op_type), | 1785 /* "gn" and "gN" are a bit different */ |
1736 oap->op_type == OP_REPLACE ? cap->nchar : NUL); | 1786 prep_redo(oap->regname, 0L, NUL, cap->cmdchar, cap->nchar, |
1787 get_op_char(oap->op_type), | |
1788 get_extra_op_char(oap->op_type)); | |
1789 else | |
1790 prep_redo(oap->regname, 0L, NUL, 'v', | |
1791 get_op_char(oap->op_type), | |
1792 get_extra_op_char(oap->op_type), | |
1793 oap->op_type == OP_REPLACE | |
1794 ? cap->nchar : NUL); | |
1737 if (!redo_VIsual_busy) | 1795 if (!redo_VIsual_busy) |
1738 { | 1796 { |
1739 redo_VIsual_mode = resel_VIsual_mode; | 1797 redo_VIsual_mode = resel_VIsual_mode; |
1740 redo_VIsual_col = resel_VIsual_col; | 1798 redo_VIsual_vcol = resel_VIsual_vcol; |
1741 redo_VIsual_line_count = resel_VIsual_line_count; | 1799 redo_VIsual_line_count = resel_VIsual_line_count; |
1742 redo_VIsual_count = cap->count0; | 1800 redo_VIsual_count = cap->count0; |
1743 } | 1801 } |
1744 } | 1802 } |
1745 | 1803 |
1761 # endif | 1819 # endif |
1762 ) | 1820 ) |
1763 { | 1821 { |
1764 oap->inclusive = FALSE; | 1822 oap->inclusive = FALSE; |
1765 /* Try to include the newline, unless it's an operator | 1823 /* Try to include the newline, unless it's an operator |
1766 * that works on lines only */ | 1824 * that works on lines only. */ |
1767 if (*p_sel != 'o' | 1825 if (*p_sel != 'o' && !op_on_lines(oap->op_type)) |
1768 && !op_on_lines(oap->op_type) | |
1769 && oap->end.lnum < curbuf->b_ml.ml_line_count) | |
1770 { | 1826 { |
1771 ++oap->end.lnum; | 1827 if (oap->end.lnum < curbuf->b_ml.ml_line_count) |
1772 oap->end.col = 0; | 1828 { |
1829 ++oap->end.lnum; | |
1830 oap->end.col = 0; | |
1773 # ifdef FEAT_VIRTUALEDIT | 1831 # ifdef FEAT_VIRTUALEDIT |
1774 oap->end.coladd = 0; | 1832 oap->end.coladd = 0; |
1775 # endif | 1833 # endif |
1776 ++oap->line_count; | 1834 ++oap->line_count; |
1835 } | |
1836 else | |
1837 { | |
1838 /* Cannot move below the last line, make the op | |
1839 * inclusive to tell the operation to include the | |
1840 * line break. */ | |
1841 oap->inclusive = TRUE; | |
1842 } | |
1777 } | 1843 } |
1778 } | 1844 } |
1779 } | 1845 } |
1780 | 1846 |
1781 redo_VIsual_busy = FALSE; | 1847 redo_VIsual_busy = FALSE; |
1908 if (curwin->w_cursor.lnum + oap->line_count - 1 > | 1974 if (curwin->w_cursor.lnum + oap->line_count - 1 > |
1909 curbuf->b_ml.ml_line_count) | 1975 curbuf->b_ml.ml_line_count) |
1910 beep_flush(); | 1976 beep_flush(); |
1911 else | 1977 else |
1912 { | 1978 { |
1913 (void)do_join(oap->line_count, oap->op_type == OP_JOIN, TRUE); | 1979 (void)do_join(oap->line_count, oap->op_type == OP_JOIN, TRUE, TRUE); |
1914 auto_format(FALSE, TRUE); | 1980 auto_format(FALSE, TRUE); |
1915 } | 1981 } |
1916 break; | 1982 break; |
1917 | 1983 |
1918 case OP_DELETE: | 1984 case OP_DELETE: |
1919 #ifdef FEAT_VISUAL | 1985 #ifdef FEAT_VISUAL |
1920 VIsual_reselect = FALSE; /* don't reselect now */ | 1986 VIsual_reselect = FALSE; /* don't reselect now */ |
1921 #endif | 1987 #endif |
1922 if (empty_region_error) | 1988 if (empty_region_error) |
1989 { | |
1923 vim_beep(); | 1990 vim_beep(); |
1991 CancelRedo(); | |
1992 } | |
1924 else | 1993 else |
1925 { | 1994 { |
1926 (void)op_delete(oap); | 1995 (void)op_delete(oap); |
1927 if (oap->motion_type == MLINE && has_format_option(FO_AUTO)) | 1996 if (oap->motion_type == MLINE && has_format_option(FO_AUTO)) |
1928 u_save_cursor(); /* cursor line wasn't saved yet */ | 1997 u_save_cursor(); /* cursor line wasn't saved yet */ |
1932 | 2001 |
1933 case OP_YANK: | 2002 case OP_YANK: |
1934 if (empty_region_error) | 2003 if (empty_region_error) |
1935 { | 2004 { |
1936 if (!gui_yank) | 2005 if (!gui_yank) |
2006 { | |
1937 vim_beep(); | 2007 vim_beep(); |
2008 CancelRedo(); | |
2009 } | |
1938 } | 2010 } |
1939 else | 2011 else |
1940 (void)op_yank(oap, FALSE, !gui_yank); | 2012 (void)op_yank(oap, FALSE, !gui_yank); |
1941 check_cursor_col(); | 2013 check_cursor_col(); |
1942 break; | 2014 break; |
1944 case OP_CHANGE: | 2016 case OP_CHANGE: |
1945 #ifdef FEAT_VISUAL | 2017 #ifdef FEAT_VISUAL |
1946 VIsual_reselect = FALSE; /* don't reselect now */ | 2018 VIsual_reselect = FALSE; /* don't reselect now */ |
1947 #endif | 2019 #endif |
1948 if (empty_region_error) | 2020 if (empty_region_error) |
2021 { | |
1949 vim_beep(); | 2022 vim_beep(); |
2023 CancelRedo(); | |
2024 } | |
1950 else | 2025 else |
1951 { | 2026 { |
1952 /* This is a new edit command, not a restart. Need to | 2027 /* This is a new edit command, not a restart. Need to |
1953 * remember it to make 'insertmode' work with mappings for | 2028 * remember it to make 'insertmode' work with mappings for |
1954 * Visual mode. But do this only once and not when typed and | 2029 * Visual mode. But do this only once and not when typed and |
2006 case OP_TILDE: | 2081 case OP_TILDE: |
2007 case OP_UPPER: | 2082 case OP_UPPER: |
2008 case OP_LOWER: | 2083 case OP_LOWER: |
2009 case OP_ROT13: | 2084 case OP_ROT13: |
2010 if (empty_region_error) | 2085 if (empty_region_error) |
2086 { | |
2011 vim_beep(); | 2087 vim_beep(); |
2088 CancelRedo(); | |
2089 } | |
2012 else | 2090 else |
2013 op_tilde(oap); | 2091 op_tilde(oap); |
2014 check_cursor_col(); | 2092 check_cursor_col(); |
2015 break; | 2093 break; |
2016 | 2094 |
2039 #ifdef FEAT_VISUAL | 2117 #ifdef FEAT_VISUAL |
2040 VIsual_reselect = FALSE; /* don't reselect now */ | 2118 VIsual_reselect = FALSE; /* don't reselect now */ |
2041 #endif | 2119 #endif |
2042 #ifdef FEAT_VISUALEXTRA | 2120 #ifdef FEAT_VISUALEXTRA |
2043 if (empty_region_error) | 2121 if (empty_region_error) |
2122 { | |
2044 vim_beep(); | 2123 vim_beep(); |
2124 CancelRedo(); | |
2125 } | |
2045 else | 2126 else |
2046 { | 2127 { |
2047 /* This is a new edit command, not a restart. Need to | 2128 /* This is a new edit command, not a restart. Need to |
2048 * remember it to make 'insertmode' work with mappings for | 2129 * remember it to make 'insertmode' work with mappings for |
2049 * Visual mode. But do this only once. */ | 2130 * Visual mode. But do this only once. */ |
2069 VIsual_reselect = FALSE; /* don't reselect now */ | 2150 VIsual_reselect = FALSE; /* don't reselect now */ |
2070 #endif | 2151 #endif |
2071 #ifdef FEAT_VISUALEXTRA | 2152 #ifdef FEAT_VISUALEXTRA |
2072 if (empty_region_error) | 2153 if (empty_region_error) |
2073 #endif | 2154 #endif |
2155 { | |
2074 vim_beep(); | 2156 vim_beep(); |
2157 CancelRedo(); | |
2158 } | |
2075 #ifdef FEAT_VISUALEXTRA | 2159 #ifdef FEAT_VISUALEXTRA |
2076 else | 2160 else |
2077 op_replace(oap, cap->nchar); | 2161 op_replace(oap, cap->nchar); |
2078 #endif | 2162 #endif |
2079 break; | 2163 break; |
2201 op_function(oap) | 2285 op_function(oap) |
2202 oparg_T *oap UNUSED; | 2286 oparg_T *oap UNUSED; |
2203 { | 2287 { |
2204 #ifdef FEAT_EVAL | 2288 #ifdef FEAT_EVAL |
2205 char_u *(argv[1]); | 2289 char_u *(argv[1]); |
2290 int save_virtual_op = virtual_op; | |
2206 | 2291 |
2207 if (*p_opfunc == NUL) | 2292 if (*p_opfunc == NUL) |
2208 EMSG(_("E774: 'operatorfunc' is empty")); | 2293 EMSG(_("E774: 'operatorfunc' is empty")); |
2209 else | 2294 else |
2210 { | 2295 { |
2219 argv[0] = (char_u *)"block"; | 2304 argv[0] = (char_u *)"block"; |
2220 else if (oap->motion_type == MLINE) | 2305 else if (oap->motion_type == MLINE) |
2221 argv[0] = (char_u *)"line"; | 2306 argv[0] = (char_u *)"line"; |
2222 else | 2307 else |
2223 argv[0] = (char_u *)"char"; | 2308 argv[0] = (char_u *)"char"; |
2309 | |
2310 /* Reset virtual_op so that 'virtualedit' can be changed in the | |
2311 * function. */ | |
2312 virtual_op = MAYBE; | |
2313 | |
2224 (void)call_func_retnr(p_opfunc, 1, argv, FALSE); | 2314 (void)call_func_retnr(p_opfunc, 1, argv, FALSE); |
2315 | |
2316 virtual_op = save_virtual_op; | |
2225 } | 2317 } |
2226 #else | 2318 #else |
2227 EMSG(_("E775: Eval feature not available")); | 2319 EMSG(_("E775: Eval feature not available")); |
2228 #endif | 2320 #endif |
2229 } | 2321 } |
4340 t = OK; | 4432 t = OK; |
4341 } | 4433 } |
4342 break; | 4434 break; |
4343 } | 4435 } |
4344 #ifdef FEAT_COMMENTS | 4436 #ifdef FEAT_COMMENTS |
4345 if (get_leader_len(ml_get_curline(), NULL, FALSE) > 0) | 4437 if (get_leader_len(ml_get_curline(), NULL, FALSE, TRUE) > 0) |
4346 { | 4438 { |
4347 /* Ignore this line, continue at start of next line. */ | 4439 /* Ignore this line, continue at start of next line. */ |
4348 ++curwin->w_cursor.lnum; | 4440 ++curwin->w_cursor.lnum; |
4349 curwin->w_cursor.col = 0; | 4441 curwin->w_cursor.col = 0; |
4350 continue; | 4442 continue; |
4499 retval = FAIL; | 4591 retval = FAIL; |
4500 break; | 4592 break; |
4501 } | 4593 } |
4502 curwin->w_cursor.lnum++; | 4594 curwin->w_cursor.lnum++; |
4503 curwin->w_curswant %= width2; | 4595 curwin->w_curswant %= width2; |
4596 linelen = linetabsize(ml_get_curline()); | |
4504 } | 4597 } |
4505 } | 4598 } |
4506 } | 4599 } |
4507 #ifdef FEAT_VERTSPLIT | 4600 #ifdef FEAT_VERTSPLIT |
4508 } | 4601 } |
6983 * multi-byte and the other way around. Also handles adding | 7076 * multi-byte and the other way around. Also handles adding |
6984 * composing characters for utf-8. */ | 7077 * composing characters for utf-8. */ |
6985 for (n = cap->count1; n > 0; --n) | 7078 for (n = cap->count1; n > 0; --n) |
6986 { | 7079 { |
6987 State = REPLACE; | 7080 State = REPLACE; |
6988 ins_char(cap->nchar); | 7081 if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) |
7082 { | |
7083 int c = ins_copychar(curwin->w_cursor.lnum | |
7084 + (cap->nchar == Ctrl_Y ? -1 : 1)); | |
7085 if (c != NUL) | |
7086 ins_char(c); | |
7087 else | |
7088 /* will be decremented further down */ | |
7089 ++curwin->w_cursor.col; | |
7090 } | |
7091 else | |
7092 ins_char(cap->nchar); | |
6989 State = old_State; | 7093 State = old_State; |
6990 if (cap->ncharC1 != 0) | 7094 if (cap->ncharC1 != 0) |
6991 ins_char(cap->ncharC1); | 7095 ins_char(cap->ncharC1); |
6992 if (cap->ncharC2 != 0) | 7096 if (cap->ncharC2 != 0) |
6993 ins_char(cap->ncharC2); | 7097 ins_char(cap->ncharC2); |
7005 * Get ptr again, because u_save and/or showmatch() will have | 7109 * Get ptr again, because u_save and/or showmatch() will have |
7006 * released the line. At the same time we let know that the | 7110 * released the line. At the same time we let know that the |
7007 * line will be changed. | 7111 * line will be changed. |
7008 */ | 7112 */ |
7009 ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE); | 7113 ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE); |
7010 ptr[curwin->w_cursor.col] = cap->nchar; | 7114 if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) |
7115 { | |
7116 int c = ins_copychar(curwin->w_cursor.lnum | |
7117 + (cap->nchar == Ctrl_Y ? -1 : 1)); | |
7118 if (c != NUL) | |
7119 ptr[curwin->w_cursor.col] = c; | |
7120 } | |
7121 else | |
7122 ptr[curwin->w_cursor.col] = cap->nchar; | |
7011 if (p_sm && msg_silent == 0) | 7123 if (p_sm && msg_silent == 0) |
7012 showmatch(cap->nchar); | 7124 showmatch(cap->nchar); |
7013 ++curwin->w_cursor.col; | 7125 ++curwin->w_cursor.col; |
7014 } | 7126 } |
7015 #ifdef FEAT_NETBEANS_INTG | 7127 #ifdef FEAT_NETBEANS_INTG |
7554 redraw_curbuf_later(INVERTED); /* update the inversion */ | 7666 redraw_curbuf_later(INVERTED); /* update the inversion */ |
7555 } | 7667 } |
7556 else /* start Visual mode */ | 7668 else /* start Visual mode */ |
7557 { | 7669 { |
7558 check_visual_highlight(); | 7670 check_visual_highlight(); |
7559 if (cap->count0) /* use previously selected part */ | 7671 if (cap->count0 > 0 && resel_VIsual_mode != NUL) |
7560 { | 7672 { |
7561 if (resel_VIsual_mode == NUL) /* there is none */ | 7673 /* use previously selected part */ |
7562 { | |
7563 beep_flush(); | |
7564 return; | |
7565 } | |
7566 VIsual = curwin->w_cursor; | 7674 VIsual = curwin->w_cursor; |
7567 | 7675 |
7568 VIsual_active = TRUE; | 7676 VIsual_active = TRUE; |
7569 VIsual_reselect = TRUE; | 7677 VIsual_reselect = TRUE; |
7570 if (!cap->arg) | 7678 if (!cap->arg) |
7588 } | 7696 } |
7589 VIsual_mode = resel_VIsual_mode; | 7697 VIsual_mode = resel_VIsual_mode; |
7590 if (VIsual_mode == 'v') | 7698 if (VIsual_mode == 'v') |
7591 { | 7699 { |
7592 if (resel_VIsual_line_count <= 1) | 7700 if (resel_VIsual_line_count <= 1) |
7593 curwin->w_cursor.col += resel_VIsual_col * cap->count0 - 1; | 7701 { |
7702 validate_virtcol(); | |
7703 curwin->w_curswant = curwin->w_virtcol | |
7704 + resel_VIsual_vcol * cap->count0 - 1; | |
7705 } | |
7594 else | 7706 else |
7595 curwin->w_cursor.col = resel_VIsual_col; | 7707 curwin->w_curswant = resel_VIsual_vcol; |
7596 check_cursor_col(); | 7708 coladvance(curwin->w_curswant); |
7597 } | 7709 } |
7598 if (resel_VIsual_col == MAXCOL) | 7710 if (resel_VIsual_vcol == MAXCOL) |
7599 { | 7711 { |
7600 curwin->w_curswant = MAXCOL; | 7712 curwin->w_curswant = MAXCOL; |
7601 coladvance((colnr_T)MAXCOL); | 7713 coladvance((colnr_T)MAXCOL); |
7602 } | 7714 } |
7603 else if (VIsual_mode == Ctrl_V) | 7715 else if (VIsual_mode == Ctrl_V) |
7604 { | 7716 { |
7605 validate_virtcol(); | 7717 validate_virtcol(); |
7606 curwin->w_curswant = curwin->w_virtcol | 7718 curwin->w_curswant = curwin->w_virtcol |
7607 + resel_VIsual_col * cap->count0 - 1; | 7719 + resel_VIsual_vcol * cap->count0 - 1; |
7608 coladvance(curwin->w_curswant); | 7720 coladvance(curwin->w_curswant); |
7609 } | 7721 } |
7610 else | 7722 else |
7611 curwin->w_set_curswant = TRUE; | 7723 curwin->w_set_curswant = TRUE; |
7612 redraw_curbuf_later(INVERTED); /* show the inversion */ | 7724 redraw_curbuf_later(INVERTED); /* show the inversion */ |
7615 { | 7727 { |
7616 if (!cap->arg) | 7728 if (!cap->arg) |
7617 /* start Select mode when 'selectmode' contains "cmd" */ | 7729 /* start Select mode when 'selectmode' contains "cmd" */ |
7618 may_start_select('c'); | 7730 may_start_select('c'); |
7619 n_start_visual_mode(cap->cmdchar); | 7731 n_start_visual_mode(cap->cmdchar); |
7732 if (VIsual_mode != 'V' && *p_sel == 'e') | |
7733 ++cap->count1; /* include one more char */ | |
7734 if (cap->count0 > 0 && --cap->count1 > 0) | |
7735 { | |
7736 /* With a count select that many characters or lines. */ | |
7737 if (VIsual_mode == 'v' || VIsual_mode == Ctrl_V) | |
7738 nv_right(cap); | |
7739 else if (VIsual_mode == 'V') | |
7740 nv_down(cap); | |
7741 } | |
7620 } | 7742 } |
7621 } | 7743 } |
7622 } | 7744 } |
7623 | 7745 |
7624 /* | 7746 /* |
7873 cap->arg = TRUE; | 7995 cap->arg = TRUE; |
7874 nv_visual(cap); | 7996 nv_visual(cap); |
7875 break; | 7997 break; |
7876 #endif /* FEAT_VISUAL */ | 7998 #endif /* FEAT_VISUAL */ |
7877 | 7999 |
8000 /* "gn", "gN" visually select next/previous search match | |
8001 * "gn" selects next match | |
8002 * "gN" selects previous match | |
8003 */ | |
8004 case 'N': | |
8005 case 'n': | |
8006 #ifdef FEAT_VISUAL | |
8007 if (!current_search(cap->count1, cap->nchar == 'n')) | |
8008 #endif | |
8009 beep_flush(); | |
8010 break; | |
8011 | |
7878 /* | 8012 /* |
7879 * "gj" and "gk" two new funny movement keys -- up and down | 8013 * "gj" and "gk" two new funny movement keys -- up and down |
7880 * movement based on *screen* line rather than *file* line. | 8014 * movement based on *screen* line rather than *file* line. |
7881 */ | 8015 */ |
7882 case 'j': | 8016 case 'j': |
8277 break; | 8411 break; |
8278 #endif | 8412 #endif |
8279 | 8413 |
8280 #ifdef FEAT_WINDOWS | 8414 #ifdef FEAT_WINDOWS |
8281 case 't': | 8415 case 't': |
8282 goto_tabpage((int)cap->count0); | 8416 if (!checkclearop(oap)) |
8417 goto_tabpage((int)cap->count0); | |
8283 break; | 8418 break; |
8284 case 'T': | 8419 case 'T': |
8285 goto_tabpage(-(int)cap->count1); | 8420 if (!checkclearop(oap)) |
8421 goto_tabpage(-(int)cap->count1); | |
8286 break; | 8422 break; |
8287 #endif | 8423 #endif |
8288 | 8424 |
8289 case '+': | 8425 case '+': |
8290 case '-': /* "g+" and "g-": undo or redo along the timeline */ | 8426 case '-': /* "g+" and "g-": undo or redo along the timeline */ |
8527 curwin->w_curswant = (colnr_T)(cap->count0 - 1); | 8663 curwin->w_curswant = (colnr_T)(cap->count0 - 1); |
8528 } | 8664 } |
8529 else | 8665 else |
8530 curwin->w_curswant = 0; | 8666 curwin->w_curswant = 0; |
8531 /* keep curswant at the column where we wanted to go, not where | 8667 /* keep curswant at the column where we wanted to go, not where |
8532 we ended; differs if line is too short */ | 8668 * we ended; differs if line is too short */ |
8533 curwin->w_set_curswant = FALSE; | 8669 curwin->w_set_curswant = FALSE; |
8534 } | 8670 } |
8535 | 8671 |
8536 /* | 8672 /* |
8537 * Handle back-word command "b" and "B". | 8673 * Handle back-word command "b" and "B". |
8739 #endif | 8875 #endif |
8740 if (pp->col > 0) | 8876 if (pp->col > 0) |
8741 { | 8877 { |
8742 --pp->col; | 8878 --pp->col; |
8743 #ifdef FEAT_MBYTE | 8879 #ifdef FEAT_MBYTE |
8744 mb_adjustpos(pp); | 8880 mb_adjustpos(curbuf, pp); |
8745 #endif | 8881 #endif |
8746 } | 8882 } |
8747 else if (pp->lnum > 1) | 8883 else if (pp->lnum > 1) |
8748 { | 8884 { |
8749 --pp->lnum; | 8885 --pp->lnum; |
9208 clearopbeep(cap->oap); /* beyond last line */ | 9344 clearopbeep(cap->oap); /* beyond last line */ |
9209 else | 9345 else |
9210 { | 9346 { |
9211 prep_redo(cap->oap->regname, cap->count0, | 9347 prep_redo(cap->oap->regname, cap->count0, |
9212 NUL, cap->cmdchar, NUL, NUL, cap->nchar); | 9348 NUL, cap->cmdchar, NUL, NUL, cap->nchar); |
9213 (void)do_join(cap->count0, cap->nchar == NUL, TRUE); | 9349 (void)do_join(cap->count0, cap->nchar == NUL, TRUE, TRUE); |
9214 } | 9350 } |
9215 } | 9351 } |
9216 } | 9352 } |
9217 | 9353 |
9218 /* | 9354 /* |
9264 was_visual = TRUE; | 9400 was_visual = TRUE; |
9265 regname = cap->oap->regname; | 9401 regname = cap->oap->regname; |
9266 # ifdef FEAT_CLIPBOARD | 9402 # ifdef FEAT_CLIPBOARD |
9267 adjust_clip_reg(®name); | 9403 adjust_clip_reg(®name); |
9268 # endif | 9404 # endif |
9269 if (regname == 0 || VIM_ISDIGIT(regname) | 9405 if (regname == 0 || regname == '"' || VIM_ISDIGIT(regname) |
9270 # ifdef FEAT_CLIPBOARD | 9406 # ifdef FEAT_CLIPBOARD |
9271 || (clip_unnamed && (regname == '*' || regname == '+')) | 9407 || (clip_unnamed && (regname == '*' || regname == '+')) |
9272 # endif | 9408 # endif |
9273 | 9409 |
9274 ) | 9410 ) |