diff options
author | AdnoC <adam.r.cutler@gmail.com> | 2016-05-04 14:16:19 -0400 |
---|---|---|
committer | AdnoC <adam.r.cutler@gmail.com> | 2017-05-31 13:19:08 -0400 |
commit | 9a91ce4fa6a7504644e10a6761eae5cc5699159a (patch) | |
tree | 1afe9cfbb2c5a3a0254289993c34c68cbc5b83fc | |
parent | a00b03d03f1c8e3aced87c54da7223672bce720d (diff) | |
download | rneovim-9a91ce4fa6a7504644e10a6761eae5cc5699159a.tar.gz rneovim-9a91ce4fa6a7504644e10a6761eae5cc5699159a.tar.bz2 rneovim-9a91ce4fa6a7504644e10a6761eae5cc5699159a.zip |
eval: Add ability to set the unnamed register with setreg
-rw-r--r-- | runtime/doc/eval.txt | 2 | ||||
-rw-r--r-- | src/nvim/eval.c | 12 | ||||
-rw-r--r-- | src/nvim/ops.c | 16 |
3 files changed, 29 insertions, 1 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index f076458fed..f73599ebd9 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -6710,6 +6710,8 @@ setreg({regname}, {value} [, {options}]) used as the width of the selection - if it is not specified then the width of the block is set to the number of characters in the longest line (counting a <Tab> as 1 character). + If {options} contains "u" or '"', then the unnamed register is + set to point to register {regname}. If {options} contains no register settings, then the default is to use character mode unless {value} ends in a <NL> for diff --git a/src/nvim/eval.c b/src/nvim/eval.c index e4b3128930..473de02ab6 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -5100,7 +5100,8 @@ bool garbage_collect(bool testing) do { yankreg_T reg; char name = NUL; - reg_iter = op_register_iter(reg_iter, &name, ®); + bool is_unnamed = false; + reg_iter = op_register_iter(reg_iter, &name, ®, &is_unnamed); if (name != NUL) { ABORTING(set_ref_dict)(reg.additional_data, copyID); } @@ -14792,6 +14793,7 @@ static void f_setreg(typval_T *argvars, typval_T *rettv, FunPtr fptr) regname = '"'; } + bool set_unnamed = false; if (argvars[2].v_type != VAR_UNKNOWN) { const char *stropt = tv_get_string_chk(&argvars[2]); if (stropt == NULL) { @@ -14820,6 +14822,10 @@ static void f_setreg(typval_T *argvars, typval_T *rettv, FunPtr fptr) } break; } + case 'u': case '"': { // unnamed register + set_unnamed = true; + break; + } } } } @@ -14872,6 +14878,10 @@ free_lstval: append, yank_type, block_len); } rettv->vval.v_number = 0; + + if (set_unnamed) { + op_register_set_previous(regname); + } } /* diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 9e5121b3fe..90d9d41a2a 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -5853,3 +5853,19 @@ const yankreg_T *op_register_get(const char name) } return &y_regs[i]; } + +/// Set the previous yank register +/// +/// @param[in] name Register name. +/// +/// @return true on success, false on failure. +bool op_register_set_previous(const char name) +{ + int i = op_reg_index(name); + if (i == -1) { + return false; + } + + y_previous = &y_regs[i]; + return true; +} |