From 689f5d604e59eba1ddab6f91b458a8163dc6629d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 1 Sep 2022 20:32:59 +0800 Subject: feat(api): add support for :horizontal modifier --- test/functional/api/command_spec.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'test/functional/api/command_spec.lua') diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index 440e93da0e..2d8bf23f5b 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -125,6 +125,7 @@ describe('nvim_create_user_command', function() confirm = false, emsg_silent = false, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -160,6 +161,7 @@ describe('nvim_create_user_command', function() confirm = false, emsg_silent = false, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -195,6 +197,7 @@ describe('nvim_create_user_command', function() confirm = false, emsg_silent = false, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -224,12 +227,13 @@ describe('nvim_create_user_command', function() bang = true, line1 = 10, line2 = 10, - mods = "confirm unsilent botright", + mods = "confirm unsilent botright horizontal", smods = { browse = false, confirm = true, emsg_silent = false, hide = false, + horizontal = true, keepalt = false, keepjumps = false, keepmarks = false, @@ -249,7 +253,7 @@ describe('nvim_create_user_command', function() count = 10, reg = "", }, exec_lua [=[ - vim.api.nvim_command('unsilent botright confirm 10CommandWithLuaCallback! h\tey ') + vim.api.nvim_command('unsilent horizontal botright confirm 10CommandWithLuaCallback! h\tey ') return result ]=]) @@ -265,6 +269,7 @@ describe('nvim_create_user_command', function() confirm = false, emsg_silent = false, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -300,6 +305,7 @@ describe('nvim_create_user_command', function() confirm = false, emsg_silent = false, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -347,6 +353,7 @@ describe('nvim_create_user_command', function() confirm = false, emsg_silent = false, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -383,6 +390,7 @@ describe('nvim_create_user_command', function() confirm = false, emsg_silent = false, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -429,6 +437,7 @@ describe('nvim_create_user_command', function() confirm = false, emsg_silent = false, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, -- cgit From 1ef7720567b08caec0c077605fb2a01a9d6eafbc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 1 Sep 2022 18:46:34 +0800 Subject: fix(api)!: correctly deal with number before :tab Now nvim_parse_cmd and nvim_create_user_command use a "tab" value which is the same as the number passed before :tab modifier instead of the number plus 1, and "tab" value is -1 if :tab modifier is not used. --- test/functional/api/command_spec.lua | 41 +++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 10 deletions(-) (limited to 'test/functional/api/command_spec.lua') diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index 2d8bf23f5b..44a19d8348 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -136,7 +136,7 @@ describe('nvim_create_user_command', function() sandbox = false, silent = false, split = "", - tab = 0, + tab = -1, unsilent = false, verbose = -1, vertical = false, @@ -172,7 +172,7 @@ describe('nvim_create_user_command', function() sandbox = false, silent = false, split = "", - tab = 0, + tab = -1, unsilent = false, verbose = -1, vertical = false, @@ -208,7 +208,7 @@ describe('nvim_create_user_command', function() sandbox = false, silent = false, split = "", - tab = 0, + tab = -1, unsilent = false, verbose = -1, vertical = false, @@ -244,7 +244,7 @@ describe('nvim_create_user_command', function() sandbox = false, silent = false, split = "botright", - tab = 0, + tab = -1, unsilent = true, verbose = -1, vertical = false, @@ -280,7 +280,7 @@ describe('nvim_create_user_command', function() sandbox = false, silent = false, split = "", - tab = 0, + tab = -1, unsilent = false, verbose = -1, vertical = false, @@ -316,7 +316,7 @@ describe('nvim_create_user_command', function() sandbox = false, silent = false, split = "", - tab = 0, + tab = -1, unsilent = false, verbose = -1, vertical = false, @@ -364,7 +364,7 @@ describe('nvim_create_user_command', function() sandbox = false, silent = false, split = "", - tab = 0, + tab = -1, unsilent = false, verbose = -1, vertical = false, @@ -401,7 +401,7 @@ describe('nvim_create_user_command', function() sandbox = false, silent = false, split = "", - tab = 0, + tab = -1, unsilent = false, verbose = -1, vertical = false, @@ -448,7 +448,7 @@ describe('nvim_create_user_command', function() sandbox = false, silent = false, split = "", - tab = 0, + tab = -1, unsilent = false, verbose = -1, vertical = false, @@ -523,8 +523,29 @@ describe('nvim_create_user_command', function() vim.api.nvim_cmd({ cmd = 'echo', args = { '&verbose' }, mods = opts.smods }, {}) end, {}) ]] - eq("3", meths.cmd({ cmd = 'MyEcho', mods = { verbose = 3 } }, { output = true })) + + eq(1, #meths.list_tabpages()) + exec_lua[[ + vim.api.nvim_create_user_command('MySplit', function(opts) + vim.api.nvim_cmd({ cmd = 'split', mods = opts.smods }, {}) + end, {}) + ]] + meths.cmd({ cmd = 'MySplit' }, {}) + eq(1, #meths.list_tabpages()) + eq(2, #meths.list_wins()) + meths.cmd({ cmd = 'MySplit', mods = { tab = 1 } }, {}) + eq(2, #meths.list_tabpages()) + eq(2, funcs.tabpagenr()) + meths.cmd({ cmd = 'MySplit', mods = { tab = 1 } }, {}) + eq(3, #meths.list_tabpages()) + eq(2, funcs.tabpagenr()) + meths.cmd({ cmd = 'MySplit', mods = { tab = 3 } }, {}) + eq(4, #meths.list_tabpages()) + eq(4, funcs.tabpagenr()) + meths.cmd({ cmd = 'MySplit', mods = { tab = 0 } }, {}) + eq(5, #meths.list_tabpages()) + eq(1, funcs.tabpagenr()) end) end) -- cgit From 35e2c4a2edd28f72c48c70530c5486365c2502a4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 28 Sep 2022 18:27:59 +0800 Subject: fix(lua): fix architecture-dependent behavior in usercmd "reg" (#20384) I don't think using an integer as a NUL-terminated string can work on big-endian systems, at least. This is also not tested. Add a test. Also fix a mistake in the docs of nvim_parse_cmd. --- test/functional/api/command_spec.lua | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'test/functional/api/command_spec.lua') diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index 44a19d8348..f19d7a362b 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -423,6 +423,7 @@ describe('nvim_create_user_command', function() nargs = 0, bang = true, count = 2, + register = true, }) ]] eq({ @@ -460,6 +461,42 @@ describe('nvim_create_user_command', function() vim.cmd('CommandWithNoArgs') return result ]]) + -- register can be specified + eq({ + args = "", + fargs = {}, + bang = false, + line1 = 1, + line2 = 1, + mods = "", + smods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + horizontal = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + split = "", + tab = -1, + unsilent = false, + verbose = -1, + vertical = false, + }, + range = 0, + count = 2, + reg = "+", + }, exec_lua [[ + vim.cmd('CommandWithNoArgs +') + return result + ]]) end) -- cgit From c022140ec6a66402e405152054b6ab0141940419 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Mon, 7 Nov 2022 22:27:37 +0600 Subject: feat(api): add command name to Lua command callback opts Adds a `name` key to the opts dict passed to Lua command callbacks created using `nvim_create_user_command()`. This is useful for when multiple commands use the same callback. Note that this kind of behavior is not as strange as one might think, even some internal Neovim commands reuse the same internal C function, differing their behavior by checking the command name. `substitute`, `smagic` and `snomagic` are examples of that. This will also be useful for generalized Lua command preview functions that can preview a wide range of commands, in which case knowing the command name is necessary for the preview function to actually be able to execute the command that it's supposed to preview. --- test/functional/api/command_spec.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/functional/api/command_spec.lua') diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index f19d7a362b..d0fb26edc7 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -114,6 +114,7 @@ describe('nvim_create_user_command', function() ]] eq({ + name = "CommandWithLuaCallback", args = [[this\ is a\ test]], fargs = {"this ", "is", "a test"}, bang = false, @@ -150,6 +151,7 @@ describe('nvim_create_user_command', function() ]=]) eq({ + name = "CommandWithLuaCallback", args = [[this includes\ a backslash: \\]], fargs = {"this", "includes a", "backslash:", "\\"}, bang = false, @@ -186,6 +188,7 @@ describe('nvim_create_user_command', function() ]=]) eq({ + name = "CommandWithLuaCallback", args = "a\\b", fargs = {"a\\b"}, bang = false, @@ -222,6 +225,7 @@ describe('nvim_create_user_command', function() ]=]) eq({ + name = "CommandWithLuaCallback", args = 'h\tey ', fargs = {[[h]], [[ey]]}, bang = true, @@ -258,6 +262,7 @@ describe('nvim_create_user_command', function() ]=]) eq({ + name = "CommandWithLuaCallback", args = "h", fargs = {"h"}, bang = false, @@ -294,6 +299,7 @@ describe('nvim_create_user_command', function() ]]) eq({ + name = "CommandWithLuaCallback", args = "", fargs = {}, -- fargs works without args bang = false, @@ -342,6 +348,7 @@ describe('nvim_create_user_command', function() ]] eq({ + name = "CommandWithOneOrNoArg", args = "hello I'm one argument", fargs = {"hello I'm one argument"}, -- Doesn't split args bang = false, @@ -379,6 +386,7 @@ describe('nvim_create_user_command', function() -- f-args is an empty table if no args were passed eq({ + name = "CommandWithOneOrNoArg", args = "", fargs = {}, bang = false, @@ -427,6 +435,7 @@ describe('nvim_create_user_command', function() }) ]] eq({ + name = "CommandWithNoArgs", args = "", fargs = {}, bang = false, @@ -463,6 +472,7 @@ describe('nvim_create_user_command', function() ]]) -- register can be specified eq({ + name = "CommandWithNoArgs", args = "", fargs = {}, bang = false, -- cgit