diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2018-11-24 19:36:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-24 19:36:04 +0100 |
commit | 8b39e4ec793334be0e48101830f66e05691393bd (patch) | |
tree | 40d9b5b3fee2829baf8c3ab5fa38cf8d0629d7ce /src/nvim/api/vim.c | |
parent | 108566e7b6f1b331dac8e339280c230bf39c137d (diff) | |
parent | 01dbf0951b25d582451a8e656731dcf3d9295a71 (diff) | |
download | rneovim-8b39e4ec793334be0e48101830f66e05691393bd.tar.gz rneovim-8b39e4ec793334be0e48101830f66e05691393bd.tar.bz2 rneovim-8b39e4ec793334be0e48101830f66e05691393bd.zip |
Merge pull request #6920 from bfredl/namespace
make namespaces explicit (intitially for bufhl and virttext)
Diffstat (limited to 'src/nvim/api/vim.c')
-rw-r--r-- | src/nvim/api/vim.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 7fcccfd988..54b27477e0 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. @@ -884,6 +902,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) |