Mercurial > vim
comparison src/misc1.c @ 14424:0a69e6e708f9 v8.1.0226
patch 8.1.0226: too many #ifdefs
commit https://github.com/vim/vim/commit/1f0bfe561737cd445532f20d7607a81d1dadddee
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jul 29 16:09:22 2018 +0200
patch 8.1.0226: too many #ifdefs
Problem: Too many #ifdefs.
Solution: Graduate the +vreplace feature, it's not much code and quite a few
#ifdefs.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 29 Jul 2018 16:15:05 +0200 |
parents | c62601adad69 |
children | c8f07e8b273e |
comparison
equal
deleted
inserted
replaced
14423:cd3118af2cfc | 14424:0a69e6e708f9 |
---|---|
782 int lead_len; /* length of comment leader */ | 782 int lead_len; /* length of comment leader */ |
783 char_u *lead_flags; /* position in 'comments' for comment leader */ | 783 char_u *lead_flags; /* position in 'comments' for comment leader */ |
784 char_u *leader = NULL; /* copy of comment leader */ | 784 char_u *leader = NULL; /* copy of comment leader */ |
785 #endif | 785 #endif |
786 char_u *allocated = NULL; /* allocated memory */ | 786 char_u *allocated = NULL; /* allocated memory */ |
787 #if defined(FEAT_SMARTINDENT) || defined(FEAT_VREPLACE) || defined(FEAT_LISP) \ | |
788 || defined(FEAT_CINDENT) || defined(FEAT_COMMENTS) | |
789 char_u *p; | 787 char_u *p; |
790 #endif | |
791 int saved_char = NUL; /* init for GCC */ | 788 int saved_char = NUL; /* init for GCC */ |
792 #if defined(FEAT_SMARTINDENT) || defined(FEAT_COMMENTS) | 789 #if defined(FEAT_SMARTINDENT) || defined(FEAT_COMMENTS) |
793 pos_T *pos; | 790 pos_T *pos; |
794 #endif | 791 #endif |
795 #ifdef FEAT_SMARTINDENT | 792 #ifdef FEAT_SMARTINDENT |
802 # endif | 799 # endif |
803 ); | 800 ); |
804 int no_si = FALSE; /* reset did_si afterwards */ | 801 int no_si = FALSE; /* reset did_si afterwards */ |
805 int first_char = NUL; /* init for GCC */ | 802 int first_char = NUL; /* init for GCC */ |
806 #endif | 803 #endif |
807 #if defined(FEAT_VREPLACE) && (defined(FEAT_LISP) || defined(FEAT_CINDENT)) | 804 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) |
808 int vreplace_mode; | 805 int vreplace_mode; |
809 #endif | 806 #endif |
810 int did_append; /* appended a new line */ | 807 int did_append; /* appended a new line */ |
811 int saved_pi = curbuf->b_p_pi; /* copy of preserveindent setting */ | 808 int saved_pi = curbuf->b_p_pi; /* copy of preserveindent setting */ |
812 | 809 |
815 */ | 812 */ |
816 saved_line = vim_strsave(ml_get_curline()); | 813 saved_line = vim_strsave(ml_get_curline()); |
817 if (saved_line == NULL) /* out of memory! */ | 814 if (saved_line == NULL) /* out of memory! */ |
818 return FALSE; | 815 return FALSE; |
819 | 816 |
820 #ifdef FEAT_VREPLACE | |
821 if (State & VREPLACE_FLAG) | 817 if (State & VREPLACE_FLAG) |
822 { | 818 { |
823 /* | 819 /* |
824 * With VREPLACE we make a copy of the next line, which we will be | 820 * With VREPLACE we make a copy of the next line, which we will be |
825 * starting to replace. First make the new line empty and let vim play | 821 * starting to replace. First make the new line empty and let vim play |
855 #endif | 851 #endif |
856 replace_push(*p++); | 852 replace_push(*p++); |
857 } | 853 } |
858 saved_line[curwin->w_cursor.col] = NUL; | 854 saved_line[curwin->w_cursor.col] = NUL; |
859 } | 855 } |
860 #endif | 856 |
861 | 857 if ((State & INSERT) && !(State & VREPLACE_FLAG)) |
862 if ((State & INSERT) | |
863 #ifdef FEAT_VREPLACE | |
864 && !(State & VREPLACE_FLAG) | |
865 #endif | |
866 ) | |
867 { | 858 { |
868 p_extra = saved_line + curwin->w_cursor.col; | 859 p_extra = saved_line + curwin->w_cursor.col; |
869 #ifdef FEAT_SMARTINDENT | 860 #ifdef FEAT_SMARTINDENT |
870 if (do_si) /* need first char after new line break */ | 861 if (do_si) /* need first char after new line break */ |
871 { | 862 { |
1599 #endif | 1590 #endif |
1600 | 1591 |
1601 old_cursor = curwin->w_cursor; | 1592 old_cursor = curwin->w_cursor; |
1602 if (dir == BACKWARD) | 1593 if (dir == BACKWARD) |
1603 --curwin->w_cursor.lnum; | 1594 --curwin->w_cursor.lnum; |
1604 #ifdef FEAT_VREPLACE | |
1605 if (!(State & VREPLACE_FLAG) || old_cursor.lnum >= orig_line_count) | 1595 if (!(State & VREPLACE_FLAG) || old_cursor.lnum >= orig_line_count) |
1606 #endif | |
1607 { | 1596 { |
1608 if (ml_append(curwin->w_cursor.lnum, p_extra, (colnr_T)0, FALSE) | 1597 if (ml_append(curwin->w_cursor.lnum, p_extra, (colnr_T)0, FALSE) |
1609 == FAIL) | 1598 == FAIL) |
1610 goto theend; | 1599 goto theend; |
1611 /* Postpone calling changed_lines(), because it would mess up folding | 1600 /* Postpone calling changed_lines(), because it would mess up folding |
1618 #endif | 1607 #endif |
1619 ) | 1608 ) |
1620 mark_adjust(curwin->w_cursor.lnum + 1, (linenr_T)MAXLNUM, 1L, 0L); | 1609 mark_adjust(curwin->w_cursor.lnum + 1, (linenr_T)MAXLNUM, 1L, 0L); |
1621 did_append = TRUE; | 1610 did_append = TRUE; |
1622 } | 1611 } |
1623 #ifdef FEAT_VREPLACE | |
1624 else | 1612 else |
1625 { | 1613 { |
1626 /* | 1614 /* |
1627 * In VREPLACE mode we are starting to replace the next line. | 1615 * In VREPLACE mode we are starting to replace the next line. |
1628 */ | 1616 */ |
1638 ml_replace(curwin->w_cursor.lnum, p_extra, TRUE); | 1626 ml_replace(curwin->w_cursor.lnum, p_extra, TRUE); |
1639 changed_bytes(curwin->w_cursor.lnum, 0); | 1627 changed_bytes(curwin->w_cursor.lnum, 0); |
1640 curwin->w_cursor.lnum--; | 1628 curwin->w_cursor.lnum--; |
1641 did_append = FALSE; | 1629 did_append = FALSE; |
1642 } | 1630 } |
1643 #endif | |
1644 | 1631 |
1645 if (newindent | 1632 if (newindent |
1646 #ifdef FEAT_SMARTINDENT | 1633 #ifdef FEAT_SMARTINDENT |
1647 || did_si | 1634 || did_si |
1648 #endif | 1635 #endif |
1742 curwin->w_cursor.col = newcol; | 1729 curwin->w_cursor.col = newcol; |
1743 #ifdef FEAT_VIRTUALEDIT | 1730 #ifdef FEAT_VIRTUALEDIT |
1744 curwin->w_cursor.coladd = 0; | 1731 curwin->w_cursor.coladd = 0; |
1745 #endif | 1732 #endif |
1746 | 1733 |
1747 #if defined(FEAT_VREPLACE) && (defined(FEAT_LISP) || defined(FEAT_CINDENT)) | 1734 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) |
1748 /* | 1735 /* |
1749 * In VREPLACE mode, we are handling the replace stack ourselves, so stop | 1736 * In VREPLACE mode, we are handling the replace stack ourselves, so stop |
1750 * fixthisline() from doing it (via change_indent()) by telling it we're in | 1737 * fixthisline() from doing it (via change_indent()) by telling it we're in |
1751 * normal INSERT mode. | 1738 * normal INSERT mode. |
1752 */ | 1739 */ |
1789 { | 1776 { |
1790 do_c_expr_indent(); | 1777 do_c_expr_indent(); |
1791 ai_col = (colnr_T)getwhitecols_curline(); | 1778 ai_col = (colnr_T)getwhitecols_curline(); |
1792 } | 1779 } |
1793 #endif | 1780 #endif |
1794 #if defined(FEAT_VREPLACE) && (defined(FEAT_LISP) || defined(FEAT_CINDENT)) | 1781 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) |
1795 if (vreplace_mode != 0) | 1782 if (vreplace_mode != 0) |
1796 State = vreplace_mode; | 1783 State = vreplace_mode; |
1797 #endif | 1784 #endif |
1798 | 1785 |
1799 #ifdef FEAT_VREPLACE | |
1800 /* | 1786 /* |
1801 * Finally, VREPLACE gets the stuff on the new line, then puts back the | 1787 * Finally, VREPLACE gets the stuff on the new line, then puts back the |
1802 * original line, and inserts the new stuff char by char, pushing old stuff | 1788 * original line, and inserts the new stuff char by char, pushing old stuff |
1803 * onto the replace stack (via ins_char()). | 1789 * onto the replace stack (via ins_char()). |
1804 */ | 1790 */ |
1819 #endif | 1805 #endif |
1820 ins_bytes(p_extra); /* will call changed_bytes() */ | 1806 ins_bytes(p_extra); /* will call changed_bytes() */ |
1821 vim_free(p_extra); | 1807 vim_free(p_extra); |
1822 next_line = NULL; | 1808 next_line = NULL; |
1823 } | 1809 } |
1824 #endif | |
1825 | 1810 |
1826 retval = OK; /* success! */ | 1811 retval = OK; /* success! */ |
1827 theend: | 1812 theend: |
1828 curbuf->b_p_pi = saved_pi; | 1813 curbuf->b_p_pi = saved_pi; |
1829 vim_free(saved_line); | 1814 vim_free(saved_line); |
2305 } | 2290 } |
2306 } | 2291 } |
2307 return (count); | 2292 return (count); |
2308 } | 2293 } |
2309 | 2294 |
2310 #if defined(FEAT_VREPLACE) || defined(FEAT_INS_EXPAND) || defined(PROTO) | |
2311 /* | 2295 /* |
2312 * Insert string "p" at the cursor position. Stops at a NUL byte. | 2296 * Insert string "p" at the cursor position. Stops at a NUL byte. |
2313 * Handles Replace mode and multi-byte characters. | 2297 * Handles Replace mode and multi-byte characters. |
2314 */ | 2298 */ |
2315 void | 2299 void |
2316 ins_bytes(char_u *p) | 2300 ins_bytes(char_u *p) |
2317 { | 2301 { |
2318 ins_bytes_len(p, (int)STRLEN(p)); | 2302 ins_bytes_len(p, (int)STRLEN(p)); |
2319 } | 2303 } |
2320 #endif | 2304 |
2321 | |
2322 #if defined(FEAT_VREPLACE) || defined(FEAT_INS_EXPAND) \ | |
2323 || defined(FEAT_COMMENTS) || defined(FEAT_MBYTE) || defined(PROTO) | |
2324 /* | 2305 /* |
2325 * Insert string "p" with length "len" at the cursor position. | 2306 * Insert string "p" with length "len" at the cursor position. |
2326 * Handles Replace mode and multi-byte characters. | 2307 * Handles Replace mode and multi-byte characters. |
2327 */ | 2308 */ |
2328 void | 2309 void |
2329 ins_bytes_len(char_u *p, int len) | 2310 ins_bytes_len(char_u *p, int len) |
2330 { | 2311 { |
2331 int i; | 2312 int i; |
2332 # ifdef FEAT_MBYTE | 2313 #ifdef FEAT_MBYTE |
2333 int n; | 2314 int n; |
2334 | 2315 |
2335 if (has_mbyte) | 2316 if (has_mbyte) |
2336 for (i = 0; i < len; i += n) | 2317 for (i = 0; i < len; i += n) |
2337 { | 2318 { |
2341 else | 2322 else |
2342 n = (*mb_ptr2len)(p + i); | 2323 n = (*mb_ptr2len)(p + i); |
2343 ins_char_bytes(p + i, n); | 2324 ins_char_bytes(p + i, n); |
2344 } | 2325 } |
2345 else | 2326 else |
2346 # endif | 2327 #endif |
2347 for (i = 0; i < len; ++i) | 2328 for (i = 0; i < len; ++i) |
2348 ins_char(p[i]); | 2329 ins_char(p[i]); |
2349 } | 2330 } |
2350 #endif | |
2351 | 2331 |
2352 /* | 2332 /* |
2353 * Insert or replace a single character at the cursor position. | 2333 * Insert or replace a single character at the cursor position. |
2354 * When in REPLACE or VREPLACE mode, replace any existing character. | 2334 * When in REPLACE or VREPLACE mode, replace any existing character. |
2355 * Caller must have prepared for undo. | 2335 * Caller must have prepared for undo. |
2404 oldlen = 0; | 2384 oldlen = 0; |
2405 newlen = charlen; | 2385 newlen = charlen; |
2406 | 2386 |
2407 if (State & REPLACE_FLAG) | 2387 if (State & REPLACE_FLAG) |
2408 { | 2388 { |
2409 #ifdef FEAT_VREPLACE | |
2410 if (State & VREPLACE_FLAG) | 2389 if (State & VREPLACE_FLAG) |
2411 { | 2390 { |
2412 colnr_T new_vcol = 0; /* init for GCC */ | 2391 colnr_T new_vcol = 0; /* init for GCC */ |
2413 colnr_T vcol; | 2392 colnr_T vcol; |
2414 int old_list; | 2393 int old_list; |
2454 newlen += vcol - new_vcol; | 2433 newlen += vcol - new_vcol; |
2455 } | 2434 } |
2456 curwin->w_p_list = old_list; | 2435 curwin->w_p_list = old_list; |
2457 } | 2436 } |
2458 else | 2437 else |
2459 #endif | |
2460 if (oldp[col] != NUL) | 2438 if (oldp[col] != NUL) |
2461 { | 2439 { |
2462 /* normal replace */ | 2440 /* normal replace */ |
2463 #ifdef FEAT_MBYTE | 2441 #ifdef FEAT_MBYTE |
2464 oldlen = (*mb_ptr2len)(oldp + col); | 2442 oldlen = (*mb_ptr2len)(oldp + col); |