Mercurial > vim
comparison src/fold.c @ 29:ac33b7c03fac v7.0018
updated for version 7.0018
author | vimboss |
---|---|
date | Mon, 11 Oct 2004 10:16:09 +0000 |
parents | 3fc0f57ecb91 |
children | f6033dcbaf31 |
comparison
equal
deleted
inserted
replaced
28:726bdc53fa49 | 29:ac33b7c03fac |
---|---|
1899 ml_replace(lnum, newline, FALSE); | 1899 ml_replace(lnum, newline, FALSE); |
1900 } | 1900 } |
1901 } | 1901 } |
1902 break; | 1902 break; |
1903 } | 1903 } |
1904 } | |
1905 | |
1906 /* get_foldtext() {{{2 */ | |
1907 /* | |
1908 * Return the text for a closed fold at line "lnum", with last line "lnume". | |
1909 * When 'foldtext' isn't set puts the result in "buf[51]". Otherwise the | |
1910 * result is in allocated memory. | |
1911 */ | |
1912 char_u * | |
1913 get_foldtext(wp, lnum, lnume, foldinfo, buf) | |
1914 win_T *wp; | |
1915 linenr_T lnum, lnume; | |
1916 foldinfo_T *foldinfo; | |
1917 char_u *buf; | |
1918 { | |
1919 char_u *text = NULL; | |
1920 | |
1921 #ifdef FEAT_EVAL | |
1922 if (*wp->w_p_fdt != NUL) | |
1923 { | |
1924 char_u dashes[51]; | |
1925 win_T *save_curwin; | |
1926 int level; | |
1927 char_u *p; | |
1928 int len; | |
1929 | |
1930 /* Set "v:foldstart" and "v:foldend". */ | |
1931 set_vim_var_nr(VV_FOLDSTART, lnum); | |
1932 set_vim_var_nr(VV_FOLDEND, lnume); | |
1933 | |
1934 /* Set "v:folddashes" to a string of "level" dashes. */ | |
1935 /* Set "v:foldlevel" to "level". */ | |
1936 level = foldinfo->fi_level; | |
1937 if (level > 50) | |
1938 level = 50; | |
1939 vim_memset(dashes, '-', (size_t)level); | |
1940 dashes[level] = NUL; | |
1941 set_vim_var_string(VV_FOLDDASHES, dashes, -1); | |
1942 set_vim_var_nr(VV_FOLDLEVEL, (long)level); | |
1943 save_curwin = curwin; | |
1944 curwin = wp; | |
1945 curbuf = wp->w_buffer; | |
1946 | |
1947 ++emsg_off; | |
1948 text = eval_to_string_safe(wp->w_p_fdt, NULL); | |
1949 --emsg_off; | |
1950 | |
1951 curwin = save_curwin; | |
1952 curbuf = curwin->w_buffer; | |
1953 set_vim_var_string(VV_FOLDDASHES, NULL, -1); | |
1954 | |
1955 if (text != NULL) | |
1956 { | |
1957 /* Replace unprintable characters, if there are any. But | |
1958 * replace a TAB with a space. */ | |
1959 for (p = text; *p != NUL; ++p) | |
1960 { | |
1961 # ifdef FEAT_MBYTE | |
1962 if (has_mbyte && (len = (*mb_ptr2len_check)(p)) > 1) | |
1963 { | |
1964 if (!vim_isprintc((*mb_ptr2char)(p))) | |
1965 break; | |
1966 p += len - 1; | |
1967 } | |
1968 else | |
1969 # endif | |
1970 if (*p == TAB) | |
1971 *p = ' '; | |
1972 else if (ptr2cells(p) > 1) | |
1973 break; | |
1974 } | |
1975 if (*p != NUL) | |
1976 { | |
1977 p = transstr(text); | |
1978 vim_free(text); | |
1979 text = p; | |
1980 } | |
1981 } | |
1982 } | |
1983 if (text == NULL) | |
1984 #endif | |
1985 { | |
1986 sprintf((char *)buf, _("+--%3ld lines folded "), | |
1987 (long)(lnume - lnum + 1)); | |
1988 text = buf; | |
1989 } | |
1990 return text; | |
1904 } | 1991 } |
1905 | 1992 |
1906 /* foldtext_cleanup() {{{2 */ | 1993 /* foldtext_cleanup() {{{2 */ |
1907 /* | 1994 /* |
1908 * Remove 'foldmarker' and 'commentstring' from "str" (in-place). | 1995 * Remove 'foldmarker' and 'commentstring' from "str" (in-place). |