menu_get(): doc

This commit is contained in:
Justin M. Keyes 2017-07-28 02:31:03 +02:00
parent dc685387a3
commit 3b45f676c0
5 changed files with 48 additions and 47 deletions

View File

@ -5509,18 +5509,23 @@ max({expr}) Return the maximum value of all items in {expr}.
an error. An empty |List| or |Dictionary| results in zero. an error. An empty |List| or |Dictionary| results in zero.
menu_get({path}, {modes}) *menu_get()* menu_get({path}, {modes}) *menu_get()*
Returns a |Dictionary| with all the submenu of {path} (set to Returns a |List| of |Dictionaries| describing |menus| (defined
an empty string to match all menus). Only the commands matching {modes} are by |:menu|, |:amenu|, etc.).
returned ('a' for all, 'i' for insert see |creating-menus|). {path} limits the result to a subtree of the menu hierarchy
(empty string matches all menus). E.g. to get items in the
"File" menu subtree: >
:echo menu_get('File','')
<
{modes} is a string of zero or more modes (see |maparg()| or
|creating-menus| for the list of modes). "a" means "all".
For instance, executing: For example: >
>
nnoremenu &Test.Test inormal nnoremenu &Test.Test inormal
inoremenu Test.Test insert inoremenu Test.Test insert
vnoremenu Test.Test x vnoremenu Test.Test x
echo menu_get("") echo menu_get("")
< <
should produce an output with a similar structure: returns something like this:
> >
[ { [ {
"hidden": 0, "hidden": 0,

View File

@ -127,6 +127,7 @@ Functions:
|dictwatcheradd()| notifies a callback whenever a |Dict| is modified |dictwatcheradd()| notifies a callback whenever a |Dict| is modified
|dictwatcherdel()| |dictwatcherdel()|
|execute()| works with |:redir| |execute()| works with |:redir|
|menu_get()|
|msgpackdump()|, |msgpackparse()| provide msgpack de/serialization |msgpackdump()|, |msgpackparse()| provide msgpack de/serialization
Events: Events:

View File

@ -936,8 +936,7 @@ int utf_char2len(int c)
/// ///
/// @param c character to convert to \p buf /// @param c character to convert to \p buf
/// @param[out] buf UTF-8 string generated from \p c, does not add \0 /// @param[out] buf UTF-8 string generated from \p c, does not add \0
/// @return the number of bytes (between 1 and 6) /// @return Number of bytes (1-6). Does not include composing characters.
/// @note This does not include composing characters.
int utf_char2bytes(int c, char_u *const buf) int utf_char2bytes(int c, char_u *const buf)
{ {
if (c < 0x80) { /* 7 bits */ if (c < 0x80) { /* 7 bits */

View File

@ -91,11 +91,9 @@ ex_menu(exarg_T *eap)
// Locate an optional "icon=filename" argument // Locate an optional "icon=filename" argument
// Kept just the command parsing from vim for compativility but no further // TODO(nvim): Currently this is only parsed. Should expose it to UIs.
// processing is done
if (STRNCMP(arg, "icon=", 5) == 0) { if (STRNCMP(arg, "icon=", 5) == 0) {
arg += 5; arg += 5;
// icon = arg;
while (*arg != NUL && *arg != ' ') { while (*arg != NUL && *arg != ' ') {
if (*arg == '\\') if (*arg == '\\')
STRMOVE(arg, arg + 1); STRMOVE(arg, arg + 1);
@ -1138,14 +1136,14 @@ static bool menu_namecmp(const char_u *const name, const char_u *const mname)
} }
/// converts a string into a combination of \ref MENU_MODES /// Returns the \ref MENU_MODES specified by menu command `cmd`.
/// (eg :menu! returns MENU_CMDLINE_MODE | MENU_INSERT_MODE) /// (eg :menu! returns MENU_CMDLINE_MODE | MENU_INSERT_MODE)
/// ///
/// @param[in] cmd a string like 'n' (normal) or 'a' (all) /// @param[in] cmd string like "nmenu", "vmenu", etc.
/// @param[in] forceit Was there a "!" after the command? /// @param[in] forceit bang (!) was given after the command
/// @param[out] If "noremap" is not NULL, then the flag it points to is set /// @param[out] noremap If not NULL, the flag it points to is set according
/// according to whether the command is a "nore" command. /// to whether the command is a "nore" command.
/// @param[out] unmenu is not NULL, then the flag it points to is set according /// @param[out] unmenu If not NULL, the flag it points to is set according
/// to whether the command is an "unmenu" command. /// to whether the command is an "unmenu" command.
int int
get_menu_cmd_modes( get_menu_cmd_modes(

View File

@ -78,12 +78,10 @@ describe('menu_get', function()
command('cnoremenu Edit.Paste <C-R>"') command('cnoremenu Edit.Paste <C-R>"')
end) end)
it('no path, all modes', function() it("path='', modes='a'", function()
local m = funcs.menu_get("","a"); local m = funcs.menu_get("","a");
-- You can use the following to print the expected table -- HINT: To print the expected table and regenerate the tests:
-- and regenerate the tests: -- print(require('pl.pretty').dump(m))
-- local pretty = require('pl.pretty');
-- print(pretty.dump(m))
local expected = { local expected = {
{ {
shortcut = "T", shortcut = "T",