Hi Bram!

On Mi, 13 Mär 2013, Bram Moolenaar wrote:

> What should happen is when evaluating 'foldtext' it should check if this
> results in an error, and then stop evaluating it.  Like what happens in
> win_line() with b_syn_error.  It's a bit more work, but it's probably
> the right way to do it.
> 

I didn't want to add yet another variable to the win_T struct, so I made 
get_foldtext() check, whether the last time it run, it was still on the 
same window and some lines before, otherwise, we at least check once, 
whether the current foldtext setting succeeds and if not, we skip 
evaluating the foldtext setting for the rest of the folds in the current 
window. (See attached patch)

regards,
Christian
-- 

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


diff --git a/src/fold.c b/src/fold.c
--- a/src/fold.c
+++ b/src/fold.c
@@ -1930,8 +1930,21 @@
     char_u	*buf;
 {
     char_u	*text = NULL;
+#ifdef FEAT_EVAL
+     /* an error occurred when evaluating 'fdt' setting */
+    static	int got_fdt_error = FALSE;
+    int		save_did_emsg = did_emsg;
+    static	win_T*	last_wp = NULL;
+    static	linenr_T last_lnum = 0;
 
-#ifdef FEAT_EVAL
+    if ((last_wp != wp || last_wp == NULL) ||
+	(last_lnum > lnum || last_lnum == 0))
+	/* window changed, try evaluating foldtext setting once again */
+	got_fdt_error = FALSE;
+
+    if (!got_fdt_error)
+	did_emsg = FALSE; /* might not yet been reset from a previous error */
+
     if (*wp->w_p_fdt != NUL)
     {
 	char_u	dashes[MAX_LEVEL + 2];
@@ -1952,19 +1965,30 @@
 	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;
+	if (!got_fdt_error) /* skip evaluating foldtext on errors */
+	{
+	    save_curwin = curwin;
+	    curwin = wp;
+	    curbuf = wp->w_buffer;
 
-	++emsg_off;
-	text = eval_to_string_safe(wp->w_p_fdt, NULL,
-			 was_set_insecurely((char_u *)"foldtext", OPT_LOCAL));
-	--emsg_off;
+	    ++emsg_off;
+	    text = eval_to_string_safe(wp->w_p_fdt, NULL,
+			    was_set_insecurely((char_u *)"foldtext", OPT_LOCAL));
+	    --emsg_off;
 
-	curwin = save_curwin;
-	curbuf = curwin->w_buffer;
+	    if (text == NULL)
+		got_fdt_error = TRUE;
+
+	    curwin = save_curwin;
+	    curbuf = curwin->w_buffer;
+	}
+	last_lnum = lnum;
+	last_wp   = wp;
 	set_vim_var_string(VV_FOLDDASHES, NULL, -1);
 
+	if (!did_emsg && save_did_emsg)
+	    did_emsg = save_did_emsg;
+
 	if (text != NULL)
 	{
 	    /* Replace unprintable characters, if there are any.  But

Raspunde prin e-mail lui