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 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/nvim/api/buffer.c') 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 -- cgit From 9fa7727ce047e8e2e13f9fbf60d5defe9cf45060 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 10 May 2018 23:37:56 +0200 Subject: API: nvim_get_commands(): always return keys - Always return all keys, with at least NIL value. - Require `opts` param to be {"builtin":false} - Validate `opts` param --- src/nvim/api/buffer.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'src/nvim/api/buffer.c') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index c4508a0c81..878c8aad87 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -479,12 +479,11 @@ 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. +/// Gets a list of maps describing buffer-local |user-commands|. /// -/// @param buffer Buffer handle. -/// @param opts Optional parameters, currently always +/// @param buffer Buffer handle. +/// @param opts Optional parameters. Currently only supports +/// {"builtin":false} /// @param[out] err Error details, if any. /// /// @returns Array of dictionaries describing commands. @@ -492,6 +491,25 @@ ArrayOf(Dictionary) nvim_buf_get_commands(Buffer buffer, Dictionary opts, Error *err) FUNC_API_SINCE(4) { + for (size_t i = 0; i < opts.size; i++) { + String k = opts.items[i].key; + Object v = opts.items[i].value; + if (!strequal("builtin", k.data)) { + api_set_error(err, kErrorTypeValidation, "unexpected key: %s", + k.data); + return (Array)ARRAY_DICT_INIT; + } + if (v.type != kObjectTypeBoolean || v.data.boolean != false) { + api_set_error(err, kErrorTypeValidation, + "builtin commands not supported yet"); + return (Array)ARRAY_DICT_INIT; + } + } + + if (buffer == -1) { + return commands_array(NULL); + } + buf_T *buf = find_buffer_by_handle(buffer, err); if (!buf) { return (Array)ARRAY_DICT_INIT; -- cgit From 738bffea2cbb810ad1d3a3aa5bfeb88392260a8a Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 11 May 2018 07:50:00 +0200 Subject: API: nvim_get_commands(): more attributes Support more :command attributes: -bang -bar -register --- src/nvim/api/buffer.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/nvim/api/buffer.c') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 878c8aad87..19f92f002d 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -459,14 +459,13 @@ Integer nvim_buf_get_changedtick(Buffer buffer, Error *err) return buf->b_changedtick; } -/// Gets a list of dictionaries describing buffer-local mappings. -/// The "buffer" key in the returned dictionary reflects the buffer -/// handle where the mapping is present. +/// Gets a list of buffer-local |mapping| definitions. /// /// @param mode Mode short-name ("n", "i", "v", ...) /// @param buffer Buffer handle /// @param[out] err Error details, if any -/// @returns Array of maparg()-like dictionaries describing mappings +/// @returns Array of maparg()-like dictionaries describing mappings. +/// The "buffer" key holds the associated buffer handle. ArrayOf(Dictionary) nvim_buf_get_keymap(Buffer buffer, String mode, Error *err) FUNC_API_SINCE(3) { @@ -479,7 +478,7 @@ ArrayOf(Dictionary) nvim_buf_get_keymap(Buffer buffer, String mode, Error *err) return keymap_array(mode, buf); } -/// Gets a list of maps describing buffer-local |user-commands|. +/// Gets a list of buffer-local |user-commands|. /// /// @param buffer Buffer handle. /// @param opts Optional parameters. Currently only supports -- cgit From cb6672853a0df3dbe5202621d818ef1c2da7432c Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 11 May 2018 20:59:53 +0200 Subject: API: nvim_get_commands(): builtin is irrelevant for buffer-local builtin commands are never buffer-local, so we can return empty for that case. --- src/nvim/api/buffer.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/nvim/api/buffer.c') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 19f92f002d..eda7fcd74c 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -481,8 +481,7 @@ ArrayOf(Dictionary) nvim_buf_get_keymap(Buffer buffer, String mode, Error *err) /// Gets a list of buffer-local |user-commands|. /// /// @param buffer Buffer handle. -/// @param opts Optional parameters. Currently only supports -/// {"builtin":false} +/// @param opts Optional parameters. Currently not used. /// @param[out] err Error details, if any. /// /// @returns Array of dictionaries describing commands. @@ -490,27 +489,31 @@ ArrayOf(Dictionary) nvim_buf_get_commands(Buffer buffer, Dictionary opts, Error *err) FUNC_API_SINCE(4) { + bool global = (buffer == -1); + bool builtin = false; + for (size_t i = 0; i < opts.size; i++) { String k = opts.items[i].key; Object v = opts.items[i].value; if (!strequal("builtin", k.data)) { - api_set_error(err, kErrorTypeValidation, "unexpected key: %s", - k.data); + api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data); return (Array)ARRAY_DICT_INIT; } - if (v.type != kObjectTypeBoolean || v.data.boolean != false) { - api_set_error(err, kErrorTypeValidation, - "builtin commands not supported yet"); - return (Array)ARRAY_DICT_INIT; + if (strequal("builtin", k.data)) { + builtin = v.data.boolean; } } - if (buffer == -1) { + if (global) { + if (builtin) { + api_set_error(err, kErrorTypeValidation, "builtin=true not implemented"); + return (Array)ARRAY_DICT_INIT; + } return commands_array(NULL); } buf_T *buf = find_buffer_by_handle(buffer, err); - if (!buf) { + if (builtin || !buf) { return (Array)ARRAY_DICT_INIT; } return commands_array(buf); -- cgit From 137eedb4edab1643b47282cce4ca07dd2ee42a63 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 11 May 2018 21:26:05 +0200 Subject: API: nvim_get_commands(): return Dictionary --- src/nvim/api/buffer.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/nvim/api/buffer.c') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index eda7fcd74c..fa4ad27e60 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -467,7 +467,7 @@ Integer nvim_buf_get_changedtick(Buffer buffer, Error *err) /// @returns Array of maparg()-like dictionaries describing mappings. /// The "buffer" key holds the associated buffer handle. ArrayOf(Dictionary) nvim_buf_get_keymap(Buffer buffer, String mode, Error *err) - FUNC_API_SINCE(3) + FUNC_API_SINCE(3) { buf_T *buf = find_buffer_by_handle(buffer, err); @@ -478,16 +478,15 @@ ArrayOf(Dictionary) nvim_buf_get_keymap(Buffer buffer, String mode, Error *err) return keymap_array(mode, buf); } -/// Gets a list of buffer-local |user-commands|. +/// Gets a map of buffer-local |user-commands|. /// /// @param buffer Buffer handle. /// @param opts Optional parameters. Currently not used. /// @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) +/// @returns Map of maps describing commands. +Dictionary nvim_buf_get_commands(Buffer buffer, Dictionary opts, Error *err) + FUNC_API_SINCE(4) { bool global = (buffer == -1); bool builtin = false; @@ -497,7 +496,7 @@ ArrayOf(Dictionary) nvim_buf_get_commands(Buffer buffer, Dictionary opts, Object v = opts.items[i].value; if (!strequal("builtin", k.data)) { api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data); - return (Array)ARRAY_DICT_INIT; + return (Dictionary)ARRAY_DICT_INIT; } if (strequal("builtin", k.data)) { builtin = v.data.boolean; @@ -507,14 +506,14 @@ ArrayOf(Dictionary) nvim_buf_get_commands(Buffer buffer, Dictionary opts, if (global) { if (builtin) { api_set_error(err, kErrorTypeValidation, "builtin=true not implemented"); - return (Array)ARRAY_DICT_INIT; + return (Dictionary)ARRAY_DICT_INIT; } return commands_array(NULL); } buf_T *buf = find_buffer_by_handle(buffer, err); if (builtin || !buf) { - return (Array)ARRAY_DICT_INIT; + return (Dictionary)ARRAY_DICT_INIT; } return commands_array(buf); } -- cgit