diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-11-30 20:35:57 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-11-30 20:35:57 +0000 |
commit | 54446b98a1425f780221c52c5bdb8aad1e78246a (patch) | |
tree | 2f9f5b80267ac84e01456dcea40c69712825d2f5 | |
parent | 412c6b971fcd5dadf370161dd2e0cd981c348eb8 (diff) | |
parent | 1b7b916b7631ddf73c38e3a0070d64e4636cb2f3 (diff) | |
download | rneovim-20231130_mix.tar.gz rneovim-20231130_mix.tar.bz2 rneovim-20231130_mix.zip |
Merge branch 'aucmd_textputpost' into 20231130_mix20231130_mix
-rw-r--r-- | src/nvim/auevents.lua | 1 | ||||
-rw-r--r-- | src/nvim/ops.c | 54 |
2 files changed, 55 insertions, 0 deletions
diff --git a/src/nvim/auevents.lua b/src/nvim/auevents.lua index 696df7c534..e50ca76d0e 100644 --- a/src/nvim/auevents.lua +++ b/src/nvim/auevents.lua @@ -115,6 +115,7 @@ return { 'TextChangedP', -- text was modified in Insert mode(popup) 'TextChangedT', -- text was modified in Terminal mode 'TextYankPost', -- after a yank or delete was done (y, d, c) + 'TextPutPost', -- after a put was done (p, P) 'UIEnter', -- after UI attaches 'UILeave', -- after UI detaches 'User', -- user defined autocommand diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 8c8900710d..2ef95f03c4 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -3167,6 +3167,56 @@ static void do_autocmd_textyankpost(oparg_T *oap, yankreg_T *reg) recursive = false; } +/// Execute autocommands for TextPutPost. +/// +/// @param oap Operator arguments. +/// @param reg The yank register used. +static void do_autocmd_textputpost(int regname, yankreg_T *reg) + FUNC_ATTR_NONNULL_ALL +{ + static bool recursive = false; + int len; + + if (recursive || !has_event(EVENT_TEXTPUTPOST)) { + // No autocommand was defined, or we yanked from this autocommand. + return; + } + + recursive = true; + + save_v_event_T save_v_event; + // Set the v:event dictionary with information about the yank. + dict_T *dict = get_v_event(&save_v_event); + + // The yanked text contents. + list_T *const list = tv_list_alloc((ptrdiff_t)reg->y_size); + for (size_t i = 0; i < reg->y_size; i++) { + tv_list_append_string(list, (const char *)reg->y_array[i], -1); + } + tv_list_set_lock(list, VAR_FIXED); + (void)tv_dict_add_list(dict, S_LEN("regcontents"), list); + + // Register type. + char buf[NUMBUFLEN + 6]; + format_reg_type(reg->y_type, reg->y_width, buf, ARRAY_SIZE(buf)); + (void)tv_dict_add_str(dict, S_LEN("regtype"), buf); + + // Name of requested register, or empty string for unnamed operation. + len = (*utf_char2len)(regname); + buf[len] = 0; + utf_char2bytes(regname, buf); + recursive = true; + (void)tv_dict_add_str(dict, S_LEN("regname"), buf); + + tv_dict_set_keys_readonly(dict); + textlock++; + apply_autocmds(EVENT_TEXTPUTPOST, NULL, NULL, false, curbuf); + textlock--; + restore_v_event(dict, &save_v_event); + + recursive = false; +} + /// Put contents of register "regname" into the text. /// Caller must check "regname" to be valid! /// @@ -3953,6 +4003,10 @@ error: } end: + if (reg) { + do_autocmd_textputpost(regname, reg); + } + if (cmdmod.cmod_flags & CMOD_LOCKMARKS) { curbuf->b_op_start = orig_start; curbuf->b_op_end = orig_end; |