From 4543fc1612183da659a9ca10f826ae59e2186f22 Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Sat, 30 Sep 2017 22:20:47 +0200 Subject: [PATCH 1/4] menu_get: prettyprint special chars --- src/nvim/menu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/nvim/menu.c b/src/nvim/menu.c index 0db250d111..69700e34fd 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -698,7 +698,9 @@ static dict_T *menu_get_recursive(const vimmenu_T *menu, int modes) if (*menu->strings[bit] == NUL) { tv_dict_add_str(impl, S_LEN("rhs"), (char *)""); } else { - tv_dict_add_str(impl, S_LEN("rhs"), (char *)menu->strings[bit]); + tv_dict_add_allocated_str(impl, S_LEN("rhs"), + str2special_save((char *)menu->strings[bit], + false, false)); } tv_dict_add_nr(impl, S_LEN("silent"), menu->silent[bit]); tv_dict_add_nr(impl, S_LEN("enabled"), From 9fb8b47ad845b0dc95da64705276c9f163e97f6c Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Sat, 30 Sep 2017 22:21:06 +0200 Subject: [PATCH 2/4] menu_get: adjust tests for prettyprinting ... and add a bit of new testing --- test/functional/ex_cmds/menu_spec.lua | 102 +++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 2 deletions(-) diff --git a/test/functional/ex_cmds/menu_spec.lua b/test/functional/ex_cmds/menu_spec.lua index 55da8da8dc..5238752af4 100644 --- a/test/functional/ex_cmds/menu_spec.lua +++ b/test/functional/ex_cmds/menu_spec.lua @@ -107,7 +107,7 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "inormal\27", + rhs = "inormal", silent = 0 }, v = { @@ -242,7 +242,7 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "\18\"", + rhs = "\"", silent = 0 }, n = { @@ -380,4 +380,102 @@ describe('menu_get', function() eq(expected, m) end) + it('prettyprints special chars', function() + clear() + command('nnoremenu &Test.Test inormal') + command('inoremenu &Test.Test2 ') + command('vnoremenu &Test.Test3 yA0xyz') + command('inoremenu &Test.Test4 *') + command('inoremenu &Test.Test5 +') + local m = funcs.menu_get("","a"); + local expected = { + { + shortcut = "T", + hidden = 0, + submenus = { + { + priority = 500, + mappings = { + n = { + sid = 1, + noremap = 1, + enabled = 1, + rhs = "inormal", + silent = 0 + } + }, + name = "Test", + hidden = 0 + }, + { + priority = 500, + mappings = { + i = { + sid = 1, + noremap = 1, + enabled = 1, + rhs = "", + silent = 0 + } + }, + name = "Test2", + hidden = 0 + }, + { + priority = 500, + mappings = { + s = { + sid = 1, + noremap = 1, + enabled = 1, + rhs = "yA0xyz", + silent = 0 + }, + v = { + sid = 1, + noremap = 1, + enabled = 1, + rhs = "yA0xyz", + silent = 0 + } + }, + name = "Test3", + hidden = 0 + }, + { + priority = 500, + mappings = { + i = { + sid = 1, + noremap = 1, + enabled = 1, + rhs = "*", + silent = 0 + } + }, + name = "Test4", + hidden = 0 + }, + { + priority = 500, + mappings = { + i = { + sid = 1, + noremap = 1, + enabled = 1, + rhs = "+", + silent = 0 + } + }, + name = "Test5", + hidden = 0 + } + }, + priority = 500, + name = "Test" + } + } + + eq(m, expected) + end) end) From 41f624a85b95d54ce038637cbe53530ad1b99f53 Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Mon, 2 Oct 2017 14:55:19 +0200 Subject: [PATCH 3/4] Deal with NOP, add actext to output --- src/nvim/menu.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/nvim/menu.c b/src/nvim/menu.c index 69700e34fd..88d968704b 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -682,6 +682,10 @@ static dict_T *menu_get_recursive(const vimmenu_T *menu, int modes) tv_dict_add_str(dict, S_LEN("shortcut"), buf); } + if (menu->actext) { + tv_dict_add_str(dict, S_LEN("actext"), (char *)menu->actext); + } + if (menu->modes & MENU_TIP_MODE && menu->strings[MENU_INDEX_TIP]) { tv_dict_add_str(dict, S_LEN("tooltip"), (char *)menu->strings[MENU_INDEX_TIP]); @@ -695,13 +699,9 @@ static dict_T *menu_get_recursive(const vimmenu_T *menu, int modes) for (int bit = 0; bit < MENU_MODES; bit++) { if ((menu->modes & modes & (1 << bit)) != 0) { dict_T *impl = tv_dict_alloc(); - if (*menu->strings[bit] == NUL) { - tv_dict_add_str(impl, S_LEN("rhs"), (char *)""); - } else { - tv_dict_add_allocated_str(impl, S_LEN("rhs"), - str2special_save((char *)menu->strings[bit], - false, false)); - } + tv_dict_add_allocated_str(impl, S_LEN("rhs"), + str2special_save((char *)menu->strings[bit], + false, false)); tv_dict_add_nr(impl, S_LEN("silent"), menu->silent[bit]); tv_dict_add_nr(impl, S_LEN("enabled"), (menu->enabled & (1 << bit)) ? 1 : 0); From 1f6138702c5413bd870fb14e2237c5b42f061cd2 Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Mon, 2 Oct 2017 14:55:25 +0200 Subject: [PATCH 4/4] More tests --- test/functional/ex_cmds/menu_spec.lua | 318 +++++++++++++++++++------- 1 file changed, 234 insertions(+), 84 deletions(-) diff --git a/test/functional/ex_cmds/menu_spec.lua b/test/functional/ex_cmds/menu_spec.lua index 5238752af4..2bc73d811b 100644 --- a/test/functional/ex_cmds/menu_spec.lua +++ b/test/functional/ex_cmds/menu_spec.lua @@ -379,6 +379,13 @@ describe('menu_get', function() } eq(expected, m) end) +end) + +describe('menu_get', function() + + before_each(function() + clear() + end) it('prettyprints special chars', function() clear() @@ -387,94 +394,237 @@ describe('menu_get', function() command('vnoremenu &Test.Test3 yA0xyz') command('inoremenu &Test.Test4 *') command('inoremenu &Test.Test5 +') - local m = funcs.menu_get("","a"); + command('nnoremenu &Test.Test6 ') + command('nnoremenu &Test.Test7 ') + command('nnoremenu &Test.Test8 ') + command('nnoremenu &Test.Test9 ""') + + local m = funcs.menu_get(""); local expected = { - { - shortcut = "T", - hidden = 0, - submenus = { - { - priority = 500, - mappings = { - n = { - sid = 1, - noremap = 1, - enabled = 1, - rhs = "inormal", - silent = 0 - } - }, - name = "Test", - hidden = 0 + { + shortcut = "T", + hidden = 0, + submenus = { + { + priority = 500, + mappings = { + n = { + sid = 1, + noremap = 1, + enabled = 1, + rhs = "inormal", + silent = 0 + } }, - { - priority = 500, - mappings = { - i = { - sid = 1, - noremap = 1, - enabled = 1, - rhs = "", - silent = 0 - } - }, - name = "Test2", - hidden = 0 - }, - { - priority = 500, - mappings = { - s = { - sid = 1, - noremap = 1, - enabled = 1, - rhs = "yA0xyz", - silent = 0 - }, - v = { - sid = 1, - noremap = 1, - enabled = 1, - rhs = "yA0xyz", - silent = 0 - } - }, - name = "Test3", - hidden = 0 - }, - { - priority = 500, - mappings = { - i = { - sid = 1, - noremap = 1, - enabled = 1, - rhs = "*", - silent = 0 - } - }, - name = "Test4", - hidden = 0 - }, - { - priority = 500, - mappings = { - i = { - sid = 1, - noremap = 1, - enabled = 1, - rhs = "+", - silent = 0 - } - }, - name = "Test5", - hidden = 0 - } + name = "Test", + hidden = 0 }, - priority = 500, - name = "Test" - } + { + priority = 500, + mappings = { + i = { + sid = 1, + noremap = 1, + enabled = 1, + rhs = "", + silent = 0 + } + }, + name = "Test2", + hidden = 0 + }, + { + priority = 500, + mappings = { + s = { + sid = 1, + noremap = 1, + enabled = 1, + rhs = "yA0xyz", + silent = 0 + }, + v = { + sid = 1, + noremap = 1, + enabled = 1, + rhs = "yA0xyz", + silent = 0 + } + }, + name = "Test3", + hidden = 0 + }, + { + priority = 500, + mappings = { + i = { + sid = 1, + noremap = 1, + enabled = 1, + rhs = "*", + silent = 0 + } + }, + name = "Test4", + hidden = 0 + }, + { + priority = 500, + mappings = { + i = { + sid = 1, + noremap = 1, + enabled = 1, + rhs = "+", + silent = 0 + } + }, + name = "Test5", + hidden = 0 + }, + { + priority = 500, + mappings = { + n = { + sid = 1, + noremap = 1, + enabled = 1, + rhs = "", + silent = 0 + } + }, + name = "Test6", + hidden = 0 + }, + { + priority = 500, + mappings = { + n = { + sid = 1, + noremap = 1, + enabled = 1, + rhs = "", + silent = 0 + } + }, + name = "Test7", + hidden = 0 + }, + { + priority = 500, + mappings = { + n = { + sid = 1, + noremap = 1, + enabled = 1, + rhs = "", + silent = 0 + } + }, + name = "Test8", + hidden = 0 + }, + { + priority = 500, + mappings = { + n = { + sid = 1, + noremap = 1, + enabled = 1, + rhs = "\"\"", + silent = 0 + } + }, + name = "Test9", + hidden = 0 + } + }, + priority = 500, + name = "Test" } + } + + eq(m, expected) + end) + + it('works with right-aligned text and spaces', function() + clear() + command('nnoremenu &TestY.TestX\\ x inormal') + command('nnoremenu &Test\\ 1.Test\\ 2 Wargl') + command('nnoremenu &Test4.Test3 i space') + + local m = funcs.menu_get(""); + local expected = { + { + shortcut = "T", + hidden = 0, + actext = "Y", + submenus = { + { + mappings = { + n = { + sid = 1, + noremap = 1, + enabled = 1, + rhs = "inormal", + silent = 0 + } + }, + hidden = 0, + actext = "X x", + priority = 500, + name = "Test" + } + }, + priority = 500, + name = "Test" + }, + { + shortcut = "T", + hidden = 0, + submenus = { + { + priority = 500, + mappings = { + n = { + sid = 1, + noremap = 1, + enabled = 1, + rhs = "Wargl", + silent = 0 + } + }, + name = "Test 2", + hidden = 0 + } + }, + priority = 500, + name = "Test 1" + }, + { + shortcut = "T", + hidden = 0, + submenus = { + { + mappings = { + n = { + sid = 1, + noremap = 1, + enabled = 1, + rhs = "i space", + silent = 0 + } + }, + hidden = 0, + actext = "3", + priority = 500, + name = "Test" + } + }, + priority = 500, + name = "Test4" + } + } eq(m, expected) end)