diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/autoload/usermark.vim | 7 | ||||
-rw-r--r-- | runtime/autoload/userreg.vim | 7 | ||||
-rw-r--r-- | runtime/doc/options.txt | 56 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/semantic_tokens.lua | 6 | ||||
-rw-r--r-- | runtime/lua/vim/usermark.lua | 68 | ||||
-rw-r--r-- | runtime/lua/vim/userreg.lua | 51 | ||||
-rw-r--r-- | runtime/plugin/usermark.vim | 1 | ||||
-rw-r--r-- | runtime/plugin/userreg.vim | 1 |
8 files changed, 193 insertions, 4 deletions
diff --git a/runtime/autoload/usermark.vim b/runtime/autoload/usermark.vim new file mode 100644 index 0000000000..b1b4113d1a --- /dev/null +++ b/runtime/autoload/usermark.vim @@ -0,0 +1,7 @@ +" This is used for the default userreg function. + +lua vim.usermark = require('vim.usermark') + +function! usermark#func(action, mark) abort + return v:lua.vim.usermark.fn(a:action, a:mark) +endfunction diff --git a/runtime/autoload/userreg.vim b/runtime/autoload/userreg.vim new file mode 100644 index 0000000000..fd026a12e6 --- /dev/null +++ b/runtime/autoload/userreg.vim @@ -0,0 +1,7 @@ +" This is used for the default userreg function. + +lua vim.userreg = require('vim.userreg') + +function! userreg#func(action, register, content) abort + return v:lua.vim.userreg.fn(a:action, a:register, a:content) +endfunction diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index b1af90a604..2bd976fa43 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -1371,7 +1371,8 @@ A jump table for the options with a short description can be found at |Q_op|. 'colorcolumn' 'cc' string (default "") local to window 'colorcolumn' is a comma-separated list of screen columns that are - highlighted with ColorColumn |hl-ColorColumn|. Useful to align + highlighted with ColorColumn |hl-ColorColumn| and drawn using the + "colorcol" option from 'fillchars'. Useful to align text. Will make screen redrawing slower. The screen column can be an absolute number, or a number preceded with '+' or '-', which is added to or subtracted from 'textwidth'. > @@ -2501,6 +2502,7 @@ A jump table for the options with a short description can be found at |Q_op|. diff '-' deleted lines of the 'diff' option msgsep ' ' message separator 'display' eob '~' empty lines at the end of a buffer + colorcol ' ' character to display in the colorcolumn lastline '@' 'display' contains lastline/truncate Any one that is omitted will fall back to the default. For "stl" and @@ -2539,6 +2541,7 @@ A jump table for the options with a short description can be found at |Q_op|. fold Folded |hl-Folded| diff DiffDelete |hl-DiffDelete| eob EndOfBuffer |hl-EndOfBuffer| + colorcol:c ColorColumn |hl-ColorColumn| lastline NonText |hl-NonText| *'fixendofline'* *'fixeol'* *'nofixendofline'* *'nofixeol'* @@ -6828,6 +6831,57 @@ A jump table for the options with a short description can be found at |Q_op|. written to disk (see |crash-recovery|). Also used for the |CursorHold| autocommand event. + *'userregfunc'* *'urf'* +'userregfunc' 'urf' string (default "") + global + The option specifies a function to be used to handle any registers + that Neovim does not natively handle. This option unlocks all + characters to be used as registers by the user. + + The 'userregfunc' function is called each time a user register is read + from or written to. + + The 'userregfunc' function must take the following parameters: + + {action} The action being done on this register (either 'yank' + or 'put' + + {register} The string holding the name of the register. This + is always a single character, though multi-byte + characters are allowed. + + {content} If the action is 'yank' this is the content being + yanked into the register. The content is a dictionary + with the following items: + + {lines} The lines being yanked, as a list. + + {type} The type of yank, either "line", "char", or + "block" + + {width} The width in case of "block" mode. + + {additional_data} Additional data. (can be returned in + put mode). + + In case the action is 'put', the 'userregfunc' function should return + the content to place in that location. The content can either be a + string, in which case "char" mode is inferred, or it can return a + dictionary of the same template that populates 'content'. + + A very simple example of a 'userregfunc' function that behaves exactly + like traditional registers would look like: > + + 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 userregfunc=MyUserregFunction +< *'varsofttabstop'* *'vsts'* 'varsofttabstop' 'vsts' string (default "") local to buffer diff --git a/runtime/lua/vim/lsp/semantic_tokens.lua b/runtime/lua/vim/lsp/semantic_tokens.lua index b1bc48dac6..a9d3d0cbd6 100644 --- a/runtime/lua/vim/lsp/semantic_tokens.lua +++ b/runtime/lua/vim/lsp/semantic_tokens.lua @@ -330,7 +330,7 @@ function STHighlighter:process_response(response, client, version) end vim.list_extend(tokens, old_tokens, idx) else - tokens = response.data + tokens = response.data or {} end -- Update the state with the new results @@ -378,7 +378,7 @@ function STHighlighter:on_win(topline, botline) -- -- Instead, we have to use normal extmarks that can attach to locations -- in the buffer and are persisted between redraws. - local highlights = current_result.highlights + local highlights = current_result.highlights or {} local idx = binary_search(highlights, topline) for i = idx, #highlights do @@ -612,7 +612,7 @@ function M.get_at_pos(bufnr, row, col) local tokens = {} for client_id, client in pairs(highlighter.client_state) do - local highlights = client.current_result.highlights + local highlights = client.current_result.highlights or {} if highlights then local idx = binary_search(highlights, row) for i = idx, #highlights do diff --git a/runtime/lua/vim/usermark.lua b/runtime/lua/vim/usermark.lua new file mode 100644 index 0000000000..0d1ec0ae0f --- /dev/null +++ b/runtime/lua/vim/usermark.lua @@ -0,0 +1,68 @@ +-- Defualt implementation of the usermarkfunc. This default implementation is +-- extensible and allows other plugins to register handlers for different +-- registers. +-- +-- The default handler behaves just as a normal register would. + +local vim = assert(vim) +local usermark = {} + +-- Returns a "default handler" which behaves like normal global marks. When a +-- call to set() is made, it stores the current line and col of the cursor and +-- the filename of the current file. +function usermark._default_handler() + local d = {} + + -- Called when a mark is recalled using the "'" command. Just returns what was + -- stored before or nothing if it was never set before. + function d.get(self, mark) + return self.content or {} + end + + -- Called when a mark is set using the "m" command. Stores the current cursor + -- position to be recalled at a later time. + function d.set(self, mark) + local r,c = unpack(vim.api.nvim_win_get_cursor(0)) + local file = vim.fn.expand("%:p") + + self.content = { + line = r; + col = c; + } + + if file ~= '' then + self.content.file = file + end + end + + return d +end + +-- The store for register default handler +usermark._marktable = {} + +-- Function for the 'usermarkfunc'. Will defer to the handler associated with +-- the provided mark. +-- +-- If not handler is registered to a given mark, the default handler is used, +-- which is a re-implementation of standard mark behavior. +function usermark.fn(action, mark) + if not usermark._marktable[mark] then + usermark._marktable[mark] = usermark._default_handler() + end + + if action == "get" then + return usermark._marktable[mark]:get(mark) + else + usermark._marktable[mark]:set(mark) + return nil + end +end + +-- Registers a handler with a mark. Gets and sets will then defer to this +-- handler when determining the mark's behavior. +function usermark.register_handler(mark, handler) + usermark._marktable[mark] = handler +end + +return usermark diff --git a/runtime/lua/vim/userreg.lua b/runtime/lua/vim/userreg.lua new file mode 100644 index 0000000000..5abcff0407 --- /dev/null +++ b/runtime/lua/vim/userreg.lua @@ -0,0 +1,51 @@ +-- Defualt implementation of the userregfunc. This default implementation is +-- extensible and allows other plugins to register handlers for different +-- registers. +-- +-- The default handler behaves just as a normal register would. + +local userreg = {} + +-- Returns a "default handler" which behaves exactly like the builtin registers +-- in Vim. Simply stores whatever was yanked and returns the last thing that was +-- yanked. +function userreg._default_handler() + local d = {} + + function d.do_yank(self, content) + self.content = content + end + + function d.do_put(self) + return self.content or {} + end + + return d +end + +-- The store for registers default handler +userreg._regtable = {} + +-- Function for the userreg. This function will defer to the handler registered +-- to the given register. If no handler is registered to the given register, the +-- default handler is used. +function userreg.fn(action, register, content) + if not userreg._regtable[register] then + userreg._regtable[register] = userreg._default_handler() + end + + if action == "yank" then + userreg._regtable[register]:do_yank(content) + return nil + else + return userreg._regtable[register]:do_put() + end +end + +-- Registers a handler with a register. Future yanks and puts will defer to the +-- handler when determining the content to put/yank. +function userreg.register_handler(register, handler) + userreg._regtable[register] = handler +end + +return userreg diff --git a/runtime/plugin/usermark.vim b/runtime/plugin/usermark.vim new file mode 100644 index 0000000000..917e7510f1 --- /dev/null +++ b/runtime/plugin/usermark.vim @@ -0,0 +1 @@ +set usermarkfunc=usermark#func diff --git a/runtime/plugin/userreg.vim b/runtime/plugin/userreg.vim new file mode 100644 index 0000000000..099e7c65cb --- /dev/null +++ b/runtime/plugin/userreg.vim @@ -0,0 +1 @@ +set userregfunc=userreg#func |