From 689f5d604e59eba1ddab6f91b458a8163dc6629d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 1 Sep 2022 20:32:59 +0800 Subject: [PATCH] feat(api): add support for :horizontal modifier --- runtime/doc/api.txt | 1 + src/nvim/api/command.c | 7 +++++++ src/nvim/api/keysets.lua | 1 + src/nvim/lua/executor.c | 2 ++ test/functional/api/command_spec.lua | 13 +++++++++++-- test/functional/api/vim_spec.lua | 26 ++++++++++++++++++++++++-- 6 files changed, 46 insertions(+), 4 deletions(-) diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt index 89baf84c86..82978d0b3c 100644 --- a/runtime/doc/api.txt +++ b/runtime/doc/api.txt @@ -1839,6 +1839,7 @@ nvim_parse_cmd({str}, {opts}) *nvim_parse_cmd()* • browse: (boolean) |:browse|. • confirm: (boolean) |:confirm|. • hide: (boolean) |:hide|. + • horizontal: (boolean) |:horizontal|. • keepalt: (boolean) |:keepalt|. • keepjumps: (boolean) |:keepjumps|. • keepmarks: (boolean) |:keepmarks|. diff --git a/src/nvim/api/command.c b/src/nvim/api/command.c index 1323fc347b..b821e07d60 100644 --- a/src/nvim/api/command.c +++ b/src/nvim/api/command.c @@ -62,6 +62,7 @@ /// - browse: (boolean) |:browse|. /// - confirm: (boolean) |:confirm|. /// - hide: (boolean) |:hide|. +/// - horizontal: (boolean) |:horizontal|. /// - keepalt: (boolean) |:keepalt|. /// - keepjumps: (boolean) |:keepjumps|. /// - keepmarks: (boolean) |:keepmarks|. @@ -250,6 +251,7 @@ Dictionary nvim_parse_cmd(String str, Dictionary opts, Error *err) PUT(mods, "lockmarks", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_flags & CMOD_LOCKMARKS)); PUT(mods, "noswapfile", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_flags & CMOD_NOSWAPFILE)); PUT(mods, "vertical", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_split & WSP_VERT)); + PUT(mods, "horizontal", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_split & WSP_HOR)); const char *split; if (cmdinfo.cmdmod.cmod_split & WSP_BOT) { @@ -576,6 +578,10 @@ String nvim_cmd(uint64_t channel_id, Dict(cmd) *cmd, Dict(cmd_opts) *opts, Error OBJ_TO_BOOL(vertical, mods.vertical, false, "'mods.vertical'"); cmdinfo.cmdmod.cmod_split |= (vertical ? WSP_VERT : 0); + bool horizontal; + OBJ_TO_BOOL(horizontal, mods.horizontal, false, "'mods.horizontal'"); + cmdinfo.cmdmod.cmod_split |= (horizontal ? WSP_HOR : 0); + if (HAS_KEY(mods.split)) { if (mods.split.type != kObjectTypeString) { VALIDATION_ERROR("'mods.split' must be a String"); @@ -753,6 +759,7 @@ static void build_cmdline_str(char **cmdlinep, exarg_T *eap, CmdParseInfo *cmdin } while (0) CMDLINE_APPEND_IF(cmdinfo->cmdmod.cmod_split & WSP_VERT, "vertical "); + CMDLINE_APPEND_IF(cmdinfo->cmdmod.cmod_split & WSP_HOR, "horizontal "); CMDLINE_APPEND_IF(cmdinfo->cmdmod.cmod_flags & CMOD_SANDBOX, "sandbox "); CMDLINE_APPEND_IF(cmdinfo->cmdmod.cmod_flags & CMOD_NOAUTOCMD, "noautocmd "); CMDLINE_APPEND_IF(cmdinfo->cmdmod.cmod_flags & CMOD_BROWSE, "browse "); diff --git a/src/nvim/api/keysets.lua b/src/nvim/api/keysets.lua index 6fad52ba75..af3dc24f51 100644 --- a/src/nvim/api/keysets.lua +++ b/src/nvim/api/keysets.lua @@ -188,6 +188,7 @@ return { "browse"; "confirm"; "hide"; + "horizontal"; "keepalt"; "keepjumps"; "keepmarks"; diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index f144e47c3a..2315ecd874 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -2103,6 +2103,8 @@ int nlua_do_ucmd(ucmd_T *cmd, exarg_T *eap, bool preview) lua_pushboolean(lstate, cmdmod.cmod_split & WSP_VERT); lua_setfield(lstate, -2, "vertical"); + lua_pushboolean(lstate, cmdmod.cmod_split & WSP_HOR); + lua_setfield(lstate, -2, "horizontal"); lua_pushboolean(lstate, cmdmod.cmod_flags & CMOD_SILENT); lua_setfield(lstate, -2, "silent"); lua_pushboolean(lstate, cmdmod.cmod_flags & CMOD_ERRSILENT); 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, diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 24d0b6da45..2e37c4787d 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3195,6 +3195,7 @@ describe('API', function() force = false }, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -3236,6 +3237,7 @@ describe('API', function() force = false }, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -3277,6 +3279,7 @@ describe('API', function() force = false }, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -3318,6 +3321,7 @@ describe('API', function() force = false }, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -3359,6 +3363,7 @@ describe('API', function() force = false }, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -3400,6 +3405,7 @@ describe('API', function() force = false }, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -3441,6 +3447,7 @@ describe('API', function() force = false }, hide = false, + horizontal = true, keepalt = false, keepjumps = false, keepmarks = false, @@ -3456,7 +3463,7 @@ describe('API', function() verbose = 15, vertical = false, }, - }, meths.parse_cmd('15verbose silent! aboveleft topleft tab filter /foo/ split foo.txt', {})) + }, meths.parse_cmd('15verbose silent! horizontal topleft tab filter /foo/ split foo.txt', {})) eq({ cmd = 'split', args = { 'foo.txt' }, @@ -3480,6 +3487,7 @@ describe('API', function() force = true }, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -3522,6 +3530,7 @@ describe('API', function() force = false }, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -3563,6 +3572,7 @@ describe('API', function() force = false }, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -3605,6 +3615,7 @@ describe('API', function() force = false }, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -3697,6 +3708,7 @@ describe('API', function() force = false, }, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -3798,10 +3810,20 @@ describe('API', function() eq('1', meths.cmd({ cmd = 'echomsg', args = { '1' }, mods = { silent = true } }, { output = true })) - -- with :silent message isn't added to message history + -- but message isn't added to message history eq('', meths.cmd({ cmd = 'messages' }, { output = true })) meths.create_user_command("Foo", 'set verbose', {}) eq(" verbose=1", meths.cmd({ cmd = "Foo", mods = { verbose = 1 } }, { output = true })) + meths.create_user_command("Mods", "echo ''", {}) + eq('keepmarks keeppatterns silent 3verbose aboveleft horizontal', + meths.cmd({ cmd = "Mods", mods = { + horizontal = true, + keepmarks = true, + keeppatterns = true, + silent = true, + split = 'aboveleft', + verbose = 3, + } }, { output = true })) eq(0, meths.get_option_value("verbose", {})) command('edit foo.txt | edit bar.txt') eq(' 1 #h "foo.txt" line 1',