mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 03:05:11 -07:00
feat(ui): allow to get the highlight namespace
This commit is contained in:
parent
be463e7643
commit
2615ed879e
@ -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.
|
||||
|
||||
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()*
|
||||
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
|
||||
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.
|
||||
---
|
||||
--- @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 create? boolean
|
||||
|
||||
--- @class vim.api.keyset.get_ns
|
||||
--- @field winid? integer
|
||||
|
||||
--- @class vim.api.keyset.highlight
|
||||
--- @field bold? boolean
|
||||
--- @field standout? boolean
|
||||
|
@ -195,6 +195,11 @@ typedef struct {
|
||||
Boolean create;
|
||||
} Dict(get_highlight);
|
||||
|
||||
typedef struct {
|
||||
OptionalKeys is_set__get_ns_;
|
||||
Window winid;
|
||||
} Dict(get_ns);
|
||||
|
||||
typedef struct {
|
||||
OptionalKeys is_set__win_text_height_;
|
||||
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
|
||||
/// 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'}))
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user