Mercurial > vim
comparison src/search.c @ 14:946da5994c01
updated for version 7.0006
author | vimboss |
---|---|
date | Mon, 05 Jul 2004 15:58:32 +0000 |
parents | bdeee1504ac1 |
children | 4ac1dce8dd5e |
comparison
equal
deleted
inserted
replaced
13:24d5189d3956 | 14:946da5994c01 |
---|---|
1556 int cpo_match; /* vi compatible matching */ | 1556 int cpo_match; /* vi compatible matching */ |
1557 int cpo_bsl; /* don't recognize backslashes */ | 1557 int cpo_bsl; /* don't recognize backslashes */ |
1558 int match_escaped = 0; /* search for escaped match */ | 1558 int match_escaped = 0; /* search for escaped match */ |
1559 int dir; /* Direction to search */ | 1559 int dir; /* Direction to search */ |
1560 int comment_col = MAXCOL; /* start of / / comment */ | 1560 int comment_col = MAXCOL; /* start of / / comment */ |
1561 #ifdef FEAT_LISP | |
1562 int lispcomm = FALSE; /* inside of Lisp-style comment */ | |
1563 int lisp = curbuf->b_p_lisp; /* engage Lisp-specific hacks ;) */ | |
1564 #endif | |
1561 | 1565 |
1562 pos = curwin->w_cursor; | 1566 pos = curwin->w_cursor; |
1563 linep = ml_get(pos.lnum); | 1567 linep = ml_get(pos.lnum); |
1564 | 1568 |
1565 cpo_match = (vim_strchr(p_cpo, CPO_MATCH) != NULL); | 1569 cpo_match = (vim_strchr(p_cpo, CPO_MATCH) != NULL); |
1820 #endif | 1824 #endif |
1821 | 1825 |
1822 do_quotes = -1; | 1826 do_quotes = -1; |
1823 start_in_quotes = MAYBE; | 1827 start_in_quotes = MAYBE; |
1824 /* backward search: Check if this line contains a single-line comment */ | 1828 /* backward search: Check if this line contains a single-line comment */ |
1825 if (backwards && comment_dir) | 1829 if ((backwards && comment_dir) |
1830 #ifdef FEAT_LISP | |
1831 || lisp | |
1832 #endif | |
1833 ) | |
1826 comment_col = check_linecomment(linep); | 1834 comment_col = check_linecomment(linep); |
1835 #ifdef FEAT_LISP | |
1836 if (lisp && comment_col != MAXCOL && pos.col > (colnr_T)comment_col) | |
1837 lispcomm = TRUE; /* find match inside this comment */ | |
1838 #endif | |
1827 while (!got_int) | 1839 while (!got_int) |
1828 { | 1840 { |
1829 /* | 1841 /* |
1830 * Go to the next position, forward or backward. We could use | 1842 * Go to the next position, forward or backward. We could use |
1831 * inc() and dec() here, but that is much slower | 1843 * inc() and dec() here, but that is much slower |
1832 */ | 1844 */ |
1833 if (backwards) | 1845 if (backwards) |
1834 { | 1846 { |
1847 #ifdef FEAT_LISP | |
1848 /* char to match is inside of comment, don't search outside */ | |
1849 if (lispcomm && pos.col < (colnr_T)comment_col) | |
1850 break; | |
1851 #endif | |
1835 if (pos.col == 0) /* at start of line, go to prev. one */ | 1852 if (pos.col == 0) /* at start of line, go to prev. one */ |
1836 { | 1853 { |
1837 if (pos.lnum == 1) /* start of file */ | 1854 if (pos.lnum == 1) /* start of file */ |
1838 break; | 1855 break; |
1839 --pos.lnum; | 1856 --pos.lnum; |
1845 pos.col = (colnr_T)STRLEN(linep); /* pos.col on trailing NUL */ | 1862 pos.col = (colnr_T)STRLEN(linep); /* pos.col on trailing NUL */ |
1846 do_quotes = -1; | 1863 do_quotes = -1; |
1847 line_breakcheck(); | 1864 line_breakcheck(); |
1848 | 1865 |
1849 /* Check if this line contains a single-line comment */ | 1866 /* Check if this line contains a single-line comment */ |
1850 if (comment_dir) | 1867 if (comment_dir |
1868 #ifdef FEAT_LISP | |
1869 || lisp | |
1870 #endif | |
1871 ) | |
1851 comment_col = check_linecomment(linep); | 1872 comment_col = check_linecomment(linep); |
1873 #ifdef FEAT_LISP | |
1874 /* skip comment */ | |
1875 if (lisp && comment_col != MAXCOL) | |
1876 pos.col = comment_col; | |
1877 #endif | |
1852 } | 1878 } |
1853 else | 1879 else |
1854 { | 1880 { |
1855 --pos.col; | 1881 --pos.col; |
1856 #ifdef FEAT_MBYTE | 1882 #ifdef FEAT_MBYTE |
1859 #endif | 1885 #endif |
1860 } | 1886 } |
1861 } | 1887 } |
1862 else /* forward search */ | 1888 else /* forward search */ |
1863 { | 1889 { |
1864 if (linep[pos.col] == NUL) /* at end of line, go to next one */ | 1890 if (linep[pos.col] == NUL |
1865 { | 1891 /* at end of line, go to next one */ |
1866 if (pos.lnum == curbuf->b_ml.ml_line_count) /* end of file */ | 1892 #ifdef FEAT_LISP |
1893 /* don't search for match in comment */ | |
1894 || (lisp && comment_col != MAXCOL | |
1895 && pos.col == (colnr_T)comment_col) | |
1896 #endif | |
1897 ) | |
1898 { | |
1899 if (pos.lnum == curbuf->b_ml.ml_line_count /* end of file */ | |
1900 #ifdef FEAT_LISP | |
1901 /* line is exhausted and comment with it, | |
1902 * don't search for match in code */ | |
1903 || lispcomm | |
1904 #endif | |
1905 ) | |
1867 break; | 1906 break; |
1868 ++pos.lnum; | 1907 ++pos.lnum; |
1869 | 1908 |
1870 if (maxtravel && traveled++ > maxtravel) | 1909 if (maxtravel && traveled++ > maxtravel) |
1871 break; | 1910 break; |
1872 | 1911 |
1873 linep = ml_get(pos.lnum); | 1912 linep = ml_get(pos.lnum); |
1874 pos.col = 0; | 1913 pos.col = 0; |
1875 do_quotes = -1; | 1914 do_quotes = -1; |
1876 line_breakcheck(); | 1915 line_breakcheck(); |
1916 #ifdef FEAT_LISP | |
1917 if (lisp) /* find comment pos in new line */ | |
1918 comment_col = check_linecomment(linep); | |
1919 #endif | |
1877 } | 1920 } |
1878 else | 1921 else |
1879 { | 1922 { |
1880 #ifdef FEAT_MBYTE | 1923 #ifdef FEAT_MBYTE |
1881 if (has_mbyte) | 1924 if (has_mbyte) |
2092 } | 2135 } |
2093 /* FALLTHROUGH */ | 2136 /* FALLTHROUGH */ |
2094 | 2137 |
2095 default: | 2138 default: |
2096 #ifdef FEAT_LISP | 2139 #ifdef FEAT_LISP |
2097 /* For Lisp skip over backslashed (), {} and []. */ | 2140 /* |
2141 * For Lisp skip over backslashed (), {} and []. | |
2142 * (actually, we skip #\( et al) | |
2143 */ | |
2098 if (curbuf->b_p_lisp | 2144 if (curbuf->b_p_lisp |
2099 && vim_strchr((char_u *)"(){}[]", c) != NULL | 2145 && vim_strchr((char_u *)"(){}[]", c) != NULL |
2100 && pos.col > 0 | 2146 && pos.col > 1 |
2101 && check_prevcol(linep, pos.col, '\\', NULL)) | 2147 && check_prevcol(linep, pos.col, '\\', NULL) |
2148 && check_prevcol(linep, pos.col - 1, '#', NULL)) | |
2102 break; | 2149 break; |
2103 #endif | 2150 #endif |
2104 | 2151 |
2105 /* Check for match outside of quotes, and inside of | 2152 /* Check for match outside of quotes, and inside of |
2106 * quotes when the start is also inside of quotes. */ | 2153 * quotes when the start is also inside of quotes. */ |
2149 char_u *line; | 2196 char_u *line; |
2150 { | 2197 { |
2151 char_u *p; | 2198 char_u *p; |
2152 | 2199 |
2153 p = line; | 2200 p = line; |
2201 #ifdef FEAT_LISP | |
2202 /* skip Lispish one-line comments */ | |
2203 if (curbuf->b_p_lisp) | |
2204 { | |
2205 if (vim_strchr(p, ';') != NULL) /* there may be comments */ | |
2206 { | |
2207 int instr = FALSE; /* inside of string */ | |
2208 | |
2209 p = line; /* scan from start */ | |
2210 while ((p = vim_strpbrk(p, "\";")) != NULL) | |
2211 { | |
2212 if (*p == '"') | |
2213 { | |
2214 if (instr) | |
2215 { | |
2216 if (*(p - 1) != '\\') /* skip escaped quote */ | |
2217 instr = FALSE; | |
2218 } | |
2219 else if (p == line || ((p - line) >= 2 | |
2220 /* skip #\" form */ | |
2221 && *(p - 1) != '\\' && *(p - 2) != '#')) | |
2222 instr = TRUE; | |
2223 } | |
2224 else if (!instr && ((p - line) < 2 | |
2225 || (*(p - 1) != '\\' && *(p - 2) != '#'))) | |
2226 break; /* found! */ | |
2227 ++p; | |
2228 } | |
2229 } | |
2230 else | |
2231 p = NULL; | |
2232 } | |
2233 else | |
2234 #endif | |
2154 while ((p = vim_strchr(p, '/')) != NULL) | 2235 while ((p = vim_strchr(p, '/')) != NULL) |
2155 { | 2236 { |
2156 if (p[1] == '/') | 2237 if (p[1] == '/') |
2157 break; | 2238 break; |
2158 ++p; | 2239 ++p; |