aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/vim.c
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2017-06-23 09:56:35 +0200
committerBjörn Linse <bjorn.linse@gmail.com>2018-11-24 11:01:37 +0100
commit01dbf0951b25d582451a8e656731dcf3d9295a71 (patch)
tree40d9b5b3fee2829baf8c3ab5fa38cf8d0629d7ce /src/nvim/api/vim.c
parent108566e7b6f1b331dac8e339280c230bf39c137d (diff)
downloadrneovim-01dbf0951b25d582451a8e656731dcf3d9295a71.tar.gz
rneovim-01dbf0951b25d582451a8e656731dcf3d9295a71.tar.bz2
rneovim-01dbf0951b25d582451a8e656731dcf3d9295a71.zip
api: implement object namespaces
Namespaces is a lightweight concept that should be used to group objects for purposes of bulk operations and introspection. This is initially used for highlights and virtual text in buffers, and is planned to also be used for extended marks. There is no plan use them for privileges or isolation, neither to introduce nanespace-level options.
Diffstat (limited to 'src/nvim/api/vim.c')
-rw-r--r--src/nvim/api/vim.c61
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)