mirror of
https://github.com/neovim/neovim.git
synced 2026-08-29 10:31:48 +00:00
feat(options): lua closure/function options
Problem:
Cannot assign Lua functions/closures to "func" ('completefunc',
'tagfun', …) or "expr" ('foldexpr', 'indentexpr', …) options.
Solution:
- Store "func"/"expr" options as `Callback` instead of string.
- Delete oceans of copy-pasted code.
- BREAKING: LuaRef returned via RPC/Vimscript is now represented as
`"<Lua N: file:line>"` (like what `:map` shows) instead of `nil`.
- Note: `man.vim` still uses `v:lua` string, bc it's a vimscript ftplugin.
Helped-by: Lewis Russell <lewis6991@gmail.com>
This commit is contained in:
@@ -446,14 +446,12 @@ do
|
||||
|
||||
-- Add empty lines
|
||||
vim.keymap.set('n', '[<Space>', function()
|
||||
-- TODO: update once it is possible to assign a Lua function to options #25672
|
||||
vim.go.operatorfunc = "v:lua.require'vim._core.util'.space_above"
|
||||
vim.go.operatorfunc = require('vim._core.util').space_above
|
||||
return 'g@l'
|
||||
end, { expr = true, desc = 'Add empty line above cursor' })
|
||||
|
||||
vim.keymap.set('n', ']<Space>', function()
|
||||
-- TODO: update once it is possible to assign a Lua function to options #25672
|
||||
vim.go.operatorfunc = "v:lua.require'vim._core.util'.space_below"
|
||||
vim.go.operatorfunc = require('vim._core.util').space_below
|
||||
return 'g@l'
|
||||
end, { expr = true, desc = 'Add empty line below cursor' })
|
||||
end
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
local M = {}
|
||||
|
||||
--- Adds one or more blank lines above or below the cursor.
|
||||
-- TODO: move to _core/defaults.lua once it is possible to assign a Lua function to options #25672
|
||||
--- @param above? boolean Place blank line(s) above the cursor
|
||||
local function add_blank(above)
|
||||
local offset = above and 1 or 0
|
||||
@@ -12,12 +11,10 @@ local function add_blank(above)
|
||||
vim.api.nvim_buf_set_lines(0, linenr - offset, linenr - offset, true, repeated)
|
||||
end
|
||||
|
||||
-- TODO: move to _core/defaults.lua once it is possible to assign a Lua function to options #25672
|
||||
function M.space_above()
|
||||
add_blank(true)
|
||||
end
|
||||
|
||||
-- TODO: move to _core/defaults.lua once it is possible to assign a Lua function to options #25672
|
||||
function M.space_below()
|
||||
add_blank()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user