aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/vim.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2017-10-08 19:09:14 +0200
committerJustin M. Keyes <justinkz@gmail.com>2017-10-08 19:09:14 +0200
commit04187a1c74e79abfb46c0b9c1e522b61f1cedcae (patch)
treeae13c45333d1fb47e1734f59d3625139d69a8161 /src/nvim/api/vim.c
parent032b088c848585e60e8dc1a210f240bad6bb3387 (diff)
parent481e40cc8ca061f5c3a68f56f30ee96e9086da4d (diff)
downloadrneovim-04187a1c74e79abfb46c0b9c1e522b61f1cedcae.tar.gz
rneovim-04187a1c74e79abfb46c0b9c1e522b61f1cedcae.tar.bz2
rneovim-04187a1c74e79abfb46c0b9c1e522b61f1cedcae.zip
Merge #7082 'api: nvim_get_hl_by_name/by_id'
Diffstat (limited to 'src/nvim/api/vim.c')
-rw-r--r--src/nvim/api/vim.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index ab893a4c0f..bc89ffefe6 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,47 @@ void nvim_command(String command, Error *err)
try_end(err);
}
+/// 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, 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, rgb, err);
+ return result;
+}
+
+/// 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, 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 hl_get_attr_by_id(attrcode, rgb, err);
+}
+
/// Passes input keys to Nvim.
/// On VimL error: Does not fail, but updates v:errmsg.
///