mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
docs(api): document nvim_buf_add_highlight vs nvim_buf_set_extmark (#23310)
This commit is contained in:
parent
668f16bac7
commit
4f3f81ed86
@ -400,6 +400,23 @@ external highlighter plugin wants to add many highlights in a batch,
|
|||||||
performance can be improved by calling |nvim_buf_add_highlight()| as an
|
performance can be improved by calling |nvim_buf_add_highlight()| as an
|
||||||
asynchronous notification, after first (synchronously) requesting a source id.
|
asynchronous notification, after first (synchronously) requesting a source id.
|
||||||
|
|
||||||
|
|nvim_buf_add_highlight()| adds highlights as |extmarks|. If highlights need to
|
||||||
|
be tracked or manipulated after adding them, it is better to use
|
||||||
|
|nvim_buf_set_extmark()| directly, as this function returns the placed |extmark|
|
||||||
|
id. Thus, instead of >lua
|
||||||
|
vim.api.nvim_buf_add_highlight(buf, ns_id, hl_group, line, col_start, col_end)
|
||||||
|
<
|
||||||
|
use >lua
|
||||||
|
-- create the highlight through an extmark
|
||||||
|
extid = vim.api.nvim_buf_set_extmark(buf, ns_id, hl_group, line, col_start, {end_col = col_end, hl_group = hl_group})
|
||||||
|
|
||||||
|
-- example: modify the extmark's highlight group
|
||||||
|
vim.api.nvim_buf_set_extmark(buf, ns_id, NEW_HL_GROUP, line, col_start, {end_col = col_end, hl_group = hl_group, id = extid})
|
||||||
|
|
||||||
|
-- example: change the highlight's position
|
||||||
|
vim.api.nvim_buf_set_extmark(buf, ns_id, hl_group, NEW_LINE, col_start, {end_col = col_end, hl_group = hl_group, id = extid})
|
||||||
|
<
|
||||||
|
|
||||||
Example using the Python API client (|pynvim|):
|
Example using the Python API client (|pynvim|):
|
||||||
>python
|
>python
|
||||||
src = vim.new_highlight_source()
|
src = vim.new_highlight_source()
|
||||||
|
Loading…
Reference in New Issue
Block a user