mirror of
https://github.com/neovim/neovim.git
synced 2025-10-13 05:16:09 +00:00
Add vim_feedkeys API function
- New API function to push data to the typeahead buffer - this should equivalent to the vimscript feedkeys() function - In Vim there was a --remote-send command to insert input into a Vim server instance. Besides accepting key sequences it also translated special keys such as <CR> or <Leader>, backslash notation is ignored. This commit backports the original Vim handler for --remote-send as a bool option for vim_feedkeys() - vim-patch:0
This commit is contained in:

committed by
Thiago de Arruda

parent
aad2a69c96
commit
67c5684e23
@@ -19,6 +19,8 @@
|
|||||||
#include "nvim/message.h"
|
#include "nvim/message.h"
|
||||||
#include "nvim/eval.h"
|
#include "nvim/eval.h"
|
||||||
#include "nvim/misc2.h"
|
#include "nvim/misc2.h"
|
||||||
|
#include "nvim/term.h"
|
||||||
|
#include "nvim/getchar.h"
|
||||||
|
|
||||||
#define LINE_BUFFER_SIZE 4096
|
#define LINE_BUFFER_SIZE 4096
|
||||||
|
|
||||||
@@ -47,6 +49,60 @@ void vim_command(String str, Error *err)
|
|||||||
try_end(err);
|
try_end(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Pass input keys to Neovim
|
||||||
|
///
|
||||||
|
/// @param keys to be typed
|
||||||
|
/// @param replace_tcodes If true replace special keys such as <CR> or <Leader>
|
||||||
|
/// for compatibility with Vim --remote-send expressions
|
||||||
|
/// @param remap If True remap keys
|
||||||
|
/// @param typed Handle keys as if typed; otherwise they are handled as
|
||||||
|
/// if coming from a mapping. This matters for undo,
|
||||||
|
/// opening folds, etc.
|
||||||
|
void vim_feedkeys(String keys, Boolean replace_tcodes, Boolean remap,
|
||||||
|
Boolean typed, Error *err)
|
||||||
|
{
|
||||||
|
char *ptr = NULL;
|
||||||
|
char *cpo_save = (char *)p_cpo;
|
||||||
|
|
||||||
|
if (replace_tcodes) {
|
||||||
|
// Set 'cpoptions' the way we want it.
|
||||||
|
// B set - backslashes are *not* treated specially
|
||||||
|
// k set - keycodes are *not* reverse-engineered
|
||||||
|
// < unset - <Key> sequences *are* interpreted
|
||||||
|
// The last but one parameter of replace_termcodes() is TRUE so that the
|
||||||
|
// <lt> sequence is recognised - needed for a real backslash.
|
||||||
|
p_cpo = (char_u *)"Bk";
|
||||||
|
replace_termcodes((char_u *)keys.data, (char_u **)&ptr, false, true, true);
|
||||||
|
p_cpo = (char_u *)cpo_save;
|
||||||
|
} else {
|
||||||
|
ptr = keys.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ptr == NULL) {
|
||||||
|
set_api_error("Failed to eval expression", err);
|
||||||
|
} else {
|
||||||
|
// Add the string to the input stream.
|
||||||
|
// Can't use add_to_input_buf() here, we now have K_SPECIAL bytes.
|
||||||
|
//
|
||||||
|
// First clear typed characters from the typeahead buffer, there could
|
||||||
|
// be half a mapping there. Then append to the existing string, so
|
||||||
|
// that multiple commands from a client are concatenated.
|
||||||
|
if (typebuf.tb_maplen < typebuf.tb_len) {
|
||||||
|
del_typebuf(typebuf.tb_len - typebuf.tb_maplen, typebuf.tb_maplen);
|
||||||
|
}
|
||||||
|
(void)ins_typebuf((char_u *)ptr, (remap ? REMAP_YES : REMAP_NONE),
|
||||||
|
typebuf.tb_len, !typed, false);
|
||||||
|
|
||||||
|
// Let input_available() know we inserted text in the typeahead
|
||||||
|
// buffer. */
|
||||||
|
typebuf_was_filled = true;
|
||||||
|
|
||||||
|
if (replace_tcodes) {
|
||||||
|
free(ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Evaluates the expression str using the vim internal expression
|
/// Evaluates the expression str using the vim internal expression
|
||||||
/// evaluator (see |expression|).
|
/// evaluator (see |expression|).
|
||||||
/// Dictionaries and lists are recursively expanded.
|
/// Dictionaries and lists are recursively expanded.
|
||||||
|
Reference in New Issue
Block a user