diff options
author | Josh Rahm <rahm@google.com> | 2022-08-22 15:11:24 -0600 |
---|---|---|
committer | Josh Rahm <rahm@google.com> | 2022-08-22 15:11:24 -0600 |
commit | 8495168e18c5d9f0dc1a7f5b8fcd23d2d0ab4652 (patch) | |
tree | a034b1ad2f2ba2e96f7d56d70b2cf3cf18586887 | |
parent | de0704ff9ad57f53ae42f0f73de189084768679e (diff) | |
download | rneovim-userregs-8495168e18c5d9f0dc1a7f5b8fcd23d2d0ab4652.tar.gz rneovim-userregs-8495168e18c5d9f0dc1a7f5b8fcd23d2d0ab4652.tar.bz2 rneovim-userregs-8495168e18c5d9f0dc1a7f5b8fcd23d2d0ab4652.zip |
Add exprmark.
-rw-r--r-- | plugin/mark.lua | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/plugin/mark.lua b/plugin/mark.lua index dd3baa6..ccc6374 100644 --- a/plugin/mark.lua +++ b/plugin/mark.lua @@ -25,11 +25,10 @@ function middle_mark.set(self) api.nvim_command('norm z.') end --- The top mark is the first line on the window. Right now scrolloff is ignored, --- but maybe it shouldn't be. +-- The top mark is the first line on the window. This does respect scrolloff. local top_mark = {} function top_mark.get(self) - return vim.api.nvim_call_function('line', {'w0'}) + return vim.api.nvim_call_function('line', {'w0'}) + vim.o.scrolloff end -- Setting the top mark move the current line to the top. Principally this is -- the same mas z<cr> @@ -41,14 +40,36 @@ end -- this is the same as z- local bottom_mark = {} function bottom_mark.get(self) - return vim.api.nvim_call_function('line', {'w$'}) + return vim.api.nvim_call_function('line', {'w$'}) - vim.o.scrolloff end -- Setting the bottom mark doesn't do anything. function bottom_mark.set(self) api.nvim_command('norm z-') end +-- Mark that's like the expression register, but for a mark. +local expr_mark = {} +function expr_mark.get(self) + local mode = vim.api.nvim_call_function('mode', {}) + + if mode == "c" then + -- Avoid recurring asking for a value while in command mode. + return nil + end + + local expr = vim.api.nvim_call_function('input', {'='}) + if expr ~= "" then + return vim.api.nvim_eval(expr) + end + + return nil +end + +-- Setting the expr_mark does'nt do anything +function expr_mark.set(self) end + -- Register all the marks with their respective characters. usermark.register_handler('-', middle_mark) usermark.register_handler('+', top_mark) usermark.register_handler('_', bottom_mark) +usermark.register_handler('=', expr_mark) |