:echo is not working under certain conditions

Showing 1-4 of 4 messages
:echo is not working under certain conditions Marco Hinz 9/28/12 7:04 AM
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^
Re: :echo is not working under certain conditions Christian Brabandt 10/23/12 7:03 AM
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

Re: :echo is not working under certain conditions Bram Moolenaar 10/24/12 9:17 PM
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 -- Bram@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    ///
Re: :echo is not working under certain conditions Christian Brabandt 11/16/12 2:00 PM
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.