aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ops.c
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2023-02-02 19:02:58 +0000
committerJosh Rahm <joshuarahm@gmail.com>2023-02-02 19:02:58 +0000
commitb255fa570d8b041e4c81e3454d51e06100c2fa4f (patch)
treed3b246b467500ca48067ed4a45d2fa53966cd9f1 /src/nvim/ops.c
parenteeccad2ff1ae8892fe9e06d733a7b07a166eecb0 (diff)
parent0bd07bea095a8000cffa4f379c1fa53e009c1143 (diff)
downloadrneovim-20230125_mix.tar.gz
rneovim-20230125_mix.tar.bz2
rneovim-20230125_mix.zip
Merge branch 'aucmd_textputpost' into 20230125_mix20230125_mix
Diffstat (limited to 'src/nvim/ops.c')
-rw-r--r--src/nvim/ops.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index 93449f2337..86e317b7f6 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -3203,6 +3203,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!
///
@@ -3990,6 +4040,8 @@ error:
curwin->w_set_curswant = true;
end:
+ do_autocmd_textputpost(regname, reg);
+
if (cmdmod.cmod_flags & CMOD_LOCKMARKS) {
curbuf->b_op_start = orig_start;
curbuf->b_op_end = orig_end;