From ed3115bd26047c9b125798d9cb56d09b155a243b Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 11 Jul 2016 20:42:27 +0300 Subject: executor: Make sure it works with API values --- src/nvim/api/vim.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 413456c615..24959e9a59 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -197,7 +197,21 @@ Object nvim_eval(String expr, Error *err) return rv; } -/// Calls a VimL function with the given arguments. +/// Returns object given as argument +/// +/// This API function is used for testing. One should not rely on its presence +/// in plugins. +/// +/// @param[in] obj Object to return. +/// +/// @return its argument. +Object _vim_id(Object obj) +{ + return obj; +} + +/// Calls a VimL function with the given arguments +/// /// On VimL error: Returns a generic error; v:errmsg is not updated. /// /// @param fname Function to call -- cgit From 425d348f0f9f680a44af31fc3cecd20a07374bb5 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 16 Jul 2016 00:34:24 +0300 Subject: executor/converter: Make nlua_pop_Object not recursive --- src/nvim/api/vim.c | 54 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 13 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 24959e9a59..5d862628cb 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -197,19 +197,6 @@ Object nvim_eval(String expr, Error *err) return rv; } -/// Returns object given as argument -/// -/// This API function is used for testing. One should not rely on its presence -/// in plugins. -/// -/// @param[in] obj Object to return. -/// -/// @return its argument. -Object _vim_id(Object obj) -{ - return obj; -} - /// Calls a VimL function with the given arguments /// /// On VimL error: Returns a generic error; v:errmsg is not updated. @@ -843,3 +830,44 @@ static void write_msg(String message, bool to_err) --no_wait_return; msg_end(); } + +// Functions used for testing purposes + +/// Returns object given as argument +/// +/// This API function is used for testing. One should not rely on its presence +/// in plugins. +/// +/// @param[in] obj Object to return. +/// +/// @return its argument. +Object _vim_id(Object obj) +{ + return obj; +} + +/// Returns array given as argument +/// +/// This API function is used for testing. One should not rely on its presence +/// in plugins. +/// +/// @param[in] arr Array to return. +/// +/// @return its argument. +Array _vim_id_array(Array arr) +{ + return arr; +} + +/// Returns dictionary given as argument +/// +/// This API function is used for testing. One should not rely on its presence +/// in plugins. +/// +/// @param[in] dct Dictionary to return. +/// +/// @return its argument. +Dictionary _vim_id_dictionary(Dictionary dct) +{ + return dct; +} -- cgit From ba2f615cd40d5d809d1a141c7b098e3bd22ff7bb Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 16 Jul 2016 02:26:04 +0300 Subject: functests: Test for error conditions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit During testing found the following bugs: 1. msgpack-gen.lua script is completely unprepared for Float values either in return type or in arguments. Specifically: 1. At the time of writing relevant code FLOAT_OBJ did not exist as well as FLOATING_OBJ, but it would be used by msgpack-gen.lua should return type be Float. I added FLOATING_OBJ macros later because did not know that msgpack-gen.lua uses these _OBJ macros, otherwise it would be FLOAT_OBJ. 2. msgpack-gen.lua should use .data.floating in place of .data.float. But it did not expect that .data subattribute may have name different from lowercased type name. 2. vim_replace_termcodes returned its argument as-is if it receives an empty string (as well as _vim_id*() functions did). But if something in returned argument lives in an allocated memory such action will cause double free: once when freeing arguments, then when freeing return value. It did not cause problems yet because msgpack bindings return empty string as {NULL, 0} and nothing was actually allocated. 3. New code in msgpack-gen.lua popped arguments in reversed order, making lua bindings’ signatures be different from API ones. --- src/nvim/api/vim.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 5d862628cb..3fd1f57ace 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -139,7 +139,7 @@ String nvim_replace_termcodes(String str, Boolean from_part, Boolean do_lt, { if (str.size == 0) { // Empty string - return str; + return (String) { .data = NULL, .size = 0 }; } char *ptr = NULL; @@ -843,7 +843,7 @@ static void write_msg(String message, bool to_err) /// @return its argument. Object _vim_id(Object obj) { - return obj; + return copy_object(obj); } /// Returns array given as argument @@ -856,7 +856,7 @@ Object _vim_id(Object obj) /// @return its argument. Array _vim_id_array(Array arr) { - return arr; + return copy_object(ARRAY_OBJ(arr)).data.array; } /// Returns dictionary given as argument @@ -869,5 +869,18 @@ Array _vim_id_array(Array arr) /// @return its argument. Dictionary _vim_id_dictionary(Dictionary dct) { - return dct; + return copy_object(DICTIONARY_OBJ(dct)).data.dictionary; +} + +/// Returns floating-point value given as argument +/// +/// This API function is used for testing. One should not rely on its presence +/// in plugins. +/// +/// @param[in] flt Value to return. +/// +/// @return its argument. +Float _vim_id_float(Float flt) +{ + return flt; } -- cgit From 7b6b629e1a1e3c9f49f75f3bf2c53bb76f77e209 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 8 Apr 2017 20:30:26 +0300 Subject: api: Add FUNC_API_SINCE(1) to new functions --- src/nvim/api/vim.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 511c87f408..05317b8d69 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -844,6 +844,7 @@ static void write_msg(String message, bool to_err) /// /// @return its argument. Object _vim_id(Object obj) + FUNC_API_SINCE(1) { return copy_object(obj); } @@ -857,6 +858,7 @@ Object _vim_id(Object obj) /// /// @return its argument. Array _vim_id_array(Array arr) + FUNC_API_SINCE(1) { return copy_object(ARRAY_OBJ(arr)).data.array; } @@ -870,6 +872,7 @@ Array _vim_id_array(Array arr) /// /// @return its argument. Dictionary _vim_id_dictionary(Dictionary dct) + FUNC_API_SINCE(1) { return copy_object(DICTIONARY_OBJ(dct)).data.dictionary; } @@ -883,6 +886,7 @@ Dictionary _vim_id_dictionary(Dictionary dct) /// /// @return its argument. Float _vim_id_float(Float flt) + FUNC_API_SINCE(1) { return flt; } -- cgit From a40a969e9a4776f1e274dcf0e59c8f1ec1770ca0 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 8 Apr 2017 20:33:48 +0300 Subject: api: Rename _vim_id functions to nvim__id --- src/nvim/api/vim.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 05317b8d69..9ee3827040 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -843,7 +843,7 @@ static void write_msg(String message, bool to_err) /// @param[in] obj Object to return. /// /// @return its argument. -Object _vim_id(Object obj) +Object nvim__id(Object obj) FUNC_API_SINCE(1) { return copy_object(obj); @@ -857,7 +857,7 @@ Object _vim_id(Object obj) /// @param[in] arr Array to return. /// /// @return its argument. -Array _vim_id_array(Array arr) +Array nvim__id_array(Array arr) FUNC_API_SINCE(1) { return copy_object(ARRAY_OBJ(arr)).data.array; @@ -871,7 +871,7 @@ Array _vim_id_array(Array arr) /// @param[in] dct Dictionary to return. /// /// @return its argument. -Dictionary _vim_id_dictionary(Dictionary dct) +Dictionary nvim__id_dictionary(Dictionary dct) FUNC_API_SINCE(1) { return copy_object(DICTIONARY_OBJ(dct)).data.dictionary; @@ -885,7 +885,7 @@ Dictionary _vim_id_dictionary(Dictionary dct) /// @param[in] flt Value to return. /// /// @return its argument. -Float _vim_id_float(Float flt) +Float nvim__id_float(Float flt) FUNC_API_SINCE(1) { return flt; -- cgit From f3093bc508631930d41e9603b43687f4e51af2b3 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 10 Apr 2017 23:10:01 +0300 Subject: api: Bump nvim__*id functions since value --- src/nvim/api/vim.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 9ee3827040..0056ea1725 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -844,7 +844,7 @@ static void write_msg(String message, bool to_err) /// /// @return its argument. Object nvim__id(Object obj) - FUNC_API_SINCE(1) + FUNC_API_SINCE(2) { return copy_object(obj); } @@ -858,7 +858,7 @@ Object nvim__id(Object obj) /// /// @return its argument. Array nvim__id_array(Array arr) - FUNC_API_SINCE(1) + FUNC_API_SINCE(2) { return copy_object(ARRAY_OBJ(arr)).data.array; } @@ -872,7 +872,7 @@ Array nvim__id_array(Array arr) /// /// @return its argument. Dictionary nvim__id_dictionary(Dictionary dct) - FUNC_API_SINCE(1) + FUNC_API_SINCE(2) { return copy_object(DICTIONARY_OBJ(dct)).data.dictionary; } @@ -886,7 +886,7 @@ Dictionary nvim__id_dictionary(Dictionary dct) /// /// @return its argument. Float nvim__id_float(Float flt) - FUNC_API_SINCE(1) + FUNC_API_SINCE(2) { return flt; } -- cgit From 1bd39fb8d009f5ff62023d0f2fe86bbcdaeb3abc Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 11 Apr 2017 23:59:05 +0300 Subject: api: Remove FUNC_API_SINCE for nvim__ functions --- src/nvim/api/vim.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 0056ea1725..1d44e779c7 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -844,7 +844,6 @@ static void write_msg(String message, bool to_err) /// /// @return its argument. Object nvim__id(Object obj) - FUNC_API_SINCE(2) { return copy_object(obj); } @@ -858,7 +857,6 @@ Object nvim__id(Object obj) /// /// @return its argument. Array nvim__id_array(Array arr) - FUNC_API_SINCE(2) { return copy_object(ARRAY_OBJ(arr)).data.array; } @@ -872,7 +870,6 @@ Array nvim__id_array(Array arr) /// /// @return its argument. Dictionary nvim__id_dictionary(Dictionary dct) - FUNC_API_SINCE(2) { return copy_object(DICTIONARY_OBJ(dct)).data.dictionary; } @@ -886,7 +883,6 @@ Dictionary nvim__id_dictionary(Dictionary dct) /// /// @return its argument. Float nvim__id_float(Float flt) - FUNC_API_SINCE(2) { return flt; } -- cgit From 3ea10077534cb1dcb1597ffcf85e601fa0c0e27b Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 13 Mar 2017 15:02:37 +0100 Subject: api: nvim_get_mode() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Asynchronous API functions are served immediately, which means pending input could change the state of Nvim shortly after an async API function result is returned. nvim_get_mode() is different: - If RPCs are known to be blocked, it responds immediately (without flushing the input/event queue) - else it is handled just-in-time before waiting for input, after pending input was processed. This makes the result more reliable (but not perfect). Internally this is handled as a special case, but _semantically_ nothing has changed: API users never know when input flushes, so this internal special-case doesn't violate that. As far as API users are concerned, nvim_get_mode() is just another asynchronous API function. In all cases nvim_get_mode() never blocks for more than the time it takes to flush the input/event queue (~µs). Note: This doesn't address #6166; nvim_get_mode() will provoke #6166 if e.g. `d` is operator-pending. Closes #6159 --- src/nvim/api/vim.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index da00fbc6e3..7c57a5b456 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -11,6 +11,7 @@ #include "nvim/api/vim.h" #include "nvim/ascii.h" +#include "nvim/log.h" #include "nvim/api/private/helpers.h" #include "nvim/api/private/defs.h" #include "nvim/api/buffer.h" @@ -27,6 +28,7 @@ #include "nvim/eval.h" #include "nvim/eval/typval.h" #include "nvim/option.h" +#include "nvim/state.h" #include "nvim/syntax.h" #include "nvim/getchar.h" #include "nvim/os/input.h" @@ -701,6 +703,25 @@ Dictionary nvim_get_color_map(void) } +/// Gets the current mode. +/// mode: Mode string. |mode()| +/// blocking: true if Nvim is waiting for input. +/// +/// @returns Dictionary { "mode": String, "blocking": Boolean } +Dictionary nvim_get_mode(void) + FUNC_API_SINCE(2) FUNC_API_ASYNC +{ + Dictionary rv = ARRAY_DICT_INIT; + char *modestr = get_mode(); + bool blocked = input_blocking(); + ILOG("blocked=%d", blocked); + + PUT(rv, "mode", STRING_OBJ(cstr_as_string(modestr))); + PUT(rv, "blocking", BOOLEAN_OBJ(blocked)); + + return rv; +} + Array nvim_get_api_info(uint64_t channel_id) FUNC_API_SINCE(1) FUNC_API_ASYNC FUNC_API_NOEVAL { -- cgit From acfd2a2a29ae852ecc965ca888eb5049400bf39d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 14 Mar 2017 00:44:03 +0100 Subject: input.c: Process only safe events before blocking. Introduce multiqueue_process_priority() to process only events at or above a certain priority. --- src/nvim/api/vim.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 7c57a5b456..a00afc24fa 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -714,7 +714,6 @@ Dictionary nvim_get_mode(void) Dictionary rv = ARRAY_DICT_INIT; char *modestr = get_mode(); bool blocked = input_blocking(); - ILOG("blocked=%d", blocked); PUT(rv, "mode", STRING_OBJ(cstr_as_string(modestr))); PUT(rv, "blocking", BOOLEAN_OBJ(blocked)); -- cgit From f17a8185191b778960953508a5bf9b5f95b0560c Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 27 Apr 2017 13:54:54 +0200 Subject: api/nvim_get_mode: Use child-queue instead of "priority". --- src/nvim/api/vim.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index a00afc24fa..11f15b5ad1 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -11,7 +11,6 @@ #include "nvim/api/vim.h" #include "nvim/ascii.h" -#include "nvim/log.h" #include "nvim/api/private/helpers.h" #include "nvim/api/private/defs.h" #include "nvim/api/buffer.h" -- cgit From 2d5920ae1ada751811e04bcc8d3a8fe4f890617a Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Wed, 10 May 2017 10:29:43 +0200 Subject: api: always use prefix FUNC_API, also change NOEVAL to REMOTE_ONLY --- src/nvim/api/vim.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 12e8194c15..d0bb840b8d 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -659,7 +659,7 @@ void nvim_set_current_tabpage(Tabpage tabpage, Error *err) /// @param channel_id Channel id (passed automatically by the dispatcher) /// @param event Event type string void nvim_subscribe(uint64_t channel_id, String event) - FUNC_API_SINCE(1) FUNC_API_NOEVAL + FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY { size_t length = (event.size < METHOD_MAXLEN ? event.size : METHOD_MAXLEN); char e[METHOD_MAXLEN + 1]; @@ -673,7 +673,7 @@ void nvim_subscribe(uint64_t channel_id, String event) /// @param channel_id Channel id (passed automatically by the dispatcher) /// @param event Event type string void nvim_unsubscribe(uint64_t channel_id, String event) - FUNC_API_SINCE(1) FUNC_API_NOEVAL + FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY { size_t length = (event.size < METHOD_MAXLEN ? event.size : @@ -722,7 +722,7 @@ Dictionary nvim_get_mode(void) } Array nvim_get_api_info(uint64_t channel_id) - FUNC_API_SINCE(1) FUNC_API_ASYNC FUNC_API_NOEVAL + FUNC_API_SINCE(1) FUNC_API_ASYNC FUNC_API_REMOTE_ONLY { Array rv = ARRAY_DICT_INIT; @@ -755,7 +755,7 @@ Array nvim_get_api_info(uint64_t channel_id) /// which resulted in an error, the error type and the error message. If an /// error ocurred, the values from all preceding calls will still be returned. Array nvim_call_atomic(uint64_t channel_id, Array calls, Error *err) - FUNC_API_SINCE(1) FUNC_API_NOEVAL + FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY { Array rv = ARRAY_DICT_INIT; Array results = ARRAY_DICT_INIT; -- cgit From f424189093ab23fb727a996d317ff19d4d3f0b63 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Tue, 9 May 2017 08:55:04 +0200 Subject: api: execute lua directly from the remote api --- src/nvim/api/vim.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index d0bb840b8d..1fedaf30ef 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -15,6 +15,7 @@ #include "nvim/api/private/defs.h" #include "nvim/api/buffer.h" #include "nvim/msgpack_rpc/channel.h" +#include "nvim/lua/executor.h" #include "nvim/vim.h" #include "nvim/buffer.h" #include "nvim/file_search.h" @@ -254,6 +255,25 @@ free_vim_args: return rv; } +/// Execute lua code. Parameters might be passed, they are available inside +/// the chunk as `...`. The chunk can return a value. +/// +/// To evaluate an expression, it must be prefixed with "return ". For +/// instance, to call a lua function with arguments sent in and get its +/// return value back, use the code "return my_function(...)". +/// +/// @param code lua code to execute +/// @param args Arguments to the code +/// @param[out] err Details of an error encountered while parsing +/// or executing the lua code. +/// +/// @return Return value of lua code if present or NIL. +Object nvim_execute_lua(String code, Array args, Error *err) + FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY +{ + return executor_exec_lua_api(code, args, err); +} + /// Calculates the number of display cells occupied by `text`. /// counts as one cell. /// -- cgit From bdd73fc07ff8bcf9502f9c6a980a278b9e7b8f27 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 20 May 2017 22:20:21 +0200 Subject: api/nvim_replace_termcodes: Document keycodes behavior --- src/nvim/api/vim.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 1fedaf30ef..53e5f71fd4 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -135,7 +135,8 @@ Integer nvim_input(String keys) return (Integer)input_enqueue(keys); } -/// Replaces any terminal codes with the internal representation +/// Replaces terminal codes and key codes (, , ...) in a string with +/// the internal representation. /// /// @see replace_termcodes /// @see cpoptions -- cgit From a5a5c83608e6d4455ac40e8786fd16eaf817c608 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 23 May 2017 00:16:23 +0300 Subject: api/vim: Fix nvim_list_runtimepaths It used to 1. Always omit last component in runtimepath. 2. Always omit trailing empty item and leave uninitialized memory in place of it. --- src/nvim/api/vim.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 53e5f71fd4..de1d099c11 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -299,7 +299,7 @@ ArrayOf(String) nvim_list_runtime_paths(void) FUNC_API_SINCE(1) { Array rv = ARRAY_DICT_INIT; - uint8_t *rtp = p_rtp; + char_u *rtp = p_rtp; if (*rtp == NUL) { // No paths @@ -313,13 +313,14 @@ ArrayOf(String) nvim_list_runtime_paths(void) } rtp++; } + rv.size++; // Allocate memory for the copies - rv.items = xmalloc(sizeof(Object) * rv.size); + rv.items = xmalloc(sizeof(*rv.items) * rv.size); // Reset the position rtp = p_rtp; // Start copying - for (size_t i = 0; i < rv.size && *rtp != NUL; i++) { + for (size_t i = 0; i < rv.size; i++) { rv.items[i].type = kObjectTypeString; rv.items[i].data.string.data = xmalloc(MAXPATHL); // Copy the path from 'runtimepath' to rv.items[i] @@ -708,7 +709,7 @@ void nvim_unsubscribe(uint64_t channel_id, String event) Integer nvim_get_color_by_name(String name) FUNC_API_SINCE(1) { - return name_to_color((uint8_t *)name.data); + return name_to_color((char_u *)name.data); } Dictionary nvim_get_color_map(void) @@ -859,7 +860,7 @@ static void write_msg(String message, bool to_err) #define PUSH_CHAR(i, pos, line_buf, msg) \ if (message.data[i] == NL || pos == LINE_BUFFER_SIZE - 1) { \ line_buf[pos] = NUL; \ - msg((uint8_t *)line_buf); \ + msg((char_u *)line_buf); \ pos = 0; \ continue; \ } \ -- cgit From 45626de63f2b8057c13df0466406c43f04d6a1e6 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Thu, 25 May 2017 05:41:53 -0500 Subject: get_keymap API (#6236) * Add api function get keymap nvim_get_keymap(mode) nvim_buf_get_keymap(buffer, mode) --- src/nvim/api/vim.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 53e5f71fd4..0cffb2c87d 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -742,6 +742,17 @@ Dictionary nvim_get_mode(void) return rv; } +/// Get a list of dictionaries describing global (i.e. non-buffer) mappings +/// Note that the "buffer" key will be 0 to represent false. +/// +/// @param mode The abbreviation for the mode +/// @returns An array of maparg() like dictionaries describing mappings +ArrayOf(Dictionary) nvim_get_keymap(String mode) + FUNC_API_SINCE(3) +{ + return keymap_array(mode, NULL); +} + Array nvim_get_api_info(uint64_t channel_id) FUNC_API_SINCE(1) FUNC_API_ASYNC FUNC_API_REMOTE_ONLY { -- cgit From 3f553ac0b9b3866f1254e669eb0c1c019c789a60 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Fri, 2 Jun 2017 15:42:37 +0200 Subject: lint: fix indentation of FUNC_ATTR lines --- src/nvim/api/vim.c | 74 +++++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 0cffb2c87d..74e5167635 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -45,7 +45,7 @@ /// @param command Ex-command string /// @param[out] err Error details (including actual VimL error), if any void nvim_command(String command, Error *err) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { // Run the command try_start(); @@ -63,7 +63,7 @@ void nvim_command(String command, Error *err) /// @see feedkeys() /// @see vim_strsave_escape_csi void nvim_feedkeys(String keys, String mode, Boolean escape_csi) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { bool remap = true; bool insert = false; @@ -130,7 +130,7 @@ void nvim_feedkeys(String keys, String mode, Boolean escape_csi) /// @return Number of bytes actually written (can be fewer than /// requested if the buffer becomes full). Integer nvim_input(String keys) - FUNC_API_SINCE(1) FUNC_API_ASYNC + FUNC_API_SINCE(1) FUNC_API_ASYNC { return (Integer)input_enqueue(keys); } @@ -142,7 +142,7 @@ Integer nvim_input(String keys) /// @see cpoptions String nvim_replace_termcodes(String str, Boolean from_part, Boolean do_lt, Boolean special) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { if (str.size == 0) { // Empty string @@ -162,7 +162,7 @@ String nvim_replace_termcodes(String str, Boolean from_part, Boolean do_lt, } String nvim_command_output(String str, Error *err) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { do_cmdline_cmd("redir => v:command_output"); nvim_command(str, err); @@ -183,7 +183,7 @@ String nvim_command_output(String str, Error *err) /// @param[out] err Error details, if any /// @return Evaluation result or expanded object Object nvim_eval(String expr, Error *err) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { Object rv = OBJECT_INIT; // Evaluate the expression @@ -214,7 +214,7 @@ Object nvim_eval(String expr, Error *err) /// @param[out] err Error details, if any /// @return Result of the function call Object nvim_call_function(String fname, Array args, Error *err) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { Object rv = OBJECT_INIT; if (args.size > MAX_FUNC_ARGS) { @@ -282,7 +282,7 @@ Object nvim_execute_lua(String code, Array args, Error *err) /// @param[out] err Error details, if any /// @return Number of cells Integer nvim_strwidth(String str, Error *err) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { if (str.size > INT_MAX) { api_set_error(err, kErrorTypeValidation, "String length is too high"); @@ -296,7 +296,7 @@ Integer nvim_strwidth(String str, Error *err) /// /// @return List of paths ArrayOf(String) nvim_list_runtime_paths(void) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { Array rv = ARRAY_DICT_INIT; uint8_t *rtp = p_rtp; @@ -338,7 +338,7 @@ ArrayOf(String) nvim_list_runtime_paths(void) /// @param dir Directory path /// @param[out] err Error details, if any void nvim_set_current_dir(String dir, Error *err) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { if (dir.size >= MAXPATHL) { api_set_error(err, kErrorTypeValidation, "Directory string is too long"); @@ -367,7 +367,7 @@ void nvim_set_current_dir(String dir, Error *err) /// @param[out] err Error details, if any /// @return Current line string String nvim_get_current_line(Error *err) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { return buffer_get_line(curbuf->handle, curwin->w_cursor.lnum - 1, err); } @@ -377,7 +377,7 @@ String nvim_get_current_line(Error *err) /// @param line Line contents /// @param[out] err Error details, if any void nvim_set_current_line(String line, Error *err) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { buffer_set_line(curbuf->handle, curwin->w_cursor.lnum - 1, line, err); } @@ -386,7 +386,7 @@ void nvim_set_current_line(String line, Error *err) /// /// @param[out] err Error details, if any void nvim_del_current_line(Error *err) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { buffer_del_line(curbuf->handle, curwin->w_cursor.lnum - 1, err); } @@ -397,7 +397,7 @@ void nvim_del_current_line(Error *err) /// @param[out] err Error details, if any /// @return Variable value Object nvim_get_var(String name, Error *err) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { return dict_get_value(&globvardict, name, err); } @@ -408,7 +408,7 @@ Object nvim_get_var(String name, Error *err) /// @param value Variable value /// @param[out] err Error details, if any void nvim_set_var(String name, Object value, Error *err) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { dict_set_var(&globvardict, name, value, false, false, err); } @@ -418,7 +418,7 @@ void nvim_set_var(String name, Object value, Error *err) /// @param name Variable name /// @param[out] err Error details, if any void nvim_del_var(String name, Error *err) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { dict_set_var(&globvardict, name, NIL, true, false, err); } @@ -457,7 +457,7 @@ Object vim_del_var(String name, Error *err) /// @param[out] err Error details, if any /// @return Variable value Object nvim_get_vvar(String name, Error *err) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { return dict_get_value(&vimvardict, name, err); } @@ -468,7 +468,7 @@ Object nvim_get_vvar(String name, Error *err) /// @param[out] err Error details, if any /// @return Option value (global) Object nvim_get_option(String name, Error *err) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { return get_option_from(NULL, SREQ_GLOBAL, name, err); } @@ -479,7 +479,7 @@ Object nvim_get_option(String name, Error *err) /// @param value New option value /// @param[out] err Error details, if any void nvim_set_option(String name, Object value, Error *err) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { set_option_to(NULL, SREQ_GLOBAL, name, value, err); } @@ -488,7 +488,7 @@ void nvim_set_option(String name, Object value, Error *err) /// /// @param str Message void nvim_out_write(String str) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { write_msg(str, false); } @@ -497,7 +497,7 @@ void nvim_out_write(String str) /// /// @param str Message void nvim_err_write(String str) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { write_msg(str, true); } @@ -508,7 +508,7 @@ void nvim_err_write(String str) /// @param str Message /// @see nvim_err_write() void nvim_err_writeln(String str) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { nvim_err_write(str); nvim_err_write((String) { .data = "\n", .size = 1 }); @@ -518,7 +518,7 @@ void nvim_err_writeln(String str) /// /// @return List of buffer handles ArrayOf(Buffer) nvim_list_bufs(void) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { Array rv = ARRAY_DICT_INIT; @@ -540,7 +540,7 @@ ArrayOf(Buffer) nvim_list_bufs(void) /// /// @return Buffer handle Buffer nvim_get_current_buf(void) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { return curbuf->handle; } @@ -550,7 +550,7 @@ Buffer nvim_get_current_buf(void) /// @param id Buffer handle /// @param[out] err Error details, if any void nvim_set_current_buf(Buffer buffer, Error *err) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { buf_T *buf = find_buffer_by_handle(buffer, err); @@ -572,7 +572,7 @@ void nvim_set_current_buf(Buffer buffer, Error *err) /// /// @return List of window handles ArrayOf(Window) nvim_list_wins(void) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { Array rv = ARRAY_DICT_INIT; @@ -594,7 +594,7 @@ ArrayOf(Window) nvim_list_wins(void) /// /// @return Window handle Window nvim_get_current_win(void) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { return curwin->handle; } @@ -603,7 +603,7 @@ Window nvim_get_current_win(void) /// /// @param handle Window handle void nvim_set_current_win(Window window, Error *err) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { win_T *win = find_window_by_handle(window, err); @@ -625,7 +625,7 @@ void nvim_set_current_win(Window window, Error *err) /// /// @return List of tabpage handles ArrayOf(Tabpage) nvim_list_tabpages(void) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { Array rv = ARRAY_DICT_INIT; @@ -647,7 +647,7 @@ ArrayOf(Tabpage) nvim_list_tabpages(void) /// /// @return Tabpage handle Tabpage nvim_get_current_tabpage(void) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { return curtab->handle; } @@ -657,7 +657,7 @@ Tabpage nvim_get_current_tabpage(void) /// @param handle Tabpage handle /// @param[out] err Error details, if any void nvim_set_current_tabpage(Tabpage tabpage, Error *err) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { tabpage_T *tp = find_tab_by_handle(tabpage, err); @@ -680,7 +680,7 @@ void nvim_set_current_tabpage(Tabpage tabpage, Error *err) /// @param channel_id Channel id (passed automatically by the dispatcher) /// @param event Event type string void nvim_subscribe(uint64_t channel_id, String event) - FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY + FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY { size_t length = (event.size < METHOD_MAXLEN ? event.size : METHOD_MAXLEN); char e[METHOD_MAXLEN + 1]; @@ -694,7 +694,7 @@ void nvim_subscribe(uint64_t channel_id, String event) /// @param channel_id Channel id (passed automatically by the dispatcher) /// @param event Event type string void nvim_unsubscribe(uint64_t channel_id, String event) - FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY + FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY { size_t length = (event.size < METHOD_MAXLEN ? event.size : @@ -706,13 +706,13 @@ void nvim_unsubscribe(uint64_t channel_id, String event) } Integer nvim_get_color_by_name(String name) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { return name_to_color((uint8_t *)name.data); } Dictionary nvim_get_color_map(void) - FUNC_API_SINCE(1) + FUNC_API_SINCE(1) { Dictionary colors = ARRAY_DICT_INIT; @@ -754,7 +754,7 @@ ArrayOf(Dictionary) nvim_get_keymap(String mode) } Array nvim_get_api_info(uint64_t channel_id) - FUNC_API_SINCE(1) FUNC_API_ASYNC FUNC_API_REMOTE_ONLY + FUNC_API_SINCE(1) FUNC_API_ASYNC FUNC_API_REMOTE_ONLY { Array rv = ARRAY_DICT_INIT; @@ -787,7 +787,7 @@ Array nvim_get_api_info(uint64_t channel_id) /// which resulted in an error, the error type and the error message. If an /// error ocurred, the values from all preceding calls will still be returned. Array nvim_call_atomic(uint64_t channel_id, Array calls, Error *err) - FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY + FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY { Array rv = ARRAY_DICT_INIT; Array results = ARRAY_DICT_INIT; -- cgit From 1eff241ec68ebec76ef1e3e5c6d68bfb64602cf5 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Thu, 28 Jul 2016 22:42:22 +0200 Subject: bufhl: use kbtree for bufhl --- src/nvim/api/vim.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 74e5167635..92985b412a 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -13,6 +13,7 @@ #include "nvim/ascii.h" #include "nvim/api/private/helpers.h" #include "nvim/api/private/defs.h" +#include "nvim/api/private/dispatch.h" #include "nvim/api/buffer.h" #include "nvim/msgpack_rpc/channel.h" #include "nvim/lua/executor.h" -- cgit