diff options
| -rw-r--r-- | vis-cmds.c | 7 | ||||
| -rw-r--r-- | vis-lua.c | 8 | ||||
| -rw-r--r-- | vis.h | 3 |
3 files changed, 9 insertions, 9 deletions
@@ -695,11 +695,12 @@ static bool print_cmd(const char *key, void *value, void *data) { static bool print_cmd_name(const char *key, void *value, void *data) { CommandDef *cmd = value; - return buffer_appendf(data, "%s\n", cmd->name); + bool result = buffer_append(data, cmd->name, strlen(cmd->name)); + return result && buffer_append(data, "\n", 1); } -void vis_print_cmds(Vis *vis, Buffer *buf) { - map_iterate(vis->cmds, print_cmd_name, buf); +void vis_print_cmds(Vis *vis, Buffer *buf, const char *prefix) { + map_iterate(map_prefix(vis->cmds, prefix), print_cmd_name, buf); } static bool print_option(const char *key, void *value, void *txt) { @@ -1161,13 +1161,11 @@ static int complete_command(lua_State *L) { Vis *vis = obj_ref_check(L, 1, "vis"); const char *prefix = luaL_checkstring(L, 2); char *out = NULL, *err = NULL; - char cmd[32]; - int max_prefix_len = sizeof(cmd) - sizeof("grep '^' | vis-menu -b"); // including NUL - snprintf(cmd, sizeof(cmd), "grep '^%.*s' | vis-menu -b", max_prefix_len, prefix); Buffer buf = {0}; - vis_print_cmds(vis, &buf); - int status = vis_pipe_buf_collect(vis, buffer_content0(&buf), (const char*[]){cmd, NULL}, &out, &err, false); + vis_print_cmds(vis, &buf, prefix); + int status = vis_pipe_buf_collect(vis, buffer_content0(&buf), (const char*[]){"vis-menu", "-b", 0}, + &out, &err, false); lua_pushinteger(L, status); if (out) lua_pushstring(L, out); @@ -1234,8 +1234,9 @@ bool vis_prompt_cmd(Vis *vis, const char *cmd); * Write newline separated list of available commands to ``buf`` * @param vis The editor instance. * @param buf The buffer to write to. + * @param prefix Prefix to filter command list by. */ -void vis_print_cmds(Vis*, Buffer *buf); +void vis_print_cmds(Vis*, Buffer *buf, const char *prefix); /** * Pipe a given file range to an external process. |
