Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RDY] menu_get() / export menus #6322

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions runtime/doc/eval.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5506,6 +5506,46 @@ max({expr}) Return the maximum value of all items in {expr}.
items in {expr} cannot be used as a Number this results in
an error. An empty |List| or |Dictionary| results in zero.

menu_get({path}, {modes}) *menu_get()*
Returns a |Dictionary| with all the submenu of {path} (set to
an empty string to match all menus). Only the commands matching {modes} are
returned ('a' for all, 'i' for insert see |creating-menus|).

For instance, executing:
>
nnoremenu &Test.Test inormal
inoremenu Test.Test insert
vnoremenu Test.Test x
echo menu_get("")
<
should produce an output with a similar structure:
>
[ {
"hidden": 0,
"name": "Test",
"priority": 500,
"shortcut": 84,
"submenus": [ {
"hidden": 0,
"mappings": {
i": {
"enabled": 1,
"noremap": 1,
"rhs": "insert",
"sid": 1,
"silent": 0
},
n": { ... },
s": { ... },
v": { ... }
},
"name": "Test",
"priority": 500,
"shortcut": 0
} ]
} ]
<

*min()*
min({expr}) Return the minimum value of all items in {expr}.
{expr} can be a list or a dictionary. For a dictionary,
Expand Down
14 changes: 14 additions & 0 deletions src/nvim/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/menu.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
#include "nvim/keymap.h"
Expand Down Expand Up @@ -8173,6 +8174,19 @@ static void f_expand(typval_T *argvars, typval_T *rettv, FunPtr fptr)
}
}


/// "menu_get(path [, modes])" function
static void f_menu_get(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
tv_list_alloc_ret(rettv);
int modes = MENU_ALL_MODES;
if (argvars[1].v_type == VAR_STRING) {
const char_u *const strmodes = (char_u *)tv_get_string(&argvars[1]);
modes = get_menu_cmd_modes(strmodes, false, NULL, NULL);
}
menu_get((char_u *)tv_get_string(&argvars[0]), modes, rettv->vval.v_list);
}

/*
* "extend(list, list [, idx])" function
* "extend(dict, dict [, action])" function
Expand Down
7 changes: 4 additions & 3 deletions src/nvim/eval.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
--
-- Keys:
--
-- args Number of arguments, list with maximum and minimum number of arguments
-- or list with a minimum number of arguments only. Defaults to zero
-- args Number of arguments, list with maximum and minimum number of arguments
-- or list with a minimum number of arguments only. Defaults to zero
-- arguments.
-- func Name of the C function which implements the VimL function. Defaults to
-- func Name of the C function which implements the VimL function. Defaults to
-- `f_{funcname}`.

local varargs = function(nr)
Expand Down Expand Up @@ -208,6 +208,7 @@ return {
matchstr={args={2, 4}},
matchstrpos={args={2,4}},
max={args=1},
menu_get={args={1, 2}},
min={args=1},
mkdir={args={1, 3}},
mode={args={0, 1}},
Expand Down
2 changes: 1 addition & 1 deletion src/nvim/ex_cmds.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bit = require 'bit'
local bit = require 'bit'

-- Description of the values below is contained in ex_cmds_defs.h file.
local RANGE = 0x001
Expand Down
15 changes: 9 additions & 6 deletions src/nvim/getchar.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
#include "nvim/buffer_defs.h"
#include "nvim/ex_cmds_defs.h"

/* Values for "noremap" argument of ins_typebuf(). Also used for
* map->m_noremap and menu->noremap[]. */
#define REMAP_YES 0 /* allow remapping */
#define REMAP_NONE -1 /* no remapping */
#define REMAP_SCRIPT -2 /* remap script-local mappings only */
#define REMAP_SKIP -3 /* no remapping for first char */
/// Values for "noremap" argument of ins_typebuf(). Also used for
/// map->m_noremap and menu->noremap[].
/// @addtogroup REMAP_VALUES
/// @{
#define REMAP_YES 0 ///< allow remapping
#define REMAP_NONE -1 ///< no remapping
#define REMAP_SCRIPT -2 ///< remap script-local mappings only
#define REMAP_SKIP -3 ///< no remapping for first char
/// @}

#define KEYLEN_PART_KEY -1 /* keylen value for incomplete key-code */
#define KEYLEN_PART_MAP -2 /* keylen value for incomplete mapping */
Expand Down
13 changes: 7 additions & 6 deletions src/nvim/mbyte.c
Original file line number Diff line number Diff line change
Expand Up @@ -932,12 +932,13 @@ int utf_char2len(int c)
return 6;
}

/*
* Convert Unicode character "c" to UTF-8 string in "buf[]".
* Returns the number of bytes.
* This does not include composing characters.
*/
int utf_char2bytes(int c, char_u *buf)
/// Convert Unicode character to UTF-8 string
///
/// @param c character to convert to \p buf
/// @param[out] buf UTF-8 string generated from \p c, does not add \0
/// @return the number of bytes (between 1 and 6)
/// @note This does not include composing characters.
int utf_char2bytes(int c, char_u *const buf)
{
if (c < 0x80) { /* 7 bits */
buf[0] = c;
Expand Down
Loading