:echo is not working under certain conditions

56 views
Skip to first unread message

Marco Hinz

unread,
Sep 28, 2012, 10:04:53 AM9/28/12
to vim...@googlegroups.com
Hello!

A member of #vim has experienced a weird behaviour while Vim
scripting. Under certain conditions :echo would only print one line at
max. Thus neither 2x echo nor 1x echo containing a \n would work.


Conditions:

1) the :echo's are wrapped in an if/endif block

2) the if/endif block is the last statement in a function


Here is the corresponding stackoverflow.com thread:

http://stackoverflow.com/questions/12621333/vim-visual-key-input-strange-behaviour


mhi^

Christian Brabandt

unread,
Oct 23, 2012, 10:03:38 AM10/23/12
to vim...@googlegroups.com
Let me summarize the problem:
In the following case, :echo does not seem to work.

noremap <silent> f :call Test()<cr>
fun! Test()
call input("OK? ")
if 1
echo "foobar\nfoo"
endif
endfun

But it works, if you change the function to:

fun! Test()
call input("OK? ")
if 1
echo "foobar\nfoo"
endif
let a = 1
endfun

The problem is, that did_endif is not correctly reset and a recursive
call of do_cmdline() changes the global variable did_endif without
being reset.

Here is a patch:
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -1537,6 +1537,8 @@
#endif

--call_depth;
+ if (did_endif)
+ did_endif = FALSE;
return retval;
}

regards,
Christian

Bram Moolenaar

unread,
Oct 25, 2012, 12:17:12 AM10/25/12
to Christian Brabandt, vim...@googlegroups.com
Good catch. Would it be possible to write a test that fails without the
fix?

--
It doesn't really matter what you are able to do if you don't do it.
(Bram Moolenaar)

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Christian Brabandt

unread,
Nov 16, 2012, 5:00:43 PM11/16/12
to vim...@googlegroups.com
Hi Bram!
I haven't been able to create a test case. If I redirect the output, it
will still be visible.

regards,
Christian
--
Hebt ein Tier am Baum ein Bein, wei� man gleich, das ist kein Schwein.
Reply all
Reply to author
Forward
0 new messages