diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2022-08-21 22:01:00 -0600 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2022-08-21 22:01:00 -0600 |
commit | 5b0e381a261b1450735f4eddac55aeb956c13713 (patch) | |
tree | c61f6f14f8b5dc9e2d2f8ed1f78f50179ae3b33a /src/nvim/ops.h | |
parent | d5cc161deac2371a39821c94fd2de4f1c41b6eb9 (diff) | |
download | rneovim-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/ops.h')
-rw-r--r-- | src/nvim/ops.h | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/nvim/ops.h b/src/nvim/ops.h index 05893c9940..a456d68003 100644 --- a/src/nvim/ops.h +++ b/src/nvim/ops.h @@ -22,6 +22,7 @@ typedef int (*Indenter)(void); #define PUT_LINE_SPLIT 16 // split line for linewise register #define PUT_LINE_FORWARD 32 // put linewise register below Visual sel. #define PUT_BLOCK_INNER 64 // in block mode, do not add trailing spaces +#define ITER_REGISTER_NULL 0 /* * Registers: @@ -37,7 +38,8 @@ typedef int (*Indenter)(void); // The following registers should not be saved in ShaDa file: #define STAR_REGISTER 37 #define PLUS_REGISTER 38 -#define NUM_REGISTERS 39 +#define USER_REGISTERS_START 39 +#define NUM_REGISTERS USER_REGISTERS_START // Operator IDs; The order must correspond to opchars[] in ops.c! #define OP_NOP 0 // no pending operation @@ -96,6 +98,8 @@ typedef enum { YREG_YANK, YREG_PUT, } yreg_mode_t; +/// Returns a reference to a user-defined register. +int get_userreg(const int regname); /// Convert register name into register index /// @@ -118,10 +122,15 @@ static inline int op_reg_index(const int regname) } else if (regname == '+') { return PLUS_REGISTER; } else { - return -1; + return get_userreg(regname); } } +struct yank_registers; +typedef struct yank_registers yank_registers_T; + +typedef size_t iter_register_T; + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "ops.h.generated.h" #endif |