mirror of
https://github.com/neovim/neovim.git
synced 2025-09-23 11:38:31 +00:00
Merge #7082 'api: nvim_get_hl_by_name/by_id'
This commit is contained in:
@@ -242,39 +242,7 @@ static void push_call(UI *ui, char *name, Array args)
|
||||
static void remote_ui_highlight_set(UI *ui, HlAttrs attrs)
|
||||
{
|
||||
Array args = ARRAY_DICT_INIT;
|
||||
Dictionary hl = ARRAY_DICT_INIT;
|
||||
|
||||
if (attrs.bold) {
|
||||
PUT(hl, "bold", BOOLEAN_OBJ(true));
|
||||
}
|
||||
|
||||
if (attrs.underline) {
|
||||
PUT(hl, "underline", BOOLEAN_OBJ(true));
|
||||
}
|
||||
|
||||
if (attrs.undercurl) {
|
||||
PUT(hl, "undercurl", BOOLEAN_OBJ(true));
|
||||
}
|
||||
|
||||
if (attrs.italic) {
|
||||
PUT(hl, "italic", BOOLEAN_OBJ(true));
|
||||
}
|
||||
|
||||
if (attrs.reverse) {
|
||||
PUT(hl, "reverse", BOOLEAN_OBJ(true));
|
||||
}
|
||||
|
||||
if (attrs.foreground != -1) {
|
||||
PUT(hl, "foreground", INTEGER_OBJ(attrs.foreground));
|
||||
}
|
||||
|
||||
if (attrs.background != -1) {
|
||||
PUT(hl, "background", INTEGER_OBJ(attrs.background));
|
||||
}
|
||||
|
||||
if (attrs.special != -1) {
|
||||
PUT(hl, "special", INTEGER_OBJ(attrs.special));
|
||||
}
|
||||
Dictionary hl = hlattrs2dict(attrs);
|
||||
|
||||
ADD(args, DICTIONARY_OBJ(hl));
|
||||
push_call(ui, "highlight_set", args);
|
||||
|
@@ -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.
|
||||
///
|
||||
|
Reference in New Issue
Block a user