From ba7277cfb4e2556f246446d06b53f3427f28130f Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Wed, 26 Jul 2017 23:28:26 +0200 Subject: Adds nvim_get_hl_by_name/by_id ...in order to retrieve highlights. Added test/functional/api/highlight_spec.lua HL_NORMAL is not really a good name, since it's more like an empty attribute than the normal's one. If one pays attention, syn_cterm_attr2entry is never called with attr=0 because it's always special cased before. I suggest in subsequent PRs we remove the ATTR_OFF and just insert an EMPTY ATTR/RESET_ATTR/UNINITIALIZED for id 0. --- src/nvim/api/vim.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index ab893a4c0f..0459d9235d 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -33,6 +33,7 @@ #include "nvim/syntax.h" #include "nvim/getchar.h" #include "nvim/os/input.h" +#include "nvim/ui.h" #define LINE_BUFFER_SIZE 4096 @@ -55,6 +56,42 @@ void nvim_command(String command, Error *err) try_end(err); } +/// Retrieves highlight description from its name +/// +/// @param name Highlight group name +/// @return a highlight description e.g. {'bold': true, 'bg': 123, 'fg': 42} +/// @see nvim_get_hl_by_id +Dictionary nvim_get_hl_by_name(String name, Error *err) + FUNC_API_SINCE(3) +{ + Dictionary result = ARRAY_DICT_INIT; + int id = syn_name2id((const char_u *)name.data); + + if (id == 0) { + api_set_error(err, kErrorTypeException, "Invalid highlight name %s", + name.data); + return result; + } + result = nvim_get_hl_by_id(id, err); + return result; +} + +/// Retrieves highlight description from its id +/// +/// @param hl_id highlight id as returned by hlID() +/// @see nvim_get_hl_by_name +Dictionary nvim_get_hl_by_id(Integer hl_id, Error *err) + FUNC_API_SINCE(3) +{ + Dictionary dic = ARRAY_DICT_INIT; + if (syn_get_final_id((int)hl_id) == 0) { + api_set_error(err, kErrorTypeException, "Invalid highlight id %d", hl_id); + return dic; + } + int attrcode = syn_id2attr((int)hl_id); + return get_attr_by_id(attrcode, err); +} + /// Passes input keys to Nvim. /// On VimL error: Does not fail, but updates v:errmsg. /// -- cgit From e3a2cca3878f44252eccdc1918cc8854145de860 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Sun, 27 Aug 2017 00:33:36 +0200 Subject: Increased test coverage for RGB and cterm --- src/nvim/api/vim.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 0459d9235d..bf3e4bc6a0 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -78,7 +78,7 @@ Dictionary nvim_get_hl_by_name(String name, Error *err) /// Retrieves highlight description from its id /// -/// @param hl_id highlight id as returned by hlID() +/// @param hl_id highlight id as returned by |hlID()| /// @see nvim_get_hl_by_name Dictionary nvim_get_hl_by_id(Integer hl_id, Error *err) FUNC_API_SINCE(3) @@ -89,7 +89,7 @@ Dictionary nvim_get_hl_by_id(Integer hl_id, Error *err) return dic; } int attrcode = syn_id2attr((int)hl_id); - return get_attr_by_id(attrcode, err); + return hl_get_attr_by_id(attrcode, err); } /// Passes input keys to Nvim. -- cgit From 3a006486397d611234abd9b429bce0b44d6b7747 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Sun, 3 Sep 2017 05:25:57 +0200 Subject: Changed prototypes to accept a boolean "rgb" --- src/nvim/api/vim.c | 10 ++++++---- 1 file changed, 6 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 bf3e4bc6a0..0c3c497533 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -59,9 +59,10 @@ void nvim_command(String command, Error *err) /// Retrieves highlight description from its name /// /// @param name Highlight group name +/// @param rgb True to export GUI values /// @return a highlight description e.g. {'bold': true, 'bg': 123, 'fg': 42} /// @see nvim_get_hl_by_id -Dictionary nvim_get_hl_by_name(String name, Error *err) +Dictionary nvim_get_hl_by_name(String name, Boolean rgb, Error *err) FUNC_API_SINCE(3) { Dictionary result = ARRAY_DICT_INIT; @@ -72,15 +73,16 @@ Dictionary nvim_get_hl_by_name(String name, Error *err) name.data); return result; } - result = nvim_get_hl_by_id(id, err); + result = nvim_get_hl_by_id(id, rgb, err); return result; } /// Retrieves highlight description from its id /// /// @param hl_id highlight id as returned by |hlID()| +/// @param rgb True to export GUI values /// @see nvim_get_hl_by_name -Dictionary nvim_get_hl_by_id(Integer hl_id, Error *err) +Dictionary nvim_get_hl_by_id(Integer hl_id, Boolean rgb, Error *err) FUNC_API_SINCE(3) { Dictionary dic = ARRAY_DICT_INIT; @@ -89,7 +91,7 @@ Dictionary nvim_get_hl_by_id(Integer hl_id, Error *err) return dic; } int attrcode = syn_id2attr((int)hl_id); - return hl_get_attr_by_id(attrcode, err); + return hl_get_attr_by_id(attrcode, rgb, err); } /// Passes input keys to Nvim. -- cgit From 52517321d1859c31fef14aa75d784615693fcecb Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 8 Oct 2017 20:23:11 +0200 Subject: test: nvim_get_hl_by_name/by_id #7082 - test all properties - test failure modes --- 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 bc89ffefe6..98f4410347 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -33,7 +33,6 @@ #include "nvim/syntax.h" #include "nvim/getchar.h" #include "nvim/os/input.h" -#include "nvim/ui.h" #define LINE_BUFFER_SIZE 4096 -- cgit