Method: VimClient#send_keys2
- Defined in:
- lib/vim_client.rb
#send_keys2(keys, expr = '""') ⇒ String, Nil
Send Keys to the remote server and wait for a reply.
This method is similar to send_keys, except that it adds a callback
to the end of the keys sent, then returns the result of expr.
The keys parameter follows the same rules as send_keys.
The expr parameter follows the same rules as send_expr, except
that this expression must return a String; whereas send_expr will
automatically convert a List (Array) into a String.
For example, the following would be equivalent:
VimClient.send_expr('setline(1,["line one", "line two"])')
VimClient.send_expr('getline(1,"$")') # => "line one\nline two"
VimClient.send_keys2(
':call setline(1,["line one", "line two"])<cr>',
'join(getline(1,"$"), "\\n")'
) # => "line one\nline two"
If no expr is given, then the expr will simply return an empty string.
Note: While setline() can be used with send_keys and send_keys2
(i.e. --remote-send) to set the buffer text, any keycodes within
these command strings (including within string-literals) will be interpreted.
To understand this better, what this method actually does is append
a call to Vim's server2client() function.
It then waits for the reply, like calling remote_read().
# When you send the following:
VimClient.send_keys2(":sleep 1<cr>")
# What actually gets sent is:
# :sleep 1<cr>server2client(expand("<client>"), "")<cr>
# When sending:
VimClient.send_keys2(":sleep 1<cr>", "localtime()")
# This is sent:
# :sleep 1<cr>server2client(expand("<client>"), localtime())<cr>
The strings given for keys and expr must be in the same encoding
or an Error will be raised.
A call to send_keys2 may be preceded by other calls to send_keys, as keys sent asynchronously and added to the server's typeahead buffer.
As with send_keys, any error reported by the server will not be
reported. This includes any error evaluating the expr given to
server2client(). However, since this call is waiting for a reply,
a TimeoutError would be raised.
The basic equivalent non-VimClient call for this method would be:
response = %x{
gvim -fes -u NONE +'call remote_send("server_name", \
'\\'':sleep 1 | call server2client(expand("<client>"), localtime())<cr>'\\'', "sid")' \
+'redir >> /dev/stdout | echo remote_read(sid) | redir END | q'
}
|
|
# File 'lib/vim_client.rb', line 183
|