Loading ...
Sorry, an error occurred while loading the content.
 

Re: :echo is not working under certain conditions

Expand Messages
  • Christian Brabandt
    ... Let me summarize the problem: In the following case, :echo does not seem to work. noremap f :call Test() fun! Test() call input( OK? ) if 1
    Message 1 of 4 , Oct 23, 2012
      On Fri, September 28, 2012 16:04, Marco Hinz wrote:
      > 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

      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

      --
      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
    • Bram Moolenaar
      ... 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
      Message 2 of 4 , Oct 24, 2012
        Christian Brabandt wrote:

        > On Fri, September 28, 2012 16:04, Marco Hinz wrote:
        > > 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
        >
        > 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;
        > }

        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@... -- 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 ///

        --
        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
      • Christian Brabandt
        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
        Message 3 of 4 , Nov 16, 2012
          Hi Bram!

          On Do, 25 Okt 2012, Bram Moolenaar wrote:

          >
          > Christian Brabandt wrote:
          >
          > > On Fri, September 28, 2012 16:04, Marco Hinz wrote:
          > > > 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
          > >
          > > 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;
          > > }
          >
          > Good catch. Would it be possible to write a test that fails without the
          > fix?

          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.

          --
          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
        Your message has been successfully submitted and would be delivered to recipients shortly.