diff options
| author | Famiu Haque <famiuhaque@protonmail.com> | 2022-04-20 17:02:18 +0600 |
|---|---|---|
| committer | Famiu Haque <famiuhaque@protonmail.com> | 2022-05-31 20:55:05 +0600 |
| commit | 46536f53e82967dcac8d030ee3394cdb156f9603 (patch) | |
| tree | 4444067831639a6a1eb1916ca9cd5002261932ec /src/nvim/generators | |
| parent | e9803e1de6497ee21f77f45cf2670c2fe4e8ab22 (diff) | |
| download | rneovim-46536f53e82967dcac8d030ee3394cdb156f9603.tar.gz rneovim-46536f53e82967dcac8d030ee3394cdb156f9603.tar.bz2 rneovim-46536f53e82967dcac8d030ee3394cdb156f9603.zip | |
feat: add preview functionality to user commands
Adds a Lua-only `preview` flag to user commands which allows the command to be incrementally previewed like `:substitute` when 'inccommand' is set.
Diffstat (limited to 'src/nvim/generators')
| -rw-r--r-- | src/nvim/generators/gen_ex_cmds.lua | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/nvim/generators/gen_ex_cmds.lua b/src/nvim/generators/gen_ex_cmds.lua index 27cfe194fa..255c415a4d 100644 --- a/src/nvim/generators/gen_ex_cmds.lua +++ b/src/nvim/generators/gen_ex_cmds.lua @@ -65,20 +65,31 @@ for _, cmd in ipairs(defs) do assert(cmd.addr_type ~= 'ADDR_OTHER' and cmd.addr_type ~= 'ADDR_NONE', string.format('ex_cmds.lua:%s: Missing misplaced DFLALL\n', cmd.command)) end + if bit.band(cmd.flags, flags.PREVIEW) == flags.PREVIEW then + assert(cmd.preview_func ~= nil, + string.format('ex_cmds.lua:%s: Missing preview_func\n', cmd.command)) + end local enumname = cmd.enum or ('CMD_' .. cmd.command) local byte_cmd = cmd.command:sub(1, 1):byte() if byte_a <= byte_cmd and byte_cmd <= byte_z then table.insert(cmds, cmd.command) end + local preview_func + if cmd.preview_func then + preview_func = string.format("(ex_preview_func_T)&%s", cmd.preview_func) + else + preview_func = "NULL" + end enumfile:write(' ' .. enumname .. ',\n') defsfile:write(string.format([[ [%s] = { .cmd_name = "%s", .cmd_func = (ex_func_T)&%s, + .cmd_preview_func = %s, .cmd_argt = %uL, .cmd_addr_type = %s }, -]], enumname, cmd.command, cmd.func, cmd.flags, cmd.addr_type)) +]], enumname, cmd.command, cmd.func, preview_func, cmd.flags, cmd.addr_type)) end for i = #cmds, 1, -1 do local cmd = cmds[i] |