diff options
author | JP <17429390+resolritter@users.noreply.github.com> | 2023-04-30 06:02:38 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-30 11:02:38 +0200 |
commit | 4f3f81ed86542109824bd199198fb43e6fccdc17 (patch) | |
tree | d40e3469c61f58ac38ea302fab6693d10be9a263 | |
parent | 668f16bac779ac52d7bd9452e6001a7a6d1e9965 (diff) | |
download | rneovim-4f3f81ed86542109824bd199198fb43e6fccdc17.tar.gz rneovim-4f3f81ed86542109824bd199198fb43e6fccdc17.tar.bz2 rneovim-4f3f81ed86542109824bd199198fb43e6fccdc17.zip |
docs(api): document nvim_buf_add_highlight vs nvim_buf_set_extmark (#23310)
-rw-r--r-- | runtime/doc/api.txt | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt index 8d7253a754..2e1f58d0e3 100644 --- a/runtime/doc/api.txt +++ b/runtime/doc/api.txt @@ -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 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|): >python src = vim.new_highlight_source() |