From 25b630484023716977c3fe2790c13b41f9db9f30 Mon Sep 17 00:00:00 2001 From: Nimit Bhardwaj Date: Sat, 24 Feb 2018 15:44:51 +0530 Subject: API: nvim_get_commands() --- src/nvim/api/buffer.c | 21 +++++++++++++++++++++ src/nvim/api/private/helpers.c | 4 ++-- src/nvim/api/vim.c | 13 +++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 023f434f9d..c4508a0c81 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -24,6 +24,7 @@ #include "nvim/syntax.h" #include "nvim/window.h" #include "nvim/undo.h" +#include "nvim/ex_docmd.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "api/buffer.c.generated.h" @@ -478,6 +479,26 @@ ArrayOf(Dictionary) nvim_buf_get_keymap(Buffer buffer, String mode, Error *err) return keymap_array(mode, buf); } +/// Gets a list of dictionaries describing buffer-local commands. +/// The "buffer" key in the returned dictionary reflects the buffer +/// handle where the command is present. +/// +/// @param buffer Buffer handle. +/// @param opts Optional parameters, currently always +/// @param[out] err Error details, if any. +/// +/// @returns Array of dictionaries describing commands. +ArrayOf(Dictionary) nvim_buf_get_commands(Buffer buffer, Dictionary opts, + Error *err) + FUNC_API_SINCE(4) +{ + buf_T *buf = find_buffer_by_handle(buffer, err); + if (!buf) { + return (Array)ARRAY_DICT_INIT; + } + return commands_array(buf); +} + /// Sets a buffer-scoped (b:) variable /// /// @param buffer Buffer handle diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index b922036893..03f1a882d3 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -701,7 +701,7 @@ String cchar_to_string(char c) String cstr_to_string(const char *str) { if (str == NULL) { - return (String) STRING_INIT; + return (String) STRING_INIT; } size_t len = strlen(str); @@ -1149,7 +1149,7 @@ void api_set_error(Error *err, ErrorType errType, const char *format, ...) /// /// @param mode The abbreviation for the mode /// @param buf The buffer to get the mapping array. NULL for global -/// @returns An array of maparg() like dictionaries describing mappings +/// @returns Array of maparg()-like dictionaries describing mappings ArrayOf(Dictionary) keymap_array(String mode, buf_T *buf) { Array mappings = ARRAY_DICT_INIT; diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index df4912a51e..38e64fd6ed 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -959,6 +959,19 @@ ArrayOf(Dictionary) nvim_get_keymap(String mode) return keymap_array(mode, NULL); } +/// Gets a list of dictionaries describing global(non-buffer) commands. +/// +/// @param opts Holds the API Metadata describing what type of commands +/// are needed. +/// @param[out] err Error details, if any. +/// +/// @returns Array of dictionaries describing commands. +ArrayOf(Dictionary) nvim_get_commands(Dictionary opts, Error *err) + FUNC_API_SINCE(4) +{ + return commands_array(NULL); +} + /// Returns a 2-tuple (Array), where item 0 is the current channel id and item /// 1 is the |api-metadata| map (Dictionary). /// -- cgit