aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api
diff options
context:
space:
mode:
authorNull Chilly <56817415+nullchilly@users.noreply.github.com>2023-03-23 16:31:39 +0700
committerGitHub <noreply@github.com>2023-03-23 10:31:39 +0100
commitc0fe6c040e19ef9102a8507ffcbd88b83186326a (patch)
treeabaecffb9bfd97ae0f00502c7560eb001100c135 /src/nvim/api
parentea0b66d208dbcd5d5c0a17810596d769c7a0b6dd (diff)
downloadrneovim-c0fe6c040e19ef9102a8507ffcbd88b83186326a.tar.gz
rneovim-c0fe6c040e19ef9102a8507ffcbd88b83186326a.tar.bz2
rneovim-c0fe6c040e19ef9102a8507ffcbd88b83186326a.zip
feat(api): add nvim_get_hl (#22693)
Problem: no way of getting all highlight group definitions in a namespace. Solution: add `nvim_get_hl()`, deprecate `nvim_get_hl_by_name()` and `nvim_get_hl_by_id()`.
Diffstat (limited to 'src/nvim/api')
-rw-r--r--src/nvim/api/deprecated.c46
-rw-r--r--src/nvim/api/keysets.lua5
-rw-r--r--src/nvim/api/ui.c8
-rw-r--r--src/nvim/api/vim.c56
4 files changed, 70 insertions, 45 deletions
diff --git a/src/nvim/api/deprecated.c b/src/nvim/api/deprecated.c
index 332e2b5fc3..b1e2e6811e 100644
--- a/src/nvim/api/deprecated.c
+++ b/src/nvim/api/deprecated.c
@@ -10,11 +10,14 @@
#include "nvim/api/extmark.h"
#include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
+#include "nvim/api/private/validate.h"
#include "nvim/api/vimscript.h"
#include "nvim/buffer_defs.h"
#include "nvim/decoration.h"
#include "nvim/extmark.h"
#include "nvim/globals.h"
+#include "nvim/highlight.h"
+#include "nvim/highlight_group.h"
#include "nvim/lua/executor.h"
#include "nvim/memory.h"
#include "nvim/pos.h"
@@ -159,6 +162,49 @@ Integer nvim_buf_set_virtual_text(Buffer buffer, Integer src_id, Integer line, A
return src_id;
}
+/// Gets a highlight definition by id. |hlID()|
+///
+/// @deprecated use |nvim_get_hl()| instead
+///
+/// @param hl_id Highlight id as returned by |hlID()|
+/// @param rgb Export RGB colors
+/// @param[out] err Error details, if any
+/// @return Highlight definition map
+/// @see nvim_get_hl_by_name
+Dictionary nvim_get_hl_by_id(Integer hl_id, Boolean rgb, Arena *arena, Error *err)
+ FUNC_API_SINCE(3)
+ FUNC_API_DEPRECATED_SINCE(9)
+{
+ Dictionary dic = ARRAY_DICT_INIT;
+ VALIDATE_INT((syn_get_final_id((int)hl_id) != 0), "highlight id", hl_id, {
+ return dic;
+ });
+ int attrcode = syn_id2attr((int)hl_id);
+ return hl_get_attr_by_id(attrcode, rgb, arena, err);
+}
+
+/// Gets a highlight definition by name.
+///
+/// @deprecated use |nvim_get_hl()| instead
+///
+/// @param name Highlight group name
+/// @param rgb Export RGB colors
+/// @param[out] err Error details, if any
+/// @return Highlight definition map
+/// @see nvim_get_hl_by_id
+Dictionary nvim_get_hl_by_name(String name, Boolean rgb, Arena *arena, Error *err)
+ FUNC_API_SINCE(3)
+ FUNC_API_DEPRECATED_SINCE(9)
+{
+ Dictionary result = ARRAY_DICT_INIT;
+ int id = syn_name2id(name.data);
+
+ VALIDATE_S((id != 0), "highlight name", name.data, {
+ return result;
+ });
+ return nvim_get_hl_by_id(id, rgb, arena, err);
+}
+
/// Inserts a sequence of lines to a buffer at a certain index
///
/// @deprecated use nvim_buf_set_lines(buffer, lnum, lnum, true, lines)
diff --git a/src/nvim/api/keysets.lua b/src/nvim/api/keysets.lua
index 2c7532bd27..b2b327d73e 100644
--- a/src/nvim/api/keysets.lua
+++ b/src/nvim/api/keysets.lua
@@ -145,6 +145,11 @@ return {
"altfont";
"nocombine";
}};
+ { 'get_highlight', {
+ "id";
+ "name";
+ "link";
+ }};
-- Autocmds
{ 'clear_autocmds', {
"buffer";
diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c
index a8f5d2e070..201989aee5 100644
--- a/src/nvim/api/ui.c
+++ b/src/nvim/api/ui.c
@@ -727,8 +727,8 @@ void remote_ui_hl_attr_define(UI *ui, Integer id, HlAttrs rgb_attrs, HlAttrs cte
ADD_C(args, INTEGER_OBJ(id));
MAXSIZE_TEMP_DICT(rgb, HLATTRS_DICT_SIZE);
MAXSIZE_TEMP_DICT(cterm, HLATTRS_DICT_SIZE);
- hlattrs2dict(&rgb, rgb_attrs, true);
- hlattrs2dict(&cterm, rgb_attrs, false);
+ hlattrs2dict(&rgb, rgb_attrs, true, false);
+ hlattrs2dict(&cterm, rgb_attrs, false, false);
ADD_C(args, DICTIONARY_OBJ(rgb));
ADD_C(args, DICTIONARY_OBJ(cterm));
@@ -751,7 +751,7 @@ void remote_ui_highlight_set(UI *ui, int id)
}
data->hl_id = id;
MAXSIZE_TEMP_DICT(dict, HLATTRS_DICT_SIZE);
- hlattrs2dict(&dict, syn_attr2entry(id), ui->rgb);
+ hlattrs2dict(&dict, syn_attr2entry(id), ui->rgb, false);
ADD_C(args, DICTIONARY_OBJ(dict));
push_call(ui, "highlight_set", args);
}
@@ -950,7 +950,7 @@ static Array translate_contents(UI *ui, Array contents, Arena *arena)
int attr = (int)item.items[0].data.integer;
if (attr) {
Dictionary rgb_attrs = arena_dict(arena, HLATTRS_DICT_SIZE);
- hlattrs2dict(&rgb_attrs, syn_attr2entry(attr), ui->rgb);
+ hlattrs2dict(&rgb_attrs, syn_attr2entry(attr), ui->rgb, false);
ADD(new_item, DICTIONARY_OBJ(rgb_attrs));
} else {
ADD(new_item, DICTIONARY_OBJ((Dictionary)ARRAY_DICT_INIT));
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index 4689e6b5bf..ca5dd97020 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -74,42 +74,6 @@
# include "api/vim.c.generated.h"
#endif
-/// Gets a highlight definition by name.
-///
-/// @param name Highlight group name
-/// @param rgb Export RGB colors
-/// @param[out] err Error details, if any
-/// @return Highlight definition map
-/// @see nvim_get_hl_by_id
-Dictionary nvim_get_hl_by_name(String name, Boolean rgb, Arena *arena, Error *err)
- FUNC_API_SINCE(3)
-{
- Dictionary result = ARRAY_DICT_INIT;
- int id = syn_name2id(name.data);
-
- VALIDATE_S((id != 0), "highlight name", name.data, {
- return result;
- });
- return nvim_get_hl_by_id(id, rgb, arena, err);
-}
-
-/// Gets a highlight definition by id. |hlID()|
-/// @param hl_id Highlight id as returned by |hlID()|
-/// @param rgb Export RGB colors
-/// @param[out] err Error details, if any
-/// @return Highlight definition map
-/// @see nvim_get_hl_by_name
-Dictionary nvim_get_hl_by_id(Integer hl_id, Boolean rgb, Arena *arena, Error *err)
- FUNC_API_SINCE(3)
-{
- Dictionary dic = ARRAY_DICT_INIT;
- VALIDATE_INT((syn_get_final_id((int)hl_id) != 0), "highlight id", hl_id, {
- return dic;
- });
- int attrcode = syn_id2attr((int)hl_id);
- return hl_get_attr_by_id(attrcode, rgb, arena, err);
-}
-
/// Gets a highlight group by name
///
/// similar to |hlID()|, but allocates a new ID if not present.
@@ -119,12 +83,22 @@ Integer nvim_get_hl_id_by_name(String name)
return syn_check_group(name.data, name.size);
}
-Dictionary nvim__get_hl_defs(Integer ns_id, Arena *arena, Error *err)
+/// Gets all or specific highlight groups in a namespace.
+///
+/// @param ns_id Get highlight groups for namespace ns_id |nvim_get_namespaces()|.
+/// Use 0 to get global highlight groups |:highlight|.
+/// @param opts Options dict:
+/// - name: (string) Get a highlight definition by name.
+/// - id: (integer) Get a highlight definition by id.
+/// - link: (boolean, default true) Show linked group name instead of effective definition |:hi-link|.
+///
+/// @param[out] err Error details, if any.
+/// @return Highlight groups as a map from group name to a highlight definition map as in |nvim_set_hl()|,
+/// or only a single highlight definition map if requested by name or id.
+Dictionary nvim_get_hl(Integer ns_id, Dict(get_highlight) *opts, Arena *arena, Error *err)
+ FUNC_API_SINCE(11)
{
- if (ns_id == 0) {
- return get_global_hl_defs(arena);
- }
- abort();
+ return ns_get_hl_defs((NS)ns_id, opts, arena, err);
}
/// Sets a highlight group.