Mercurial > vim
comparison src/search.c @ 4029:d179a8eff9d7 v7.3.769
updated for version 7.3.769
Problem: 'matchpairs' does not work with multi-byte characters.
Solution: Make it work. (Christian Brabandt)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Thu, 17 Jan 2013 17:02:05 +0100 |
parents | ca1c025079b1 |
children | 2067ed78d37c |
comparison
equal
deleted
inserted
replaced
4028:639564cb15a1 | 4029:d179a8eff9d7 |
---|---|
1784 backwards = (dir == FORWARD) ? FALSE : TRUE; | 1784 backwards = (dir == FORWARD) ? FALSE : TRUE; |
1785 initc = NUL; | 1785 initc = NUL; |
1786 } | 1786 } |
1787 else if (initc != '#' && initc != NUL) | 1787 else if (initc != '#' && initc != NUL) |
1788 { | 1788 { |
1789 /* 'matchpairs' is "x:y,x:y" */ | 1789 find_mps_values(&initc, &findc, &backwards, TRUE); |
1790 for (ptr = curbuf->b_p_mps; *ptr; ptr += 2) | 1790 if (findc == NUL) |
1791 { | |
1792 if (*ptr == initc) | |
1793 { | |
1794 findc = initc; | |
1795 initc = ptr[2]; | |
1796 backwards = TRUE; | |
1797 break; | |
1798 } | |
1799 ptr += 2; | |
1800 if (*ptr == initc) | |
1801 { | |
1802 findc = initc; | |
1803 initc = ptr[-2]; | |
1804 backwards = FALSE; | |
1805 break; | |
1806 } | |
1807 if (ptr[1] != ',') | |
1808 break; | |
1809 } | |
1810 if (!findc) /* invalid initc! */ | |
1811 return NULL; | 1791 return NULL; |
1812 } | 1792 } |
1813 /* | 1793 /* |
1814 * Either initc is '#', or no initc was given and we need to look under the | 1794 * Either initc is '#', or no initc was given and we need to look under the |
1815 * cursor. | 1795 * cursor. |
1884 */ | 1864 */ |
1885 if (linep[pos.col] == NUL && pos.col) | 1865 if (linep[pos.col] == NUL && pos.col) |
1886 --pos.col; | 1866 --pos.col; |
1887 for (;;) | 1867 for (;;) |
1888 { | 1868 { |
1889 initc = linep[pos.col]; | 1869 initc = PTR2CHAR(linep + pos.col); |
1890 if (initc == NUL) | 1870 if (initc == NUL) |
1891 break; | 1871 break; |
1892 | 1872 |
1893 for (ptr = curbuf->b_p_mps; *ptr; ++ptr) | 1873 find_mps_values(&initc, &findc, &backwards, FALSE); |
1894 { | |
1895 if (*ptr == initc) | |
1896 { | |
1897 findc = ptr[2]; | |
1898 backwards = FALSE; | |
1899 break; | |
1900 } | |
1901 ptr += 2; | |
1902 if (*ptr == initc) | |
1903 { | |
1904 findc = ptr[-2]; | |
1905 backwards = TRUE; | |
1906 break; | |
1907 } | |
1908 if (!*++ptr) | |
1909 break; | |
1910 } | |
1911 if (findc) | 1874 if (findc) |
1912 break; | 1875 break; |
1913 #ifdef FEAT_MBYTE | 1876 pos.col += MB_PTR2LEN(linep + pos.col); |
1914 if (has_mbyte) | |
1915 pos.col += (*mb_ptr2len)(linep + pos.col); | |
1916 else | |
1917 #endif | |
1918 ++pos.col; | |
1919 } | 1877 } |
1920 if (!findc) | 1878 if (!findc) |
1921 { | 1879 { |
1922 /* no brace in the line, maybe use " #if" then */ | 1880 /* no brace in the line, maybe use " #if" then */ |
1923 if (!cpo_match && *skipwhite(linep) == '#') | 1881 if (!cpo_match && *skipwhite(linep) == '#') |
2258 * In lines with an uneven number of quotes (without preceding '\') | 2216 * In lines with an uneven number of quotes (without preceding '\') |
2259 * we do not know which part to ignore. Therefore we only set | 2217 * we do not know which part to ignore. Therefore we only set |
2260 * inquote if the number of quotes in a line is even, unless this | 2218 * inquote if the number of quotes in a line is even, unless this |
2261 * line or the previous one ends in a '\'. Complicated, isn't it? | 2219 * line or the previous one ends in a '\'. Complicated, isn't it? |
2262 */ | 2220 */ |
2263 switch (c = linep[pos.col]) | 2221 c = PTR2CHAR(linep + pos.col); |
2222 switch (c) | |
2264 { | 2223 { |
2265 case NUL: | 2224 case NUL: |
2266 /* at end of line without trailing backslash, reset inquote */ | 2225 /* at end of line without trailing backslash, reset inquote */ |
2267 if (pos.col == 0 || linep[pos.col - 1] != '\\') | 2226 if (pos.col == 0 || linep[pos.col - 1] != '\\') |
2268 { | 2227 { |
2467 | 2426 |
2468 /* | 2427 /* |
2469 * Only show match for chars in the 'matchpairs' option. | 2428 * Only show match for chars in the 'matchpairs' option. |
2470 */ | 2429 */ |
2471 /* 'matchpairs' is "x:y,x:y" */ | 2430 /* 'matchpairs' is "x:y,x:y" */ |
2472 for (p = curbuf->b_p_mps; *p != NUL; p += 2) | 2431 for (p = curbuf->b_p_mps; *p != NUL; ++p) |
2473 { | 2432 { |
2433 if (PTR2CHAR(p) == c | |
2474 #ifdef FEAT_RIGHTLEFT | 2434 #ifdef FEAT_RIGHTLEFT |
2475 if (*p == c && (curwin->w_p_rl ^ p_ri)) | 2435 && (curwin->w_p_rl ^ p_ri) |
2436 #endif | |
2437 ) | |
2476 break; | 2438 break; |
2477 #endif | 2439 p += MB_PTR2LEN(p) + 1; |
2478 p += 2; | 2440 if (PTR2CHAR(p) == c |
2479 if (*p == c | |
2480 #ifdef FEAT_RIGHTLEFT | 2441 #ifdef FEAT_RIGHTLEFT |
2481 && !(curwin->w_p_rl ^ p_ri) | 2442 && !(curwin->w_p_rl ^ p_ri) |
2482 #endif | 2443 #endif |
2483 ) | 2444 ) |
2484 break; | 2445 break; |
2485 if (p[1] != ',') | 2446 p += MB_PTR2LEN(p); |
2447 if (*p == NUL) | |
2486 return; | 2448 return; |
2487 } | 2449 } |
2488 | 2450 |
2489 if ((lpos = findmatch(NULL, NUL)) == NULL) /* no match, so beep */ | 2451 if ((lpos = findmatch(NULL, NUL)) == NULL) /* no match, so beep */ |
2490 vim_beep(); | 2452 vim_beep(); |