diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2018-12-27 22:49:44 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2018-12-27 22:49:44 +0100 |
commit | c1015121ec626cab6cb384f544bc0be1a1760c0e (patch) | |
tree | 6cc9a5d1899a4486a24c491e07d17a7dd01f9503 /src/nvim/api/vim.c | |
parent | 4f030ec24e0e148bbb83aedaef7dd629e5fef130 (diff) | |
parent | e1876c7ad1b5e30c0a9919e2c4587d11550c8507 (diff) | |
download | rneovim-c1015121ec626cab6cb384f544bc0be1a1760c0e.tar.gz rneovim-c1015121ec626cab6cb384f544bc0be1a1760c0e.tar.bz2 rneovim-c1015121ec626cab6cb384f544bc0be1a1760c0e.zip |
Merge 'upstream/master' into pr-win-erw7
Diffstat (limited to 'src/nvim/api/vim.c')
-rw-r--r-- | src/nvim/api/vim.c | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index fed20a272a..4da61a30ef 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -46,6 +46,24 @@ # include "api/vim.c.generated.h" #endif +void api_vim_init(void) + FUNC_API_NOEXPORT +{ + namespace_ids = map_new(String, handle_T)(); +} + +void api_vim_free_all_mem(void) + FUNC_API_NOEXPORT +{ + String name; + handle_T id; + map_foreach(namespace_ids, name, id, { + (void)id; + xfree(name.data); + }) + map_free(String, handle_T)(namespace_ids); +} + /// Executes an ex-command. /// /// On execution error: fails with VimL error, does not update v:errmsg. @@ -725,6 +743,9 @@ void nvim_err_writeln(String str) /// Gets the current list of buffer handles /// +/// Includes unlisted (unloaded/deleted) buffers, like `:ls!`. +/// Use |nvim_buf_is_loaded()| to check if a buffer is loaded. +/// /// @return List of buffer handles ArrayOf(Buffer) nvim_list_bufs(void) FUNC_API_SINCE(1) @@ -884,6 +905,49 @@ void nvim_set_current_tabpage(Tabpage tabpage, Error *err) } } +/// create a new namespace, or get one with an exisiting name +/// +/// Namespaces are currently used for buffer highlighting and virtual text, see +/// |nvim_buf_add_highlight| and |nvim_buf_set_virtual_text|. +/// +/// Namespaces can have a name of be anonymous. If `name` is a non-empty string, +/// and a namespace already exists with that name,the existing namespace id is +/// returned. If an empty string is used, a new anonymous namespace is returned. +/// +/// @param name Name of the namespace or empty string +/// @return the namespace id +Integer nvim_create_namespace(String name) + FUNC_API_SINCE(5) +{ + handle_T id = map_get(String, handle_T)(namespace_ids, name); + if (id > 0) { + return id; + } + id = next_namespace_id++; + if (name.size > 0) { + String name_alloc = copy_string(name); + map_put(String, handle_T)(namespace_ids, name_alloc, id); + } + return (Integer)id; +} + +/// Get existing named namespaces +/// +/// @return dict that maps from names to namespace ids. +Dictionary nvim_get_namespaces(void) + FUNC_API_SINCE(5) +{ + Dictionary retval = ARRAY_DICT_INIT; + String name; + handle_T id; + + map_foreach(namespace_ids, name, id, { + PUT(retval, name.data, INTEGER_OBJ(id)); + }) + + return retval; +} + /// Subscribes to event broadcasts /// /// @param channel_id Channel id (passed automatically by the dispatcher) @@ -1028,7 +1092,7 @@ Array nvim_get_api_info(uint64_t channel_id) /// @param attributes Informal attributes describing the client. Clients might /// define their own keys, but the following are suggested: /// - "website" Website of client (for instance github repository) -/// - "license" Informal descripton of the license, such as "Apache 2", +/// - "license" Informal description of the license, such as "Apache 2", /// "GPLv3" or "MIT" /// - "logo" URI or path to image, preferably small logo or icon. /// .png or .svg format is preferred. |