mirror of
https://github.com/neovim/neovim
synced 2025-07-18 02:01:46 +00:00
feat(ui): allow to get the highlight namespace
This commit is contained in:
@ -979,6 +979,19 @@ nvim_get_hl_id_by_name({name}) *nvim_get_hl_id_by_name()*
|
|||||||
|
|
||||||
similar to |hlID()|, but allocates a new ID if not present.
|
similar to |hlID()|, but allocates a new ID if not present.
|
||||||
|
|
||||||
|
nvim_get_hl_ns({*opts}) *nvim_get_hl_ns()*
|
||||||
|
Gets the active highlight namespace.
|
||||||
|
|
||||||
|
Parameters: ~
|
||||||
|
• {opts} Optional parameters
|
||||||
|
• winid: (number) |window-ID| for retrieving a window's
|
||||||
|
highlight namespace. A value of -1 is returned when
|
||||||
|
|nvim_win_set_hl_ns()| has not been called for the window
|
||||||
|
(or was called with a namespace of -1).
|
||||||
|
|
||||||
|
Return: ~
|
||||||
|
Namespace id, or -1
|
||||||
|
|
||||||
nvim_get_keymap({mode}) *nvim_get_keymap()*
|
nvim_get_keymap({mode}) *nvim_get_keymap()*
|
||||||
Gets a list of global (non-buffer-local) |mapping| definitions.
|
Gets a list of global (non-buffer-local) |mapping| definitions.
|
||||||
|
|
||||||
|
10
runtime/lua/vim/_meta/api.lua
generated
10
runtime/lua/vim/_meta/api.lua
generated
@ -1258,6 +1258,16 @@ function vim.api.nvim_get_hl_by_name(name, rgb) end
|
|||||||
--- @return integer
|
--- @return integer
|
||||||
function vim.api.nvim_get_hl_id_by_name(name) end
|
function vim.api.nvim_get_hl_id_by_name(name) end
|
||||||
|
|
||||||
|
--- Gets the active highlight namespace.
|
||||||
|
---
|
||||||
|
--- @param opts vim.api.keyset.get_ns Optional parameters
|
||||||
|
--- • winid: (number) `window-ID` for retrieving a window's
|
||||||
|
--- highlight namespace. A value of -1 is returned when
|
||||||
|
--- `nvim_win_set_hl_ns()` has not been called for the window
|
||||||
|
--- (or was called with a namespace of -1).
|
||||||
|
--- @return integer
|
||||||
|
function vim.api.nvim_get_hl_ns(opts) end
|
||||||
|
|
||||||
--- Gets a list of global (non-buffer-local) `mapping` definitions.
|
--- Gets a list of global (non-buffer-local) `mapping` definitions.
|
||||||
---
|
---
|
||||||
--- @param mode string Mode short-name ("n", "i", "v", ...)
|
--- @param mode string Mode short-name ("n", "i", "v", ...)
|
||||||
|
3
runtime/lua/vim/_meta/api_keysets.lua
generated
3
runtime/lua/vim/_meta/api_keysets.lua
generated
@ -136,6 +136,9 @@ error('Cannot require a meta file')
|
|||||||
--- @field link? boolean
|
--- @field link? boolean
|
||||||
--- @field create? boolean
|
--- @field create? boolean
|
||||||
|
|
||||||
|
--- @class vim.api.keyset.get_ns
|
||||||
|
--- @field winid? integer
|
||||||
|
|
||||||
--- @class vim.api.keyset.highlight
|
--- @class vim.api.keyset.highlight
|
||||||
--- @field bold? boolean
|
--- @field bold? boolean
|
||||||
--- @field standout? boolean
|
--- @field standout? boolean
|
||||||
|
@ -195,6 +195,11 @@ typedef struct {
|
|||||||
Boolean create;
|
Boolean create;
|
||||||
} Dict(get_highlight);
|
} Dict(get_highlight);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
OptionalKeys is_set__get_ns_;
|
||||||
|
Window winid;
|
||||||
|
} Dict(get_ns);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
OptionalKeys is_set__win_text_height_;
|
OptionalKeys is_set__win_text_height_;
|
||||||
Integer start_row;
|
Integer start_row;
|
||||||
|
@ -170,6 +170,29 @@ void nvim_set_hl(Integer ns_id, String name, Dict(highlight) *val, Error *err)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets the active highlight namespace.
|
||||||
|
///
|
||||||
|
/// @param opts Optional parameters
|
||||||
|
/// - winid: (number) |window-ID| for retrieving a window's highlight
|
||||||
|
/// namespace. A value of -1 is returned when |nvim_win_set_hl_ns()|
|
||||||
|
/// has not been called for the window (or was called with a namespace
|
||||||
|
/// of -1).
|
||||||
|
/// @param[out] err Error details, if any
|
||||||
|
/// @return Namespace id, or -1
|
||||||
|
Integer nvim_get_hl_ns(Dict(get_ns) *opts, Error *err)
|
||||||
|
FUNC_API_SINCE(12)
|
||||||
|
{
|
||||||
|
if (HAS_KEY(opts, get_ns, winid)) {
|
||||||
|
win_T *win = find_window_by_handle(opts->winid, err);
|
||||||
|
if (!win) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return win->w_ns_hl;
|
||||||
|
} else {
|
||||||
|
return ns_hl_global;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Set active namespace for highlights defined with |nvim_set_hl()|. This can be set for
|
/// Set active namespace for highlights defined with |nvim_set_hl()|. This can be set for
|
||||||
/// a single window, see |nvim_win_set_hl_ns()|.
|
/// a single window, see |nvim_win_set_hl_ns()|.
|
||||||
///
|
///
|
||||||
|
@ -637,3 +637,19 @@ describe('API: get highlight', function()
|
|||||||
eq({link ='Foo', default = true}, meths.get_hl(0, {name = 'Bar'}))
|
eq({link ='Foo', default = true}, meths.get_hl(0, {name = 'Bar'}))
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('API: set/get highlight namespace', function()
|
||||||
|
it('set/get highlight namespace', function()
|
||||||
|
eq(0, meths.get_hl_ns({}))
|
||||||
|
local ns = meths.create_namespace('')
|
||||||
|
meths.set_hl_ns(ns)
|
||||||
|
eq(ns, meths.get_hl_ns({}))
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('set/get window highlight namespace', function()
|
||||||
|
eq(-1, meths.get_hl_ns({winid = 0}))
|
||||||
|
local ns = meths.create_namespace('')
|
||||||
|
meths.win_set_hl_ns(0, ns)
|
||||||
|
eq(ns, meths.get_hl_ns({winid = 0}))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
Reference in New Issue
Block a user