On Thu, 27 Apr 2006 at 9:11pm, Bram Moolenaar wrote:
>
> Hari Kirshna Dara wrote:
>
> > > > I am trying to use feedkeys() to give input to a Vim command that is
> > > > expecting input from the user, and it works if the command is not
> > > > executed using :silent prefix. Here is an example (executed on JDK
1.4.2
> > > > source):
> > > >
> > > > :ta Integer
> > > > tag 1 of 11 or more
> > > > :call feedkeys("4\<CR>") | ts
> > > > <takes me to the 4th tag>
> > > >
> > > > If I prefix the :ts command with :silent, this doesn't work, and the
fed
> > > > keys are handled by Vim as normal mode commands.
> > > >
> > > > :call feedkeys("4\<CR>") | silent ts
> > >
> > > If you try ":silent ts" manually you will see that this doesn't work
> > > either. This has nothing to do with feedkeys(). If you silence an
> > > interactive command you can predict it won't work. This is mostly to
> > > prevent Vim from an apparent hang when someone uses ":silent" for an
> > > interactive command (often indirectly).
> >
> > I understand that silencing an interactive command should work this way,
> > but when there are keys to be consumed, especially fed in advance using
> > feedkeys(), what is wrong in feeding to the interactive command? To me,
> > the usefulness of feedkeys() goes down significantly if this is not
> > supported. In fact, I don't know where you would need feedkeys() as
> > using a dynamic mapping can already achieve this.
>
> I don't know what you are talking about. The "4\<CR>" in your example
> is executed, the cursor moves four lines down.
>
> Making interactive commands with ":silent" sometimes accept keys and
> sometimes not makes them unpredictable. Consider the hit-enter prompt,
> for example.
Can you give a case where they can be unpredictable? My understanding is
that the keys can only be deliberately input to the command either
through feedkeys() or other programmatic techniques, so if a user
executed an interactive command deliberately using :silent, then there
are no keys expected. Also, it will almost always be a script that will
execute an interactive command this way, why would a user want to do
this at the command-line? Is it not going to be useful to be able to
feedkeys() to any interactive command so that we can wrap those commands
with custom functionality/defaults?
>
> > All interactive commands in unix work with redirected stdio (well,
> > except those that directly open the console, which are very rare), and
> > why shouldn't this be the case with vim commands? We have output
> > redirection for interactive commands, why can't they have a way to take
> > input by other means?
>
> You are over-generalizing. Does firefox redirect stdio? Does "reboot"?
> This only applies to commands that were made to be used in a pipe.
Sorry, I meant all console programs that expect user input. Those that
use cursors probably don't fall into this category, as they might be
opening the tty directly instead of using stdin.
--
Thanks,
Hari
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com