aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval.c
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2022-08-21 22:01:00 -0600
committerJosh Rahm <joshuarahm@gmail.com>2022-08-21 22:01:00 -0600
commit5b0e381a261b1450735f4eddac55aeb956c13713 (patch)
treec61f6f14f8b5dc9e2d2f8ed1f78f50179ae3b33a /src/nvim/eval.c
parentd5cc161deac2371a39821c94fd2de4f1c41b6eb9 (diff)
downloadrneovim-5b0e381a261b1450735f4eddac55aeb956c13713.tar.gz
rneovim-5b0e381a261b1450735f4eddac55aeb956c13713.tar.bz2
rneovim-5b0e381a261b1450735f4eddac55aeb956c13713.zip
feat(userreg): Add user-defined registers to Neovim.
This change unlocks additional registers for Neovim by allowing a user to define their own behavior for non-builtin registers. This is accopmlished through a new option 'userregfunc' The 'userregfunc' defines the function to call when handling a register for which there is no builtin functionality. The 'userregfunc' function should take 3 arguments: action - Either "yank" or "put" register - The character corresponding to the register content - In the case of action == "yank", the dictionary describing the yanked content, with the following keys: {type} - Either "char", "line" or "block" {lines} - The lines being yanked as a list {width} - The width in case of "block" mode. {additional_data} - Additional data (can be returned in "put" mode) In case of "put" this function should return the content to put. This content can be either: * A dictionary in the same template as content above. * A list of strings. This will be assumed to be "line" mode. * A string. This will be assumed to be "char" mode. An example of a "null" 'userregfunc' that provides an implementation identical to traditional vim registers would be: let s:contents = {} function! MyUserregFunction(action, register, content) abort if a:action == "put" return get(s:contents, a:register, "") else let s:contents[a:register] = a:content endif endfunction set userregfun=MyUserregFunction It is important to note that any valid unicode character can now be a register, including something like @☺. This change also addresses the multibyte parsing issues surrounding let @a = 'xyz' let @🔨 = 'hammer'
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r--src/nvim/eval.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index cb46e26f82..05497e86ce 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -3061,12 +3061,10 @@ static int eval7(char **arg, typval_T *rettv, int evaluate, int want_string)
// Register contents: @r.
case '@':
(*arg)++;
+ int regname = mb_cptr2char_adv((const char_u**) arg);
if (evaluate) {
rettv->v_type = VAR_STRING;
- rettv->vval.v_string = get_reg_contents(**arg, kGRegExprSrc);
- }
- if (**arg != NUL) {
- (*arg)++;
+ rettv->vval.v_string = get_reg_contents(regname, kGRegExprSrc);
}
break;
@@ -4166,7 +4164,7 @@ bool garbage_collect(bool testing)
// registers (ShaDa additional data)
{
- const void *reg_iter = NULL;
+ iter_register_T reg_iter = ITER_REGISTER_NULL;
do {
yankreg_T reg;
char name = NUL;
@@ -4175,7 +4173,7 @@ bool garbage_collect(bool testing)
if (name != NUL) {
ABORTING(set_ref_dict)(reg.additional_data, copyID);
}
- } while (reg_iter != NULL);
+ } while (reg_iter != ITER_REGISTER_NULL);
}
// global marks (ShaDa additional data)