Mercurial > vim
comparison src/change.c @ 18203:e0ec4cd7a865 v8.1.2096
patch 8.1.2096: too many #ifdefs
Commit: https://github.com/vim/vim/commit/8c96af9c05bfcac2d5ae081e098d4863db561511
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Sep 28 19:05:57 2019 +0200
patch 8.1.2096: too many #ifdefs
Problem: Too many #ifdefs.
Solution: Graduate FEAT_COMMENTS.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 28 Sep 2019 19:15:03 +0200 |
parents | 1101eacc1444 |
children | 6c3a8312486d |
comparison
equal
deleted
inserted
replaced
18202:13049de86673 | 18203:e0ec4cd7a865 |
---|---|
1412 int newcol = 0; // new cursor column | 1412 int newcol = 0; // new cursor column |
1413 int newindent = 0; // auto-indent of the new line | 1413 int newindent = 0; // auto-indent of the new line |
1414 int n; | 1414 int n; |
1415 int trunc_line = FALSE; // truncate current line afterwards | 1415 int trunc_line = FALSE; // truncate current line afterwards |
1416 int retval = FAIL; // return value | 1416 int retval = FAIL; // return value |
1417 #ifdef FEAT_COMMENTS | |
1418 int extra_len = 0; // length of p_extra string | 1417 int extra_len = 0; // length of p_extra string |
1419 int lead_len; // length of comment leader | 1418 int lead_len; // length of comment leader |
1420 char_u *lead_flags; // position in 'comments' for comment leader | 1419 char_u *lead_flags; // position in 'comments' for comment leader |
1421 char_u *leader = NULL; // copy of comment leader | 1420 char_u *leader = NULL; // copy of comment leader |
1422 #endif | |
1423 char_u *allocated = NULL; // allocated memory | 1421 char_u *allocated = NULL; // allocated memory |
1424 char_u *p; | 1422 char_u *p; |
1425 int saved_char = NUL; // init for GCC | 1423 int saved_char = NUL; // init for GCC |
1426 #if defined(FEAT_SMARTINDENT) || defined(FEAT_COMMENTS) | |
1427 pos_T *pos; | 1424 pos_T *pos; |
1428 #endif | |
1429 #ifdef FEAT_SMARTINDENT | 1425 #ifdef FEAT_SMARTINDENT |
1430 int do_si = (!p_paste && curbuf->b_p_si | 1426 int do_si = (!p_paste && curbuf->b_p_si |
1431 # ifdef FEAT_CINDENT | 1427 # ifdef FEAT_CINDENT |
1432 && !curbuf->b_p_cin | 1428 && !curbuf->b_p_cin |
1433 # endif | 1429 # endif |
1491 { | 1487 { |
1492 p = skipwhite(p_extra); | 1488 p = skipwhite(p_extra); |
1493 first_char = *p; | 1489 first_char = *p; |
1494 } | 1490 } |
1495 #endif | 1491 #endif |
1496 #ifdef FEAT_COMMENTS | |
1497 extra_len = (int)STRLEN(p_extra); | 1492 extra_len = (int)STRLEN(p_extra); |
1498 #endif | |
1499 saved_char = *p_extra; | 1493 saved_char = *p_extra; |
1500 *p_extra = NUL; | 1494 *p_extra = NUL; |
1501 } | 1495 } |
1502 | 1496 |
1503 u_clearline(); // cannot do "U" command when adding lines | 1497 u_clearline(); // cannot do "U" command when adding lines |
1542 char_u *ptr; | 1536 char_u *ptr; |
1543 char_u last_char; | 1537 char_u last_char; |
1544 | 1538 |
1545 old_cursor = curwin->w_cursor; | 1539 old_cursor = curwin->w_cursor; |
1546 ptr = saved_line; | 1540 ptr = saved_line; |
1547 # ifdef FEAT_COMMENTS | |
1548 if (flags & OPENLINE_DO_COM) | 1541 if (flags & OPENLINE_DO_COM) |
1549 lead_len = get_leader_len(ptr, NULL, FALSE, TRUE); | 1542 lead_len = get_leader_len(ptr, NULL, FALSE, TRUE); |
1550 else | 1543 else |
1551 lead_len = 0; | 1544 lead_len = 0; |
1552 # endif | |
1553 if (dir == FORWARD) | 1545 if (dir == FORWARD) |
1554 { | 1546 { |
1555 // Skip preprocessor directives, unless they are | 1547 // Skip preprocessor directives, unless they are |
1556 // recognised as comments. | 1548 // recognised as comments. |
1557 if ( | 1549 if ( lead_len == 0 && ptr[0] == '#') |
1558 # ifdef FEAT_COMMENTS | |
1559 lead_len == 0 && | |
1560 # endif | |
1561 ptr[0] == '#') | |
1562 { | 1550 { |
1563 while (ptr[0] == '#' && curwin->w_cursor.lnum > 1) | 1551 while (ptr[0] == '#' && curwin->w_cursor.lnum > 1) |
1564 ptr = ml_get(--curwin->w_cursor.lnum); | 1552 ptr = ml_get(--curwin->w_cursor.lnum); |
1565 newindent = get_indent(); | 1553 newindent = get_indent(); |
1566 } | 1554 } |
1567 # ifdef FEAT_COMMENTS | |
1568 if (flags & OPENLINE_DO_COM) | 1555 if (flags & OPENLINE_DO_COM) |
1569 lead_len = get_leader_len(ptr, NULL, FALSE, TRUE); | 1556 lead_len = get_leader_len(ptr, NULL, FALSE, TRUE); |
1570 else | 1557 else |
1571 lead_len = 0; | 1558 lead_len = 0; |
1572 if (lead_len > 0) | 1559 if (lead_len > 0) |
1598 } | 1585 } |
1599 } | 1586 } |
1600 } | 1587 } |
1601 } | 1588 } |
1602 else // Not a comment line | 1589 else // Not a comment line |
1603 # endif | |
1604 { | 1590 { |
1605 // Find last non-blank in line | 1591 // Find last non-blank in line |
1606 p = ptr + STRLEN(ptr) - 1; | 1592 p = ptr + STRLEN(ptr) - 1; |
1607 while (p > ptr && VIM_ISWHITE(*p)) | 1593 while (p > ptr && VIM_ISWHITE(*p)) |
1608 --p; | 1594 --p; |
1649 } | 1635 } |
1650 else // dir == BACKWARD | 1636 else // dir == BACKWARD |
1651 { | 1637 { |
1652 // Skip preprocessor directives, unless they are | 1638 // Skip preprocessor directives, unless they are |
1653 // recognised as comments. | 1639 // recognised as comments. |
1654 if ( | 1640 if (lead_len == 0 && ptr[0] == '#') |
1655 # ifdef FEAT_COMMENTS | |
1656 lead_len == 0 && | |
1657 # endif | |
1658 ptr[0] == '#') | |
1659 { | 1641 { |
1660 int was_backslashed = FALSE; | 1642 int was_backslashed = FALSE; |
1661 | 1643 |
1662 while ((ptr[0] == '#' || was_backslashed) && | 1644 while ((ptr[0] == '#' || was_backslashed) && |
1663 curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | 1645 curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) |
1686 #endif // FEAT_SMARTINDENT | 1668 #endif // FEAT_SMARTINDENT |
1687 | 1669 |
1688 did_ai = TRUE; | 1670 did_ai = TRUE; |
1689 } | 1671 } |
1690 | 1672 |
1691 #ifdef FEAT_COMMENTS | |
1692 // Find out if the current line starts with a comment leader. | 1673 // Find out if the current line starts with a comment leader. |
1693 // This may then be inserted in front of the new line. | 1674 // This may then be inserted in front of the new line. |
1694 end_comment_pending = NUL; | 1675 end_comment_pending = NUL; |
1695 if (flags & OPENLINE_DO_COM) | 1676 if (flags & OPENLINE_DO_COM) |
1696 lead_len = get_leader_len(saved_line, &lead_flags, | 1677 lead_len = get_leader_len(saved_line, &lead_flags, |
2084 } | 2065 } |
2085 curwin->w_cursor = old_cursor; | 2066 curwin->w_cursor = old_cursor; |
2086 } | 2067 } |
2087 } | 2068 } |
2088 } | 2069 } |
2089 #endif | |
2090 | 2070 |
2091 // (State == INSERT || State == REPLACE), only when dir == FORWARD | 2071 // (State == INSERT || State == REPLACE), only when dir == FORWARD |
2092 if (p_extra != NULL) | 2072 if (p_extra != NULL) |
2093 { | 2073 { |
2094 *p_extra = saved_char; // restore char that NUL replaced | 2074 *p_extra = saved_char; // restore char that NUL replaced |
2118 } | 2098 } |
2119 | 2099 |
2120 if (p_extra == NULL) | 2100 if (p_extra == NULL) |
2121 p_extra = (char_u *)""; // append empty line | 2101 p_extra = (char_u *)""; // append empty line |
2122 | 2102 |
2123 #ifdef FEAT_COMMENTS | |
2124 // concatenate leader and p_extra, if there is a leader | 2103 // concatenate leader and p_extra, if there is a leader |
2125 if (lead_len) | 2104 if (lead_len) |
2126 { | 2105 { |
2127 if (flags & OPENLINE_COM_LIST && second_line_indent > 0) | 2106 if (flags & OPENLINE_COM_LIST && second_line_indent > 0) |
2128 { | 2107 { |
2145 did_ai = TRUE; // So truncating blanks works with comments | 2124 did_ai = TRUE; // So truncating blanks works with comments |
2146 less_cols -= lead_len; | 2125 less_cols -= lead_len; |
2147 } | 2126 } |
2148 else | 2127 else |
2149 end_comment_pending = NUL; // turns out there was no leader | 2128 end_comment_pending = NUL; // turns out there was no leader |
2150 #endif | |
2151 | 2129 |
2152 old_cursor = curwin->w_cursor; | 2130 old_cursor = curwin->w_cursor; |
2153 if (dir == BACKWARD) | 2131 if (dir == BACKWARD) |
2154 --curwin->w_cursor.lnum; | 2132 --curwin->w_cursor.lnum; |
2155 if (!(State & VREPLACE_FLAG) || old_cursor.lnum >= orig_line_count) | 2133 if (!(State & VREPLACE_FLAG) || old_cursor.lnum >= orig_line_count) |
2235 if (no_si) | 2213 if (no_si) |
2236 did_si = FALSE; | 2214 did_si = FALSE; |
2237 #endif | 2215 #endif |
2238 } | 2216 } |
2239 | 2217 |
2240 #ifdef FEAT_COMMENTS | |
2241 // In REPLACE mode, for each character in the extra leader, there must be | 2218 // In REPLACE mode, for each character in the extra leader, there must be |
2242 // a NUL on the replace stack, for when it is deleted with BS. | 2219 // a NUL on the replace stack, for when it is deleted with BS. |
2243 if (REPLACE_NORMAL(State)) | 2220 if (REPLACE_NORMAL(State)) |
2244 while (lead_len-- > 0) | 2221 while (lead_len-- > 0) |
2245 replace_push(NUL); | 2222 replace_push(NUL); |
2246 #endif | |
2247 | 2223 |
2248 curwin->w_cursor = old_cursor; | 2224 curwin->w_cursor = old_cursor; |
2249 | 2225 |
2250 if (dir == FORWARD) | 2226 if (dir == FORWARD) |
2251 { | 2227 { |
2297 vreplace_mode = 0; | 2273 vreplace_mode = 0; |
2298 #endif | 2274 #endif |
2299 #ifdef FEAT_LISP | 2275 #ifdef FEAT_LISP |
2300 // May do lisp indenting. | 2276 // May do lisp indenting. |
2301 if (!p_paste | 2277 if (!p_paste |
2302 # ifdef FEAT_COMMENTS | |
2303 && leader == NULL | 2278 && leader == NULL |
2304 # endif | |
2305 && curbuf->b_p_lisp | 2279 && curbuf->b_p_lisp |
2306 && curbuf->b_p_ai) | 2280 && curbuf->b_p_ai) |
2307 { | 2281 { |
2308 fixthisline(get_lisp_indent); | 2282 fixthisline(get_lisp_indent); |
2309 ai_col = (colnr_T)getwhitecols_curline(); | 2283 ai_col = (colnr_T)getwhitecols_curline(); |