summaryrefslogtreecommitdiffstats
path: root/src/fold.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fold.c')
-rw-r--r--src/fold.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/fold.c b/src/fold.c
index ceac00bbf6..feb5c91f24 100644
--- a/src/fold.c
+++ b/src/fold.c
@@ -1903,6 +1903,93 @@ foldDelMarker(lnum, marker, markerlen)
}
}
+/* get_foldtext() {{{2 */
+/*
+ * Return the text for a closed fold at line "lnum", with last line "lnume".
+ * When 'foldtext' isn't set puts the result in "buf[51]". Otherwise the
+ * result is in allocated memory.
+ */
+ char_u *
+get_foldtext(wp, lnum, lnume, foldinfo, buf)
+ win_T *wp;
+ linenr_T lnum, lnume;
+ foldinfo_T *foldinfo;
+ char_u *buf;
+{
+ char_u *text = NULL;
+
+#ifdef FEAT_EVAL
+ if (*wp->w_p_fdt != NUL)
+ {
+ char_u dashes[51];
+ win_T *save_curwin;
+ int level;
+ char_u *p;
+ int len;
+
+ /* Set "v:foldstart" and "v:foldend". */
+ set_vim_var_nr(VV_FOLDSTART, lnum);
+ set_vim_var_nr(VV_FOLDEND, lnume);
+
+ /* Set "v:folddashes" to a string of "level" dashes. */
+ /* Set "v:foldlevel" to "level". */
+ level = foldinfo->fi_level;
+ if (level > 50)
+ level = 50;
+ vim_memset(dashes, '-', (size_t)level);
+ dashes[level] = NUL;
+ set_vim_var_string(VV_FOLDDASHES, dashes, -1);
+ set_vim_var_nr(VV_FOLDLEVEL, (long)level);
+ save_curwin = curwin;
+ curwin = wp;
+ curbuf = wp->w_buffer;
+
+ ++emsg_off;
+ text = eval_to_string_safe(wp->w_p_fdt, NULL);
+ --emsg_off;
+
+ curwin = save_curwin;
+ curbuf = curwin->w_buffer;
+ set_vim_var_string(VV_FOLDDASHES, NULL, -1);
+
+ if (text != NULL)
+ {
+ /* Replace unprintable characters, if there are any. But
+ * replace a TAB with a space. */
+ for (p = text; *p != NUL; ++p)
+ {
+# ifdef FEAT_MBYTE
+ if (has_mbyte && (len = (*mb_ptr2len_check)(p)) > 1)
+ {
+ if (!vim_isprintc((*mb_ptr2char)(p)))
+ break;
+ p += len - 1;
+ }
+ else
+# endif
+ if (*p == TAB)
+ *p = ' ';
+ else if (ptr2cells(p) > 1)
+ break;
+ }
+ if (*p != NUL)
+ {
+ p = transstr(text);
+ vim_free(text);
+ text = p;
+ }
+ }
+ }
+ if (text == NULL)
+#endif
+ {
+ sprintf((char *)buf, _("+--%3ld lines folded "),
+ (long)(lnume - lnum + 1));
+ text = buf;
+ }
+ return text;
+}
+
/* foldtext_cleanup() {{{2 */
/*
* Remove 'foldmarker' and 'commentstring' from "str" (in-place).