diff options
author | Rui Abreu Ferreira <raf-ep@gmx.com> | 2014-07-07 17:56:14 +0100 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-08-07 12:03:27 -0300 |
commit | 1dea4044e7582611072f5b7c93989e37ebb6ded6 (patch) | |
tree | 0d8bf4cb0d33f2e6e9382cae7f82727d3fefd682 /src/nvim/api/vim.c | |
parent | d8beb77b1b84fc9e40993af9610f0c4e9ddc9571 (diff) | |
download | rneovim-1dea4044e7582611072f5b7c93989e37ebb6ded6.tar.gz rneovim-1dea4044e7582611072f5b7c93989e37ebb6ded6.tar.bz2 rneovim-1dea4044e7582611072f5b7c93989e37ebb6ded6.zip |
Refactor vim_feedkeys and f_feedkeys
- To clean up the mix between feedkeys and replace_termcodes
the vim_feedkeys API function now does the same thing as the
vimscript feedkeys() function
- The original f_feedkeys() function now calls the vim_feedkeys()
function from the API
Diffstat (limited to 'src/nvim/api/vim.c')
-rw-r--r-- | src/nvim/api/vim.c | 65 |
1 files changed, 22 insertions, 43 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 6c793cbc54..a325459887 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -54,55 +54,34 @@ void vim_command(String str, Error *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) +/// @param mode specifies the mapping options +/// @see feedkeys() +void vim_feedkeys(String keys, String mode) { - 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; + bool remap = true; + bool typed = false; + + if (keys.size == 0) { + return; } - 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); + for (size_t i = 0; i < mode.size; ++i) { + switch (mode.data[i]) { + case 'n': remap = false; break; + case 'm': remap = true; break; + case 't': typed = true; break; } - (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; + /* Need to escape K_SPECIAL and CSI before putting the string in the + * typeahead buffer. */ + char *keys_esc = (char *)vim_strsave_escape_csi((char_u *)keys.data); + ins_typebuf((char_u *)keys_esc, (remap ? REMAP_YES : REMAP_NONE), + typebuf.tb_len, !typed, false); + free(keys_esc); - if (replace_tcodes) { - free(ptr); - } - } + if (vgetc_busy) + typebuf_was_filled = true; } /// Evaluates the expression str using the vim internal expression |