From efaf4732e26e2f0fbfab947296141376223b30d7 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 27 Oct 2019 15:26:32 -0700 Subject: lua/executor.c: use TRY_WRAP --- src/nvim/api/private/helpers.h | 14 ++++++++++++++ src/nvim/api/vim.c | 14 -------------- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index 0ea7667428..8930f252f6 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -102,6 +102,20 @@ typedef struct { int did_emsg; } TryState; +// `msg_list` controls the collection of abort-causing non-exception errors, +// which would otherwise be ignored. This pattern is from do_cmdline(). +// +// TODO(bfredl): prepare error-handling at "top level" (nv_event). +#define TRY_WRAP(code) \ + do { \ + struct msglist **saved_msg_list = msg_list; \ + struct msglist *private_msg_list; \ + msg_list = &private_msg_list; \ + private_msg_list = NULL; \ + code \ + msg_list = saved_msg_list; /* Restore the exception context. */ \ + } while (0) + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "api/private/helpers.h.generated.h" #endif diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 602733fd31..59761c13e7 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -53,20 +53,6 @@ # include "api/vim.c.generated.h" #endif -// `msg_list` controls the collection of abort-causing non-exception errors, -// which would otherwise be ignored. This pattern is from do_cmdline(). -// -// TODO(bfredl): prepare error-handling at "top level" (nv_event). -#define TRY_WRAP(code) \ - do { \ - struct msglist **saved_msg_list = msg_list; \ - struct msglist *private_msg_list; \ - msg_list = &private_msg_list; \ - private_msg_list = NULL; \ - code \ - msg_list = saved_msg_list; /* Restore the exception context. */ \ - } while (0) - void api_vim_init(void) FUNC_API_NOEXPORT { -- cgit From 9ef16a1628722958b6e14fe9274006e50ed6682d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 27 Oct 2019 15:05:59 -0700 Subject: doc: vim.fn, vim.call(), vim.api [ci skip] --- src/nvim/api/buffer.c | 49 ++++++++++++++++++++++++++++++++----------------- src/nvim/api/vim.c | 5 ++--- 2 files changed, 34 insertions(+), 20 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 3e1209d1b1..cb74c4227b 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -101,25 +101,39 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err) return rv; } -/// Activates buffer-update events on a channel, or as lua callbacks. +/// Activates buffer-update events on a channel, or as Lua callbacks. +/// +/// @see |nvim_buf_detach()| +/// @see |api-buffer-updates-lua| /// /// @param channel_id /// @param buffer Buffer handle, or 0 for current buffer -/// @param send_buffer Set to true if the initial notification should contain -/// the whole buffer. If so, the first notification will be a -/// `nvim_buf_lines_event`. Otherwise, the first notification will be -/// a `nvim_buf_changedtick_event`. Not used for lua callbacks. +/// @param send_buffer True if the initial notification should contain the +/// whole buffer: first notification will be `nvim_buf_lines_event`. +/// Else the first notification will be `nvim_buf_changedtick_event`. +/// Not for Lua callbacks. /// @param opts Optional parameters. -/// - `on_lines`: lua callback received on change. -/// - `on_changedtick`: lua callback received on changedtick -/// increment without text change. -/// - `utf_sizes`: include UTF-32 and UTF-16 size of -/// the replaced region. -/// See |api-buffer-updates-lua| for more information +/// - on_lines: Lua callback invoked on change. +/// Return `true` to detach. Args: +/// - buffer handle +/// - b:changedtick +/// - first line that changed (zero-indexed) +/// - last line that was changed +/// - last line in the updated range +/// - byte count of previous contents +/// - deleted_codepoints (if `utf_sizes` is true) +/// - deleted_codeunits (if `utf_sizes` is true) +/// - on_changedtick: Lua callback invoked on changedtick +/// increment without text change. Args: +/// - buffer handle +/// - b:changedtick +/// - on_detach: Lua callback invoked on detach. Args: +/// - buffer handle +/// - utf_sizes: include UTF-32 and UTF-16 size of the replaced +/// region, as args to `on_lines`. /// @param[out] err Error details, if any -/// @return False when updates couldn't be enabled because the buffer isn't -/// loaded or `opts` contained an invalid key; otherwise True. -/// TODO: LUA_API_NO_EVAL +/// @return False if attach failed (invalid parameter, or buffer isn't loaded); +/// otherwise True. TODO: LUA_API_NO_EVAL Boolean nvim_buf_attach(uint64_t channel_id, Buffer buffer, Boolean send_buffer, @@ -183,13 +197,14 @@ error: /// Deactivates buffer-update events on the channel. /// -/// For Lua callbacks see |api-lua-detach|. +/// @see |nvim_buf_attach()| +/// @see |api-lua-detach| for detaching Lua callbacks /// /// @param channel_id /// @param buffer Buffer handle, or 0 for current buffer /// @param[out] err Error details, if any -/// @return False when updates couldn't be disabled because the buffer -/// isn't loaded; otherwise True. +/// @return False if detach failed (because the buffer isn't loaded); +/// otherwise True. Boolean nvim_buf_detach(uint64_t channel_id, Buffer buffer, Error *err) diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 59761c13e7..0e64658f36 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1040,10 +1040,9 @@ fail: /// @param enter Enter the window (make it the current window) /// @param config Map defining the window configuration. Keys: /// - `relative`: Sets the window layout to "floating", placed at (row,col) -/// coordinates relative to one of: +/// coordinates relative to: /// - "editor" The global editor grid -/// - "win" Window given by the `win` field, or current window by -/// default. +/// - "win" Window given by the `win` field, or current window. /// - "cursor" Cursor position in current window. /// - `win`: |window-ID| for relative="win". /// - `anchor`: Decides which corner of the float to place at (row,col): -- cgit From 7a23b67d3594ffb8b6d8629fd9ca1ef8147596db Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 9 Nov 2019 21:18:51 -0800 Subject: paste: Select-mode, Visual-mode #11360 fix #11344 --- src/nvim/api/vim.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 0e64658f36..e587df5384 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1251,7 +1251,7 @@ Boolean nvim_paste(String data, Boolean crlf, Integer phase, Error *err) draining = true; goto theend; } - if (!(State & CMDLINE) && !(State & INSERT) && (phase == -1 || phase == 1)) { + if (!(State & (CMDLINE | INSERT)) && (phase == -1 || phase == 1)) { ResetRedobuff(); AppendCharToRedobuff('a'); // Dot-repeat. } @@ -1269,7 +1269,7 @@ Boolean nvim_paste(String data, Boolean crlf, Integer phase, Error *err) } } } - if (!(State & CMDLINE) && !(State & INSERT) && (phase == -1 || phase == 3)) { + if (!(State & (CMDLINE | INSERT)) && (phase == -1 || phase == 3)) { AppendCharToRedobuff(ESC); // Dot-repeat. } theend: -- cgit From 1cb4674547828a315b7aef5b6c635726b3bc12e5 Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Sun, 10 Nov 2019 16:38:04 +0100 Subject: api: add nvim_buf_get_virtual_text() (#11354) This adds the missing partner function of nvim_buf_set_virtual_text(). --- src/nvim/api/buffer.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index cb74c4227b..10250be044 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -1207,7 +1207,57 @@ free_exit: return 0; } -Dictionary nvim__buf_stats(Buffer buffer, Error *err) +/// Get the virtual text (annotation) for a buffer line. +/// +/// The virtual text is returned as list of lists, whereas the inner lists have +/// either one or two elements. The first element is the actual text, the +/// optional second element is the highlight group. +/// +/// The format is exactly the same as given to nvim_buf_set_virtual_text(). +/// +/// If there is no virtual text associated with the given line, an empty list +/// is returned. +/// +/// @param buffer Buffer handle, or 0 for current buffer +/// @param line Line to get the virtual text from (zero-indexed) +/// @param[out] err Error details, if any +/// @return List of virtual text chunks +Array nvim_buf_get_virtual_text(Buffer buffer, Integer lnum, Error *err) + FUNC_API_SINCE(7) +{ + Array chunks = ARRAY_DICT_INIT; + + buf_T *buf = find_buffer_by_handle(buffer, err); + if (!buf) { + return chunks; + } + + if (lnum < 0 || lnum >= MAXLNUM) { + api_set_error(err, kErrorTypeValidation, "Line number outside range"); + return chunks; + } + + BufhlLine *lineinfo = bufhl_tree_ref(&buf->b_bufhl_info, (linenr_T)(lnum + 1), + false); + if (!lineinfo) { + return chunks; + } + + for (size_t i = 0; i < lineinfo->virt_text.size; i++) { + Array chunk = ARRAY_DICT_INIT; + VirtTextChunk *vtc = &lineinfo->virt_text.items[i]; + ADD(chunk, STRING_OBJ(cstr_to_string(vtc->text))); + if (vtc->hl_id > 0) { + ADD(chunk, STRING_OBJ(cstr_to_string( + (const char *)syn_id2name(vtc->hl_id)))); + } + ADD(chunks, ARRAY_OBJ(chunk)); + } + + return chunks; +} + +Dictionary nvim__uf_stats(Buffer buffer, Error *err) { Dictionary rv = ARRAY_DICT_INIT; -- cgit From 181486d7e614c1a417ec0f555cdfd25716cb5e38 Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Mon, 11 Nov 2019 19:25:10 +0100 Subject: api: fix typo in debug function name --- src/nvim/api/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 10250be044..257e02ec4f 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -1257,7 +1257,7 @@ Array nvim_buf_get_virtual_text(Buffer buffer, Integer lnum, Error *err) return chunks; } -Dictionary nvim__uf_stats(Buffer buffer, Error *err) +Dictionary nvim__buf_stats(Buffer buffer, Error *err) { Dictionary rv = ARRAY_DICT_INIT; -- cgit From e757f4d5363125e242f1e680d1f5bb53e8014b06 Mon Sep 17 00:00:00 2001 From: Timothy C Eichler Date: Sun, 15 Oct 2017 21:51:12 +0200 Subject: namespace: add ns_initialized func --- src/nvim/api/private/helpers.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/nvim/api') diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 2056cb07e3..b54fc9207e 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -10,6 +10,7 @@ #include "nvim/api/private/helpers.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/handle.h" +#include "nvim/api/vim.h" #include "nvim/msgpack_rpc/helpers.h" #include "nvim/lua/executor.h" #include "nvim/ascii.h" @@ -1505,3 +1506,13 @@ ArrayOf(Dictionary) keymap_array(String mode, buf_T *buf) return mappings; } + + +// Is the Namespace in use? +bool ns_initialized(uint64_t ns) +{ + if (ns < 1) { + return false; + } + return ns < (uint64_t)next_namespace_id; +} -- cgit From a9065a50518ef59351f9d0d32041a991a751653f Mon Sep 17 00:00:00 2001 From: timeyyy Date: Wed, 18 Jan 2017 13:20:07 +0100 Subject: nsmarks: initial commit --- src/nvim/api/buffer.c | 217 ++++++++++++++++++++++++++++++++++++++++- src/nvim/api/private/helpers.c | 117 ++++++++++++++++++++++ src/nvim/api/vim.c | 1 + 3 files changed, 334 insertions(+), 1 deletion(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 10250be044..a77c33e891 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -23,7 +23,10 @@ #include "nvim/memory.h" #include "nvim/misc1.h" #include "nvim/ex_cmds.h" +#include "nvim/map_defs.h" +#include "nvim/map.h" #include "nvim/mark.h" +#include "nvim/mark_extended.h" #include "nvim/fileio.h" #include "nvim/move.h" #include "nvim/syntax.h" @@ -544,7 +547,8 @@ void nvim_buf_set_lines(uint64_t channel_id, (linenr_T)(end - 1), MAXLNUM, (long)extra, - false); + false, + kExtmarkUndo); changed_lines((linenr_T)start, 0, (linenr_T)end, (long)extra, true); fix_cursor((linenr_T)start, (linenr_T)end, (linenr_T)extra); @@ -999,6 +1003,213 @@ ArrayOf(Integer, 2) nvim_buf_get_mark(Buffer buffer, String name, Error *err) return rv; } +/// Returns position info for a given extmark id +/// +/// @param buffer The buffer handle +/// @param namespace a identifier returned previously with nvim_create_namespace +/// @param id the extmark id +/// @param[out] err Details of an error that may have occurred +/// @return (row, col) tuple or empty list () if extmark id was absent +ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer namespace, + Integer id, Error *err) + FUNC_API_SINCE(6) +{ + Array rv = ARRAY_DICT_INIT; + + buf_T *buf = find_buffer_by_handle(buffer, err); + + if (!buf) { + return rv; + } + + if (!ns_initialized((uint64_t)namespace)) { + api_set_error(err, kErrorTypeValidation, _("Invalid mark namespace")); + return rv; + } + + ExtendedMark *extmark = extmark_from_id(buf, + (uint64_t)namespace, + (uint64_t)id); + if (!extmark) { + return rv; + } + ADD(rv, INTEGER_OBJ((Integer)extmark->line->lnum-1)); + ADD(rv, INTEGER_OBJ((Integer)extmark->col-1)); + return rv; +} + +/// List extmarks in a range (inclusive) +/// +/// range ends can be specified as (row, col) tuples, as well as extmark +/// ids in the same namespace. In addition, 0 and -1 works as shorthands +/// for (0,0) and (-1,-1) respectively, so that all marks in the buffer can be +/// quieried as: +/// +/// all_marks = nvim_buf_get_extmarks(0, my_ns, 0, -1, -1) +/// +/// If end is a lower position than start, then the range will be traversed +/// backwards. This is mostly used with limited amount, to be able to get the +/// first marks prior to a given position. +/// +/// @param buffer The buffer handle +/// @param namespace An id returned previously from nvim_create_namespace +/// @param lower One of: extmark id, (row, col) or 0, -1 for buffer ends +/// @param upper One of: extmark id, (row, col) or 0, -1 for buffer ends +/// @param amount Maximum number of marks to return or -1 for all marks found +/// /// @param[out] err Details of an error that may have occurred +/// @return [[nsmark_id, row, col], ...] +Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, + Object start, Object end, Integer amount, + Error *err) + FUNC_API_SINCE(6) +{ + Array rv = ARRAY_DICT_INIT; + + buf_T *buf = find_buffer_by_handle(buffer, err); + if (!buf) { + return rv; + } + + if (!ns_initialized((uint64_t)ns_id)) { + api_set_error(err, kErrorTypeValidation, _("Invalid mark namespace")); + return rv; + } + + if (amount == 0) { + return rv; + } + + + bool reverse = false; + + linenr_T l_lnum; + colnr_T l_col; + if (!set_extmark_index_from_obj(buf, ns_id, start, &l_lnum, &l_col, err)) { + return rv; + } + + linenr_T u_lnum; + colnr_T u_col; + if (!set_extmark_index_from_obj(buf, ns_id, end, &u_lnum, &u_col, err)) { + return rv; + } + + if (l_lnum > u_lnum || (l_lnum == u_lnum && l_col > u_col)) { + reverse = true; + linenr_T tmp_lnum = l_lnum; + l_lnum = u_lnum; + u_lnum = tmp_lnum; + colnr_T tmp_col = l_col; + l_col = u_col; + u_col = tmp_col; + } + + + ExtmarkArray marks = extmark_get(buf, (uint64_t)ns_id, l_lnum, l_col, + u_lnum, u_col, (int64_t)amount, + reverse); + + for (size_t i = 0; i < kv_size(marks); i++) { + Array mark = ARRAY_DICT_INIT; + ExtendedMark *extmark = kv_A(marks, i); + ADD(mark, INTEGER_OBJ((Integer)extmark->mark_id)); + ADD(mark, INTEGER_OBJ(extmark->line->lnum-1)); + ADD(mark, INTEGER_OBJ(extmark->col-1)); + ADD(rv, ARRAY_OBJ(mark)); + } + + kv_destroy(marks); + return rv; +} + +/// Create or update a namespaced mark at a position +/// +/// If an invalid namespace is given, an error will be raised. +/// +/// @param buffer The buffer handle +/// @param ns_id a identifier returned previously with nvim_create_namespace +/// @param id The extmark's id or 0 for next free id +/// @param row The row to set the extmark to. +/// @param col The column to set the extmark to. +/// @param[out] err Details of an error that may have occurred +/// @return the nsmark_id for a new mark, or 0 for an update +Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer id, + Integer line, Integer col, Error *err) + FUNC_API_SINCE(6) +{ + buf_T *buf = find_buffer_by_handle(buffer, err); + if (!buf) { + return 0; + } + + if (!ns_initialized((uint64_t)ns_id)) { + api_set_error(err, kErrorTypeValidation, _("Invalid mark namespace")); + return 0; + } + + size_t len = 0; + if (line < 0 || line > buf->b_ml.ml_line_count) { + api_set_error(err, kErrorTypeValidation, "line value outside range"); + return 0; + } else if (line < buf->b_ml.ml_line_count) { + len = STRLEN(ml_get_buf(curbuf, (linenr_T)line+1, false)); + } + + if (col == -1) { + col = (Integer)len; + } else if (col < -1 || col > (Integer)len) { + api_set_error(err, kErrorTypeValidation, "col value outside range"); + return 0; + } + + uint64_t id_num; + if (id == 0) { + id_num = extmark_free_id_get(buf, (uint64_t)ns_id); + } else if (id > 0) { + id_num = (uint64_t)id; + } else { + api_set_error(err, kErrorTypeValidation, _("Invalid mark id")); + return 0; + } + + bool new = extmark_set(buf, (uint64_t)ns_id, id_num, + (linenr_T)line+1, + (colnr_T)col+1, + kExtmarkUndo); + + if (new) { + return (Integer)id_num; + } else { + return 0; + } +} + +/// Remove an extmark +/// +/// @param buffer The buffer handle +/// @param ns_id a identifier returned previously with nvim_create_namespace +/// @param id The extmarks's id +/// @param[out] err Details of an error that may have occurred +/// @return true on success, false if no extmarks found +Boolean nvim_buf_del_extmark(Buffer buffer, + Integer ns_id, + Integer id, + Error *err) + FUNC_API_SINCE(6) +{ + buf_T *buf = find_buffer_by_handle(buffer, err); + + if (!buf) { + return false; + } + if (!ns_initialized((uint64_t)ns_id)) { + api_set_error(err, kErrorTypeValidation, _("Invalid mark namespace")); + return false; + } + + return extmark_del(buf, (uint64_t)ns_id, (uint64_t)id, kExtmarkUndo); +} + /// Adds a highlight to buffer. /// /// Useful for plugins that dynamically generate highlights to a buffer @@ -1097,6 +1308,10 @@ void nvim_buf_clear_namespace(Buffer buffer, } bufhl_clear_line_range(buf, (int)ns_id, (int)line_start+1, (int)line_end); + extmark_clear(buf, ns_id == -1 ? 0 : (uint64_t)ns_id, + (linenr_T)line_start+1, + (linenr_T)line_end, + kExtmarkUndo); } /// Clears highlights and virtual text from namespace and range of lines diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index b54fc9207e..5e9a572a78 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -24,6 +24,7 @@ #include "nvim/eval/typval.h" #include "nvim/map_defs.h" #include "nvim/map.h" +#include "nvim/mark_extended.h" #include "nvim/option.h" #include "nvim/option_defs.h" #include "nvim/version.h" @@ -1507,6 +1508,63 @@ ArrayOf(Dictionary) keymap_array(String mode, buf_T *buf) return mappings; } +// Returns an extmark given an id or a positional index +// If throw == true then an error will be raised if nothing +// was found +// Returns NULL if something went wrong +ExtendedMark *extmark_from_id_or_pos(Buffer buffer, + Integer namespace, + Object id, + Error *err, + bool throw) +{ + buf_T *buf = find_buffer_by_handle(buffer, err); + + if (!buf) { + return NULL; + } + + ExtendedMark *extmark = NULL; + if (id.type == kObjectTypeArray) { + if (id.data.array.size != 2) { + api_set_error(err, kErrorTypeValidation, + _("Position must have 2 elements")); + return NULL; + } + linenr_T row = (linenr_T)id.data.array.items[0].data.integer; + colnr_T col = (colnr_T)id.data.array.items[1].data.integer; + if (row < 1 || col < 1) { + if (throw) { + api_set_error(err, kErrorTypeValidation, _("Row and column MUST be > 0")); + } + return NULL; + } + extmark = extmark_from_pos(buf, (uint64_t)namespace, row, col); + } else if (id.type != kObjectTypeInteger) { + if (throw) { + api_set_error(err, kErrorTypeValidation, + _("Mark id must be an int or [row, col]")); + } + return NULL; + } else if (id.data.integer < 0) { + if (throw) { + api_set_error(err, kErrorTypeValidation, _("Mark id must be positive")); + } + return NULL; + } else { + extmark = extmark_from_id(buf, + (uint64_t)namespace, + (uint64_t)id.data.integer); + } + + if (!extmark) { + if (throw) { + api_set_error(err, kErrorTypeValidation, _("Mark doesn't exist")); + } + return NULL; + } + return extmark; +} // Is the Namespace in use? bool ns_initialized(uint64_t ns) @@ -1516,3 +1574,62 @@ bool ns_initialized(uint64_t ns) } return ns < (uint64_t)next_namespace_id; } + +// Extmarks may be queried from position or name or even special names +// in the future such as "cursor". This macro sets the line and col +// to make the extmark functions recognize what's required +// +// *lnum: linenr_T, lnum to be set +// *col: colnr_T, col to be set +bool set_extmark_index_from_obj(buf_T *buf, Integer namespace, + Object obj, linenr_T *lnum, colnr_T *colnr, + Error *err) +{ + // Check if it is mark id + if (obj.type == kObjectTypeInteger) { + Integer id = obj.data.integer; + if (id == 0) { + *lnum = 1; + *colnr = 1; + return true; + } else if (id == -1) { + *lnum = MAXLNUM; + *colnr = MAXCOL; + return true; + } else if (id < 0) { + api_set_error(err, kErrorTypeValidation, _("Mark id must be positive")); + return false; + } + + ExtendedMark *extmark = extmark_from_id(buf, (uint64_t)namespace, + (uint64_t)id); + if (extmark) { + *lnum = extmark->line->lnum; + *colnr = extmark->col; + return true; + } else { + api_set_error(err, kErrorTypeValidation, _("No mark with requested id")); + return false; + } + + // Check if it is a position + } else if (obj.type == kObjectTypeArray) { + Array pos = obj.data.array; + if (pos.size != 2 + || pos.items[0].type != kObjectTypeInteger + || pos.items[1].type != kObjectTypeInteger) { + api_set_error(err, kErrorTypeValidation, + _("Position must have 2 integer elements")); + return false; + } + Integer line = pos.items[0].data.integer; + Integer col = pos.items[1].data.integer; + *lnum = (linenr_T)(line >= 0 ? line + 1 : MAXLNUM); + *colnr = (colnr_T)(col >= 0 ? col + 1 : MAXCOL); + return true; + } else { + api_set_error(err, kErrorTypeValidation, + _("Position must be a mark id Integer or position Array")); + return false; + } +} diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index e587df5384..10f7dd1a7b 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -39,6 +39,7 @@ #include "nvim/ops.h" #include "nvim/option.h" #include "nvim/state.h" +#include "nvim/mark_extended.h" #include "nvim/syntax.h" #include "nvim/getchar.h" #include "nvim/os/input.h" -- cgit From 18a8b702c0ce7a8bacd84f6c95e440ae23a3299e Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sat, 9 Nov 2019 12:41:50 +0100 Subject: extmark: review changes --- src/nvim/api/buffer.c | 87 +++++++++++++++++++++++++++--------------- src/nvim/api/private/helpers.c | 14 ++++--- 2 files changed, 65 insertions(+), 36 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index a77c33e891..24fa963fbc 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -1003,16 +1003,16 @@ ArrayOf(Integer, 2) nvim_buf_get_mark(Buffer buffer, String name, Error *err) return rv; } -/// Returns position info for a given extmark id +/// Returns position for a given extmark id /// /// @param buffer The buffer handle /// @param namespace a identifier returned previously with nvim_create_namespace /// @param id the extmark id /// @param[out] err Details of an error that may have occurred /// @return (row, col) tuple or empty list () if extmark id was absent -ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer namespace, +ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer ns_id, Integer id, Error *err) - FUNC_API_SINCE(6) + FUNC_API_SINCE(7) { Array rv = ARRAY_DICT_INIT; @@ -1022,13 +1022,13 @@ ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer namespace, return rv; } - if (!ns_initialized((uint64_t)namespace)) { - api_set_error(err, kErrorTypeValidation, _("Invalid mark namespace")); + if (!ns_initialized((uint64_t)ns_id)) { + api_set_error(err, kErrorTypeValidation, _("Invalid ns_id")); return rv; } ExtendedMark *extmark = extmark_from_id(buf, - (uint64_t)namespace, + (uint64_t)ns_id, (uint64_t)id); if (!extmark) { return rv; @@ -1052,16 +1052,17 @@ ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer namespace, /// first marks prior to a given position. /// /// @param buffer The buffer handle -/// @param namespace An id returned previously from nvim_create_namespace +/// @param ns_id An id returned previously from nvim_create_namespace /// @param lower One of: extmark id, (row, col) or 0, -1 for buffer ends /// @param upper One of: extmark id, (row, col) or 0, -1 for buffer ends -/// @param amount Maximum number of marks to return or -1 for all marks found -/// /// @param[out] err Details of an error that may have occurred +/// @param opts additional options. Supports the keys: +/// - amount: Maximum number of marks to return +/// @param[out] err Details of an error that may have occurred /// @return [[nsmark_id, row, col], ...] Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, - Object start, Object end, Integer amount, + Object start, Object end, Dictionary opts, Error *err) - FUNC_API_SINCE(6) + FUNC_API_SINCE(7) { Array rv = ARRAY_DICT_INIT; @@ -1071,9 +1072,26 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, } if (!ns_initialized((uint64_t)ns_id)) { - api_set_error(err, kErrorTypeValidation, _("Invalid mark namespace")); + api_set_error(err, kErrorTypeValidation, _("Invalid ns_id")); return rv; } + Integer amount = -1; + + for (size_t i = 0; i < opts.size; i++) { + String k = opts.items[i].key; + Object *v = &opts.items[i].value; + if (strequal("amount", k.data)) { + if (v->type != kObjectTypeInteger) { + api_set_error(err, kErrorTypeValidation, "amount is not an integer"); + return rv; + } + amount = v->data.integer; + v->data.integer = LUA_NOREF; + } else { + api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data); + return rv; + } + } if (amount == 0) { return rv; @@ -1122,20 +1140,30 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, return rv; } -/// Create or update a namespaced mark at a position +/// Create or update an extmark at a position /// /// If an invalid namespace is given, an error will be raised. /// +/// To create a new extmark, pass in id=0. The new extmark id will be +/// returned. To move an existing mark, pass in its id. +/// +/// It is also allowed to create a new mark by passing in a previously unused +/// id, but the caller must then keep track of existing and unused ids itself. +/// This is mainly useful over RPC, to avoid needing to wait for the return +/// value. +/// /// @param buffer The buffer handle /// @param ns_id a identifier returned previously with nvim_create_namespace -/// @param id The extmark's id or 0 for next free id +/// @param id The extmark's id or 0 to create a new mark. /// @param row The row to set the extmark to. /// @param col The column to set the extmark to. +/// @param opts Optional parameters. Currently not used. /// @param[out] err Details of an error that may have occurred -/// @return the nsmark_id for a new mark, or 0 for an update +/// @return the id of the extmark. Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer id, - Integer line, Integer col, Error *err) - FUNC_API_SINCE(6) + Integer line, Integer col, + Dictionary opts, Error *err) + FUNC_API_SINCE(7) { buf_T *buf = find_buffer_by_handle(buffer, err); if (!buf) { @@ -1143,7 +1171,12 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer id, } if (!ns_initialized((uint64_t)ns_id)) { - api_set_error(err, kErrorTypeValidation, _("Invalid mark namespace")); + api_set_error(err, kErrorTypeValidation, _("Invalid ns_id")); + return 0; + } + + if (opts.size > 0) { + api_set_error(err, kErrorTypeValidation, "opts dict isn't empty"); return 0; } @@ -1172,16 +1205,10 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer id, return 0; } - bool new = extmark_set(buf, (uint64_t)ns_id, id_num, - (linenr_T)line+1, - (colnr_T)col+1, - kExtmarkUndo); + extmark_set(buf, (uint64_t)ns_id, id_num, + (linenr_T)line+1, (colnr_T)col+1, kExtmarkUndo); - if (new) { - return (Integer)id_num; - } else { - return 0; - } + return (Integer)id_num; } /// Remove an extmark @@ -1190,12 +1217,12 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer id, /// @param ns_id a identifier returned previously with nvim_create_namespace /// @param id The extmarks's id /// @param[out] err Details of an error that may have occurred -/// @return true on success, false if no extmarks found +/// @return true on success, false if the extmark was not found. Boolean nvim_buf_del_extmark(Buffer buffer, Integer ns_id, Integer id, Error *err) - FUNC_API_SINCE(6) + FUNC_API_SINCE(7) { buf_T *buf = find_buffer_by_handle(buffer, err); @@ -1203,7 +1230,7 @@ Boolean nvim_buf_del_extmark(Buffer buffer, return false; } if (!ns_initialized((uint64_t)ns_id)) { - api_set_error(err, kErrorTypeValidation, _("Invalid mark namespace")); + api_set_error(err, kErrorTypeValidation, _("Invalid ns_id")); return false; } diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 5e9a572a78..6b69350429 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -1575,12 +1575,14 @@ bool ns_initialized(uint64_t ns) return ns < (uint64_t)next_namespace_id; } -// Extmarks may be queried from position or name or even special names -// in the future such as "cursor". This macro sets the line and col -// to make the extmark functions recognize what's required -// -// *lnum: linenr_T, lnum to be set -// *col: colnr_T, col to be set +/// Get line and column from extmark object +/// +/// Extmarks may be queried from position or name or even special names +/// in the future such as "cursor". This function sets the line and col +/// to make the extmark functions recognize what's required +/// +/// @param[out] lnum lnum to be set +/// @param[out] colnr col to be set bool set_extmark_index_from_obj(buf_T *buf, Integer namespace, Object obj, linenr_T *lnum, colnr_T *colnr, Error *err) -- cgit From 54473e9a677b001b47b1fe528b6056e9feed0f60 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 10 Nov 2019 16:52:14 -0800 Subject: doc [ci skip] --- src/nvim/api/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 5909fd7c02..58011702ac 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -1058,7 +1058,7 @@ ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer ns_id, /// @param opts additional options. Supports the keys: /// - amount: Maximum number of marks to return /// @param[out] err Details of an error that may have occurred -/// @return [[nsmark_id, row, col], ...] +/// @return [[extmark_id, row, col], ...] Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, Object start, Object end, Dictionary opts, Error *err) -- cgit From 2d7e1c32a87655b78cd23f2a3ad9a7a140493bd5 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 11 Nov 2019 22:04:21 -0800 Subject: extmark: rename ExtendedMark => Extmark --- src/nvim/api/buffer.c | 6 ++---- src/nvim/api/private/helpers.c | 12 ++++-------- 2 files changed, 6 insertions(+), 12 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 58011702ac..9ec96840d1 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -1027,9 +1027,7 @@ ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer ns_id, return rv; } - ExtendedMark *extmark = extmark_from_id(buf, - (uint64_t)ns_id, - (uint64_t)id); + Extmark *extmark = extmark_from_id(buf, (uint64_t)ns_id, (uint64_t)id); if (!extmark) { return rv; } @@ -1129,7 +1127,7 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, for (size_t i = 0; i < kv_size(marks); i++) { Array mark = ARRAY_DICT_INIT; - ExtendedMark *extmark = kv_A(marks, i); + Extmark *extmark = kv_A(marks, i); ADD(mark, INTEGER_OBJ((Integer)extmark->mark_id)); ADD(mark, INTEGER_OBJ(extmark->line->lnum-1)); ADD(mark, INTEGER_OBJ(extmark->col-1)); diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 6b69350429..fbfdb27827 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -1512,11 +1512,8 @@ ArrayOf(Dictionary) keymap_array(String mode, buf_T *buf) // If throw == true then an error will be raised if nothing // was found // Returns NULL if something went wrong -ExtendedMark *extmark_from_id_or_pos(Buffer buffer, - Integer namespace, - Object id, - Error *err, - bool throw) +Extmark *extmark_from_id_or_pos(Buffer buffer, Integer namespace, Object id, + Error *err, bool throw) { buf_T *buf = find_buffer_by_handle(buffer, err); @@ -1524,7 +1521,7 @@ ExtendedMark *extmark_from_id_or_pos(Buffer buffer, return NULL; } - ExtendedMark *extmark = NULL; + Extmark *extmark = NULL; if (id.type == kObjectTypeArray) { if (id.data.array.size != 2) { api_set_error(err, kErrorTypeValidation, @@ -1603,8 +1600,7 @@ bool set_extmark_index_from_obj(buf_T *buf, Integer namespace, return false; } - ExtendedMark *extmark = extmark_from_id(buf, (uint64_t)namespace, - (uint64_t)id); + Extmark *extmark = extmark_from_id(buf, (uint64_t)namespace, (uint64_t)id); if (extmark) { *lnum = extmark->line->lnum; *colnr = extmark->col; -- cgit From af53a0c0123338575dd59934449d7fe836835d1c Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 17 Nov 2019 19:06:59 -0800 Subject: doc: Lua [ci skip] #11378 - Rework :help lua-commands - Rename if_lua.txt => lua.txt --- src/nvim/api/buffer.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 9ec96840d1..a5f8b0974e 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -106,6 +106,14 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err) /// Activates buffer-update events on a channel, or as Lua callbacks. /// +/// Example (Lua): capture buffer updates in a global `events` variable +/// (use "print(vim.inspect(events))" to see its contents): +///
+///   events = {}
+///   vim.api.nvim_buf_attach(0, false, {
+///     on_lines=function(...) table.insert(events, {...}) end})
+/// 
+/// /// @see |nvim_buf_detach()| /// @see |api-buffer-updates-lua| /// @@ -1041,18 +1049,18 @@ ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer ns_id, /// range ends can be specified as (row, col) tuples, as well as extmark /// ids in the same namespace. In addition, 0 and -1 works as shorthands /// for (0,0) and (-1,-1) respectively, so that all marks in the buffer can be -/// quieried as: +/// queried as: /// -/// all_marks = nvim_buf_get_extmarks(0, my_ns, 0, -1, -1) +/// all_marks = nvim_buf_get_extmarks(0, my_ns, 0, -1, {}) /// /// If end is a lower position than start, then the range will be traversed -/// backwards. This is mostly used with limited amount, to be able to get the +/// backwards. This is mostly useful with limited amount, to be able to get the /// first marks prior to a given position. /// /// @param buffer The buffer handle /// @param ns_id An id returned previously from nvim_create_namespace -/// @param lower One of: extmark id, (row, col) or 0, -1 for buffer ends -/// @param upper One of: extmark id, (row, col) or 0, -1 for buffer ends +/// @param start One of: extmark id, (row, col) or 0, -1 for buffer ends +/// @param end One of: extmark id, (row, col) or 0, -1 for buffer ends /// @param opts additional options. Supports the keys: /// - amount: Maximum number of marks to return /// @param[out] err Details of an error that may have occurred @@ -1153,7 +1161,7 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, /// @param buffer The buffer handle /// @param ns_id a identifier returned previously with nvim_create_namespace /// @param id The extmark's id or 0 to create a new mark. -/// @param row The row to set the extmark to. +/// @param line The row to set the extmark to. /// @param col The column to set the extmark to. /// @param opts Optional parameters. Currently not used. /// @param[out] err Details of an error that may have occurred -- cgit From d5f14b8372b3c8d441187eea659156534cb4c9ba Mon Sep 17 00:00:00 2001 From: Dennis B Date: Fri, 22 Nov 2019 20:55:04 +1100 Subject: Clear 'cc' in nvim_open_win 'minimal' style #11361 (#11427) * Clear 'cc' in nvim_open_win 'minimal' style #11361 Add 'colorcolumn' to the list of options that should be cleared when creating a 'minimal'-style floating window. --- src/nvim/api/vim.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 10f7dd1a7b..3535bc3186 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1074,9 +1074,10 @@ fail: /// float where the text should not be edited. Disables /// 'number', 'relativenumber', 'cursorline', 'cursorcolumn', /// 'foldcolumn', 'spell' and 'list' options. 'signcolumn' -/// is changed to `auto`. The end-of-buffer region is hidden -/// by setting `eob` flag of 'fillchars' to a space char, -/// and clearing the |EndOfBuffer| region in 'winhighlight'. +/// is changed to `auto` and 'colorcolumn' is cleared. The +/// end-of-buffer region is hidden by setting `eob` flag of +/// 'fillchars' to a space char, and clearing the +/// |EndOfBuffer| region in 'winhighlight'. /// @param[out] err Error details, if any /// /// @return Window handle, or 0 on error -- cgit From fd5710ae9a3bcbc0f9cbb71de9e39253350ff09c Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 25 Nov 2019 01:08:02 -0800 Subject: doc + extmarks tweaks #11421 - nvim_buf_get_extmarks: rename "amount" => "limit" - rename `set_extmark_index_from_obj` --- src/nvim/api/buffer.c | 139 +++++++++++++++++++++++------------------ src/nvim/api/private/helpers.c | 26 ++++---- src/nvim/api/vim.c | 2 +- 3 files changed, 92 insertions(+), 75 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index a5f8b0974e..448ade5e4b 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -1013,10 +1013,10 @@ ArrayOf(Integer, 2) nvim_buf_get_mark(Buffer buffer, String name, Error *err) /// Returns position for a given extmark id /// -/// @param buffer The buffer handle -/// @param namespace a identifier returned previously with nvim_create_namespace -/// @param id the extmark id -/// @param[out] err Details of an error that may have occurred +/// @param buffer Buffer handle, or 0 for current buffer +/// @param ns_id Namespace id from |nvim_create_namespace()| +/// @param id Extmark id +/// @param[out] err Error details, if any /// @return (row, col) tuple or empty list () if extmark id was absent ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer ns_id, Integer id, Error *err) @@ -1044,30 +1044,50 @@ ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer ns_id, return rv; } -/// List extmarks in a range (inclusive) -/// -/// range ends can be specified as (row, col) tuples, as well as extmark -/// ids in the same namespace. In addition, 0 and -1 works as shorthands -/// for (0,0) and (-1,-1) respectively, so that all marks in the buffer can be -/// queried as: -/// -/// all_marks = nvim_buf_get_extmarks(0, my_ns, 0, -1, {}) -/// -/// If end is a lower position than start, then the range will be traversed -/// backwards. This is mostly useful with limited amount, to be able to get the -/// first marks prior to a given position. -/// -/// @param buffer The buffer handle -/// @param ns_id An id returned previously from nvim_create_namespace -/// @param start One of: extmark id, (row, col) or 0, -1 for buffer ends -/// @param end One of: extmark id, (row, col) or 0, -1 for buffer ends -/// @param opts additional options. Supports the keys: -/// - amount: Maximum number of marks to return -/// @param[out] err Details of an error that may have occurred -/// @return [[extmark_id, row, col], ...] -Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, - Object start, Object end, Dictionary opts, - Error *err) +/// Gets extmarks in "traversal order" from a |charwise| region defined by +/// buffer positions (inclusive, 0-indexed |api-indexing|). +/// +/// Region can be given as (row,col) tuples, or valid extmark ids (whose +/// positions define the bounds). 0 and -1 are understood as (0,0) and (-1,-1) +/// respectively, thus the following are equivalent: +/// +///
+///   nvim_buf_get_extmarks(0, my_ns, 0, -1, {})
+///   nvim_buf_get_extmarks(0, my_ns, [0,0], [-1,-1], {})
+/// 
+/// +/// If `end` is less than `start`, traversal works backwards. (Useful +/// with `limit`, to get the first marks prior to a given position.) +/// +/// Example: +/// +///
+///   local a   = vim.api
+///   local pos = a.nvim_win_get_cursor(0)
+///   local ns  = a.nvim_create_namespace('my-plugin')
+///   -- Create new extmark at line 1, column 1.
+///   local m1  = a.nvim_buf_set_extmark(0, ns, 0, 0, 0, {})
+///   -- Create new extmark at line 3, column 1.
+///   local m2  = a.nvim_buf_set_extmark(0, ns, 0, 2, 0, {})
+///   -- Get extmarks only from line 3.
+///   local ms  = a.nvim_buf_get_extmarks(0, ns, {2,0}, {2,0}, {})
+///   -- Get all marks in this buffer + namespace.
+///   local all = a.nvim_buf_get_extmarks(0, ns, 0, -1, {})
+///   print(vim.inspect(ms))
+/// 
+/// +/// @param buffer Buffer handle, or 0 for current buffer +/// @param ns_id Namespace id from |nvim_create_namespace()| +/// @param start Start of range, given as (row, col) or valid extmark id +/// (whose position defines the bound) +/// @param end End of range, given as (row, col) or valid extmark id +/// (whose position defines the bound) +/// @param opts Optional parameters. Keys: +/// - limit: Maximum number of marks to return +/// @param[out] err Error details, if any +/// @return List of [extmark_id, row, col] tuples in "traversal order". +Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, Object start, + Object end, Dictionary opts, Error *err) FUNC_API_SINCE(7) { Array rv = ARRAY_DICT_INIT; @@ -1081,17 +1101,17 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, api_set_error(err, kErrorTypeValidation, _("Invalid ns_id")); return rv; } - Integer amount = -1; + Integer limit = -1; for (size_t i = 0; i < opts.size; i++) { String k = opts.items[i].key; Object *v = &opts.items[i].value; - if (strequal("amount", k.data)) { + if (strequal("limit", k.data)) { if (v->type != kObjectTypeInteger) { - api_set_error(err, kErrorTypeValidation, "amount is not an integer"); + api_set_error(err, kErrorTypeValidation, "limit is not an integer"); return rv; } - amount = v->data.integer; + limit = v->data.integer; v->data.integer = LUA_NOREF; } else { api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data); @@ -1099,7 +1119,7 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, } } - if (amount == 0) { + if (limit == 0) { return rv; } @@ -1108,13 +1128,13 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, linenr_T l_lnum; colnr_T l_col; - if (!set_extmark_index_from_obj(buf, ns_id, start, &l_lnum, &l_col, err)) { + if (!extmark_get_index_from_obj(buf, ns_id, start, &l_lnum, &l_col, err)) { return rv; } linenr_T u_lnum; colnr_T u_col; - if (!set_extmark_index_from_obj(buf, ns_id, end, &u_lnum, &u_col, err)) { + if (!extmark_get_index_from_obj(buf, ns_id, end, &u_lnum, &u_col, err)) { return rv; } @@ -1129,9 +1149,8 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, } - ExtmarkArray marks = extmark_get(buf, (uint64_t)ns_id, l_lnum, l_col, - u_lnum, u_col, (int64_t)amount, - reverse); + ExtmarkArray marks = extmark_get(buf, (uint64_t)ns_id, l_lnum, l_col, u_lnum, + u_col, (int64_t)limit, reverse); for (size_t i = 0; i < kv_size(marks); i++) { Array mark = ARRAY_DICT_INIT; @@ -1146,26 +1165,23 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, return rv; } -/// Create or update an extmark at a position +/// Creates or updates an extmark. /// -/// If an invalid namespace is given, an error will be raised. -/// -/// To create a new extmark, pass in id=0. The new extmark id will be -/// returned. To move an existing mark, pass in its id. +/// To create a new extmark, pass id=0. The extmark id will be returned. +// To move an existing mark, pass its id. /// /// It is also allowed to create a new mark by passing in a previously unused /// id, but the caller must then keep track of existing and unused ids itself. -/// This is mainly useful over RPC, to avoid needing to wait for the return -/// value. -/// -/// @param buffer The buffer handle -/// @param ns_id a identifier returned previously with nvim_create_namespace -/// @param id The extmark's id or 0 to create a new mark. -/// @param line The row to set the extmark to. -/// @param col The column to set the extmark to. -/// @param opts Optional parameters. Currently not used. -/// @param[out] err Details of an error that may have occurred -/// @return the id of the extmark. +/// (Useful over RPC, to avoid waiting for the return value.) +/// +/// @param buffer Buffer handle, or 0 for current buffer +/// @param ns_id Namespace id from |nvim_create_namespace()| +/// @param id Extmark id, or 0 to create new +/// @param line Line number where to place the mark +/// @param col Column where to place the mark +/// @param opts Optional parameters. Currently not used. +/// @param[out] err Error details, if any +/// @return Id of the created/updated extmark Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer id, Integer line, Integer col, Dictionary opts, Error *err) @@ -1217,13 +1233,13 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer id, return (Integer)id_num; } -/// Remove an extmark +/// Removes an extmark. /// -/// @param buffer The buffer handle -/// @param ns_id a identifier returned previously with nvim_create_namespace -/// @param id The extmarks's id -/// @param[out] err Details of an error that may have occurred -/// @return true on success, false if the extmark was not found. +/// @param buffer Buffer handle, or 0 for current buffer +/// @param ns_id Namespace id from |nvim_create_namespace()| +/// @param id Extmark id +/// @param[out] err Error details, if any +/// @return true if the extmark was found, else false Boolean nvim_buf_del_extmark(Buffer buffer, Integer ns_id, Integer id, @@ -1309,7 +1325,8 @@ Integer nvim_buf_add_highlight(Buffer buffer, return ns_id; } -/// Clears namespaced objects, highlights and virtual text, from a line range +/// Clears namespaced objects (highlights, extmarks, virtual text) from +/// a region. /// /// Lines are 0-indexed. |api-indexing| To clear the namespace in the entire /// buffer, specify line_start=0 and line_end=-1. diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index fbfdb27827..b8d62e42a1 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -1512,7 +1512,7 @@ ArrayOf(Dictionary) keymap_array(String mode, buf_T *buf) // If throw == true then an error will be raised if nothing // was found // Returns NULL if something went wrong -Extmark *extmark_from_id_or_pos(Buffer buffer, Integer namespace, Object id, +Extmark *extmark_from_id_or_pos(Buffer buffer, Integer ns, Object id, Error *err, bool throw) { buf_T *buf = find_buffer_by_handle(buffer, err); @@ -1536,7 +1536,7 @@ Extmark *extmark_from_id_or_pos(Buffer buffer, Integer namespace, Object id, } return NULL; } - extmark = extmark_from_pos(buf, (uint64_t)namespace, row, col); + extmark = extmark_from_pos(buf, (uint64_t)ns, row, col); } else if (id.type != kObjectTypeInteger) { if (throw) { api_set_error(err, kErrorTypeValidation, @@ -1550,7 +1550,7 @@ Extmark *extmark_from_id_or_pos(Buffer buffer, Integer namespace, Object id, return NULL; } else { extmark = extmark_from_id(buf, - (uint64_t)namespace, + (uint64_t)ns, (uint64_t)id.data.integer); } @@ -1572,17 +1572,17 @@ bool ns_initialized(uint64_t ns) return ns < (uint64_t)next_namespace_id; } -/// Get line and column from extmark object +/// Gets the line and column of an extmark. /// -/// Extmarks may be queried from position or name or even special names -/// in the future such as "cursor". This function sets the line and col -/// to make the extmark functions recognize what's required +/// Extmarks may be queried by position, name or even special names +/// in the future such as "cursor". /// -/// @param[out] lnum lnum to be set -/// @param[out] colnr col to be set -bool set_extmark_index_from_obj(buf_T *buf, Integer namespace, - Object obj, linenr_T *lnum, colnr_T *colnr, - Error *err) +/// @param[out] lnum extmark line +/// @param[out] colnr extmark column +/// +/// @return true if the extmark was found, else false +bool extmark_get_index_from_obj(buf_T *buf, Integer ns, Object obj, linenr_T + *lnum, colnr_T *colnr, Error *err) { // Check if it is mark id if (obj.type == kObjectTypeInteger) { @@ -1600,7 +1600,7 @@ bool set_extmark_index_from_obj(buf_T *buf, Integer namespace, return false; } - Extmark *extmark = extmark_from_id(buf, (uint64_t)namespace, (uint64_t)id); + Extmark *extmark = extmark_from_id(buf, (uint64_t)ns, (uint64_t)id); if (extmark) { *lnum = extmark->line->lnum; *colnr = extmark->col; diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 3535bc3186..9adc61b843 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1291,7 +1291,7 @@ theend: /// @param lines |readfile()|-style list of lines. |channel-lines| /// @param type Edit behavior: any |getregtype()| result, or: /// - "b" |blockwise-visual| mode (may include width, e.g. "b3") -/// - "c" |characterwise| mode +/// - "c" |charwise| mode /// - "l" |linewise| mode /// - "" guess by contents, see |setreg()| /// @param after Insert after cursor (like |p|), or before (like |P|). -- cgit From 4a77df2e518a51ffd5a5fe311424b4b5305009a7 Mon Sep 17 00:00:00 2001 From: notomo Date: Tue, 26 Nov 2019 00:50:30 +0900 Subject: [RFC] extmark: fix E315 in nvim_buf_set_extmark (#11449) extmark: need to use buf instead of curbuf --- src/nvim/api/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 448ade5e4b..8f5718d97e 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -1207,7 +1207,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer id, api_set_error(err, kErrorTypeValidation, "line value outside range"); return 0; } else if (line < buf->b_ml.ml_line_count) { - len = STRLEN(ml_get_buf(curbuf, (linenr_T)line+1, false)); + len = STRLEN(ml_get_buf(buf, (linenr_T)line+1, false)); } if (col == -1) { -- cgit From f6e7857c54a015cdfac9ce65ec0b65d65d590aeb Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 29 Nov 2019 23:48:14 -0800 Subject: floatwin: show error if window is closed immediately #11476 Autocmds may close window while it is being entered, then win_set_minimal_style(wp) operates on an invalid pointer. We could silently ignore this instead, but it is unlikely to be intentional, so it is more useful to show an error. fix #11383 --- src/nvim/api/vim.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 9adc61b843..e4a9bd64ff 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1096,6 +1096,10 @@ Window nvim_open_win(Buffer buffer, Boolean enter, Dictionary config, if (enter) { win_enter(wp, false); } + if (!win_valid(wp)) { + api_set_error(err, kErrorTypeException, "Window was closed immediately"); + return 0; + } if (buffer > 0) { nvim_win_set_buf(wp->handle, buffer, err); } -- cgit From 6aa03e86da041284b5f27a59f73cef0991fc577e Mon Sep 17 00:00:00 2001 From: Siddhant Gupta Date: Sun, 6 Oct 2019 13:37:54 -0700 Subject: API: nvim_source --- src/nvim/api/vim.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index e4a9bd64ff..ee36ae28e6 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -25,6 +25,7 @@ #include "nvim/highlight.h" #include "nvim/window.h" #include "nvim/types.h" +#include "nvim/ex_cmds2.h" #include "nvim/ex_docmd.h" #include "nvim/screen.h" #include "nvim/memline.h" @@ -72,6 +73,15 @@ void api_vim_free_all_mem(void) map_free(String, handle_T)(namespace_ids); } +void nvim_source(String command, Error *err) + FUNC_API_SINCE(5) +{ + try_start(); + do_source_str((char_u *)command.data); + update_screen(VALID); + try_end(err); +} + /// Executes an ex-command. /// /// On execution error: fails with VimL error, does not update v:errmsg. -- cgit From 0a8d145075d3ce5fffe2df190992f624ae931809 Mon Sep 17 00:00:00 2001 From: Vikram Pal Date: Sat, 5 Oct 2019 20:07:27 +0530 Subject: API: nvim_source: save/restore script context #11159 Use a constant for the script id. --- src/nvim/api/vim.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index ee36ae28e6..95f6de94a4 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -74,12 +74,11 @@ void api_vim_free_all_mem(void) } void nvim_source(String command, Error *err) - FUNC_API_SINCE(5) + FUNC_API_SINCE(7) { - try_start(); - do_source_str((char_u *)command.data); - update_screen(VALID); - try_end(err); + try_start(); + do_source_str((char_u *)command.data); + try_end(err); } /// Executes an ex-command. -- cgit From 276c2da28616d7a4f504c328dbb8857d38ab7a4a Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 6 Oct 2019 19:40:36 -0700 Subject: API: nvim_source: fix multiline input - DOCMD_REPEAT is needed to source all lines of input. - Fix ":verbose set {option}?" by handling SID_STR in get_scriptname(). closes #8722 --- src/nvim/api/vim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 95f6de94a4..10ece6bc22 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -77,7 +77,7 @@ void nvim_source(String command, Error *err) FUNC_API_SINCE(7) { try_start(); - do_source_str((char_u *)command.data); + do_source_str(command.data); try_end(err); } -- cgit From bd43e011b5b0feba644ec5feae6c174def31a9e4 Mon Sep 17 00:00:00 2001 From: Vikram Pal Date: Wed, 9 Oct 2019 18:34:37 +0530 Subject: API: nvim_source_output - Similar to nvim_source but will capture the output - Add meaningful VimL tracebacks for nvim_source - Handle got_int - Add error reporting --- src/nvim/api/vim.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 10ece6bc22..bf722b4f4e 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -73,14 +73,63 @@ void api_vim_free_all_mem(void) map_free(String, handle_T)(namespace_ids); } -void nvim_source(String command, Error *err) - FUNC_API_SINCE(7) +/// Executes a multiline block of ex-commands from a string. +/// +/// On execution error: fails with VimL error, does not update v:errmsg. +/// +/// @param src String containing the ex-commands +/// @param[out] err Error details (Vim error), if any +void nvim_source(String src, Error *err) FUNC_API_SINCE(7) { try_start(); - do_source_str(command.data); + do_source_str(src.data, "nvim_source(..)"); try_end(err); } +/// Executes a multiline block of ex-commands from a string and returns its +/// (non-error) output. Shell |:!| output is not captured. +/// +/// On execution error: fails with VimL error, does not update v:errmsg. +/// +/// @param src String containing the ex-commands +/// @param[out] err Error details (Vim error), if any +String nvim_source_output(String src, Error *err) FUNC_API_SINCE(7) +{ + const int save_msg_silent = msg_silent; + garray_T *const save_capture_ga = capture_ga; + garray_T capture_local; + ga_init(&capture_local, 1, 80); + + try_start(); + msg_silent++; + capture_ga = &capture_local; + do_source_str(src.data, "nvim_source_output(..)"); + capture_ga = save_capture_ga; + msg_silent = save_msg_silent; + try_end(err); + + if (ERROR_SET(err)) { + goto theend; + } + + if (capture_local.ga_len > 1) { + String s = (String){ + .data = capture_local.ga_data, + .size = (size_t)capture_local.ga_len, + }; + // redir usually (except :echon) prepends a newline. + if (s.data[0] == '\n') { + memmove(s.data, s.data + 1, s.size - 1); + s.data[s.size - 1] = '\0'; + s.size = s.size - 1; + } + return s; // Caller will free the memory. + } +theend: + ga_clear(&capture_local); + return (String)STRING_INIT; +} + /// Executes an ex-command. /// /// On execution error: fails with VimL error, does not update v:errmsg. -- cgit From b1991f66d5845ccb72c73fdf39153a0e1fbb1124 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 1 Dec 2019 22:26:36 -0800 Subject: API: rename nvim_source => nvim_exec - Eliminate nvim_source_output(): add boolean `output` param to nvim_exec() instead. --- src/nvim/api/vim.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index bf722b4f4e..6763a3a936 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -73,28 +73,29 @@ void api_vim_free_all_mem(void) map_free(String, handle_T)(namespace_ids); } -/// Executes a multiline block of ex-commands from a string. +/// Executes Vimscript (multiline block of Ex-commands), like anonymous +/// |:source|. /// -/// On execution error: fails with VimL error, does not update v:errmsg. -/// -/// @param src String containing the ex-commands -/// @param[out] err Error details (Vim error), if any -void nvim_source(String src, Error *err) FUNC_API_SINCE(7) -{ - try_start(); - do_source_str(src.data, "nvim_source(..)"); - try_end(err); -} - -/// Executes a multiline block of ex-commands from a string and returns its -/// (non-error) output. Shell |:!| output is not captured. +/// Optionally returns (non-error, non-shell |:!|) output. /// /// On execution error: fails with VimL error, does not update v:errmsg. /// -/// @param src String containing the ex-commands +/// @see |execute()| +/// @see |nvim_command()| +/// +/// @param src Vimscript code +/// @param output Capture and return all (non-error, non-shell |:!|) output /// @param[out] err Error details (Vim error), if any -String nvim_source_output(String src, Error *err) FUNC_API_SINCE(7) +String nvim_exec(String src, Boolean output, Error *err) + FUNC_API_SINCE(7) { + if (!output) { + try_start(); + do_source_str(src.data, "nvim_exec()"); + try_end(err); + return (String)STRING_INIT; + } + const int save_msg_silent = msg_silent; garray_T *const save_capture_ga = capture_ga; garray_T capture_local; @@ -103,7 +104,7 @@ String nvim_source_output(String src, Error *err) FUNC_API_SINCE(7) try_start(); msg_silent++; capture_ga = &capture_local; - do_source_str(src.data, "nvim_source_output(..)"); + do_source_str(src.data, "nvim_exec()"); capture_ga = save_capture_ga; msg_silent = save_msg_silent; try_end(err); @@ -134,6 +135,8 @@ theend: /// /// On execution error: fails with VimL error, does not update v:errmsg. /// +/// @see |nvim_exec()| +/// /// @param command Ex-command string /// @param[out] err Error details (Vim error), if any void nvim_command(String command, Error *err) @@ -436,7 +439,7 @@ theend: return (String)STRING_INIT; } -/// Evaluates a VimL expression (:help expression). +/// Evaluates a VimL |expression|. /// Dictionaries and Lists are recursively expanded. /// /// On execution error: fails with VimL error, does not update v:errmsg. -- cgit From c34130d13a842ae0c0c1724d05800a954547d327 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 1 Dec 2019 22:43:16 -0800 Subject: API: deprecate nvim_command_output --- src/nvim/api/vim.c | 73 ++++++++++++++---------------------------------------- 1 file changed, 18 insertions(+), 55 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 6763a3a936..5eca267d61 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -76,7 +76,8 @@ void api_vim_free_all_mem(void) /// Executes Vimscript (multiline block of Ex-commands), like anonymous /// |:source|. /// -/// Optionally returns (non-error, non-shell |:!|) output. +/// Unlike |nvim_command()| this function supports heredocs, script-scope (s:), +/// etc. /// /// On execution error: fails with VimL error, does not update v:errmsg. /// @@ -86,24 +87,21 @@ void api_vim_free_all_mem(void) /// @param src Vimscript code /// @param output Capture and return all (non-error, non-shell |:!|) output /// @param[out] err Error details (Vim error), if any +/// @return Output (non-error, non-shell |:!|) if `output` is true, +/// else empty string. String nvim_exec(String src, Boolean output, Error *err) FUNC_API_SINCE(7) { - if (!output) { - try_start(); - do_source_str(src.data, "nvim_exec()"); - try_end(err); - return (String)STRING_INIT; - } - const int save_msg_silent = msg_silent; garray_T *const save_capture_ga = capture_ga; garray_T capture_local; - ga_init(&capture_local, 1, 80); + if (output) { + ga_init(&capture_local, 1, 80); + capture_ga = &capture_local; + } try_start(); msg_silent++; - capture_ga = &capture_local; do_source_str(src.data, "nvim_exec()"); capture_ga = save_capture_ga; msg_silent = save_msg_silent; @@ -113,10 +111,10 @@ String nvim_exec(String src, Boolean output, Error *err) goto theend; } - if (capture_local.ga_len > 1) { + if (output && capture_local.ga_len > 1) { String s = (String){ - .data = capture_local.ga_data, - .size = (size_t)capture_local.ga_len, + .data = capture_local.ga_data, + .size = (size_t)capture_local.ga_len, }; // redir usually (except :echon) prepends a newline. if (s.data[0] == '\n') { @@ -127,7 +125,9 @@ String nvim_exec(String src, Boolean output, Error *err) return s; // Caller will free the memory. } theend: - ga_clear(&capture_local); + if (output) { + ga_clear(&capture_local); + } return (String)STRING_INIT; } @@ -393,50 +393,13 @@ String nvim_replace_termcodes(String str, Boolean from_part, Boolean do_lt, return cstr_as_string(ptr); } -/// Executes an ex-command and returns its (non-error) output. -/// Shell |:!| output is not captured. -/// -/// On execution error: fails with VimL error, does not update v:errmsg. -/// -/// @param command Ex-command string -/// @param[out] err Error details (Vim error), if any +/// @deprecated +/// @see nvim_exec String nvim_command_output(String command, Error *err) FUNC_API_SINCE(1) + FUNC_API_DEPRECATED_SINCE(7) { - const int save_msg_silent = msg_silent; - garray_T *const save_capture_ga = capture_ga; - garray_T capture_local; - ga_init(&capture_local, 1, 80); - - try_start(); - msg_silent++; - capture_ga = &capture_local; - do_cmdline_cmd(command.data); - capture_ga = save_capture_ga; - msg_silent = save_msg_silent; - try_end(err); - - if (ERROR_SET(err)) { - goto theend; - } - - if (capture_local.ga_len > 1) { - String s = (String){ - .data = capture_local.ga_data, - .size = (size_t)capture_local.ga_len, - }; - // redir usually (except :echon) prepends a newline. - if (s.data[0] == '\n') { - memmove(s.data, s.data + 1, s.size - 1); - s.data[s.size - 1] = '\0'; - s.size = s.size - 1; - } - return s; // Caller will free the memory. - } - -theend: - ga_clear(&capture_local); - return (String)STRING_INIT; + return nvim_exec(command, true, err); } /// Evaluates a VimL |expression|. -- cgit From a3b6c2a3dc5576db45fe4e893cfb8482af591c92 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 2 Dec 2019 00:46:46 -0800 Subject: API: rename nvim_execute_lua => nvim_exec_lua - We already find ourselves renaming nvim_execute_lua in tests and scripts, which suggests "exec" is the verb we actually want. - Add "exec" verb to `:help dev-api`. --- src/nvim/api/vim.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 5eca267d61..19601b6539 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -447,6 +447,15 @@ Object nvim_eval(String expr, Error *err) return rv; } +/// @deprecated Use nvim_exec_lua() instead. +Object nvim_execute_lua(String code, Array args, Error *err) + FUNC_API_SINCE(3) + FUNC_API_DEPRECATED_SINCE(7) + FUNC_API_REMOTE_ONLY +{ + return executor_exec_lua_api(code, args, err); +} + /// Execute Lua code. Parameters (if any) are available as `...` inside the /// chunk. The chunk can return a value. /// @@ -459,8 +468,9 @@ Object nvim_eval(String expr, Error *err) /// or executing the Lua code. /// /// @return Return value of Lua code if present or NIL. -Object nvim_execute_lua(String code, Array args, Error *err) - FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY +Object nvim_exec_lua(String code, Array args, Error *err) + FUNC_API_SINCE(7) + FUNC_API_REMOTE_ONLY { return executor_exec_lua_api(code, args, err); } @@ -1275,8 +1285,8 @@ Boolean nvim_paste(String data, Boolean crlf, Integer phase, Error *err) Array lines = string_to_array(data, crlf); ADD(args, ARRAY_OBJ(lines)); ADD(args, INTEGER_OBJ(phase)); - rv = nvim_execute_lua(STATIC_CSTR_AS_STRING("return vim.paste(...)"), args, - err); + rv = nvim_exec_lua(STATIC_CSTR_AS_STRING("return vim.paste(...)"), args, + err); if (ERROR_SET(err)) { draining = true; goto theend; @@ -2410,7 +2420,7 @@ Array nvim_get_proc_children(Integer pid, Error *err) Array a = ARRAY_DICT_INIT; ADD(a, INTEGER_OBJ(pid)); String s = cstr_to_string("return vim._os_proc_children(select(1, ...))"); - Object o = nvim_execute_lua(s, a, err); + Object o = nvim_exec_lua(s, a, err); api_free_string(s); api_free_array(a); if (o.type == kObjectTypeArray) { @@ -2456,7 +2466,7 @@ Object nvim_get_proc(Integer pid, Error *err) Array a = ARRAY_DICT_INIT; ADD(a, INTEGER_OBJ(pid)); String s = cstr_to_string("return vim._os_proc_info(select(1, ...))"); - Object o = nvim_execute_lua(s, a, err); + Object o = nvim_exec_lua(s, a, err); api_free_string(s); api_free_array(a); if (o.type == kObjectTypeArray && o.data.array.size == 0) { -- cgit From 440695c29696f261337227e5c419aa1cf313c2dd Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sat, 28 Sep 2019 14:27:20 +0200 Subject: tree-sitter: implement query functionality and highlighting prototype [skip.lint] --- src/nvim/api/buffer.c | 91 ++++++++++++++++++++++++++++++++++++++++-- src/nvim/api/private/helpers.h | 6 +++ src/nvim/api/vim.c | 33 +++++++++++++++ 3 files changed, 126 insertions(+), 4 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 8f5718d97e..e6f8f73b9d 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -169,21 +169,21 @@ Boolean nvim_buf_attach(uint64_t channel_id, goto error; } cb.on_lines = v->data.luaref; - v->data.integer = LUA_NOREF; + v->data.luaref = LUA_NOREF; } else if (is_lua && strequal("on_changedtick", k.data)) { if (v->type != kObjectTypeLuaRef) { api_set_error(err, kErrorTypeValidation, "callback is not a function"); goto error; } cb.on_changedtick = v->data.luaref; - v->data.integer = LUA_NOREF; + v->data.luaref = LUA_NOREF; } else if (is_lua && strequal("on_detach", k.data)) { if (v->type != kObjectTypeLuaRef) { api_set_error(err, kErrorTypeValidation, "callback is not a function"); goto error; } cb.on_detach = v->data.luaref; - v->data.integer = LUA_NOREF; + v->data.luaref = LUA_NOREF; } else if (is_lua && strequal("utf_sizes", k.data)) { if (v->type != kObjectTypeBoolean) { api_set_error(err, kErrorTypeValidation, "utf_sizes must be boolean"); @@ -231,6 +231,90 @@ Boolean nvim_buf_detach(uint64_t channel_id, return true; } +static void buf_clear_luahl(buf_T *buf, bool force) +{ + if (buf->b_luahl || force) { + executor_free_luaref(buf->b_luahl_start); + executor_free_luaref(buf->b_luahl_window); + executor_free_luaref(buf->b_luahl_line); + executor_free_luaref(buf->b_luahl_end); + } + buf->b_luahl_start = LUA_NOREF; + buf->b_luahl_window = LUA_NOREF; + buf->b_luahl_line = LUA_NOREF; + buf->b_luahl_end = LUA_NOREF; +} + +/// Unstabilized interface for defining syntax hl in lua. +/// +/// This is not yet safe for general use, lua callbacks will need to +/// be restricted, like textlock and probably other stuff. +/// +/// The API on_line/nvim__put_attr is quite raw and not intended to be the +/// final shape. Ideally this should operate on chunks larger than a single +/// line to reduce interpreter overhead, and generate annotation objects +/// (bufhl/virttext) on the fly but using the same representation. +void nvim__buf_set_luahl(uint64_t channel_id, Buffer buffer, + DictionaryOf(LuaRef) opts, Error *err) + FUNC_API_LUA_ONLY +{ + buf_T *buf = find_buffer_by_handle(buffer, err); + + if (!buf) { + return; + } + + redraw_buf_later(buf, NOT_VALID); + buf_clear_luahl(buf, false); + + for (size_t i = 0; i < opts.size; i++) { + String k = opts.items[i].key; + Object *v = &opts.items[i].value; + if (strequal("on_start", k.data)) { + if (v->type != kObjectTypeLuaRef) { + api_set_error(err, kErrorTypeValidation, "callback is not a function"); + goto error; + } + buf->b_luahl_start = v->data.luaref; + v->data.luaref = LUA_NOREF; + } else if (strequal("on_window", k.data)) { + if (v->type != kObjectTypeLuaRef) { + api_set_error(err, kErrorTypeValidation, "callback is not a function"); + goto error; + } + buf->b_luahl_window = v->data.luaref; + v->data.luaref = LUA_NOREF; + } else if (strequal("on_line", k.data)) { + if (v->type != kObjectTypeLuaRef) { + api_set_error(err, kErrorTypeValidation, "callback is not a function"); + goto error; + } + buf->b_luahl_line = v->data.luaref; + v->data.luaref = LUA_NOREF; + } else { + api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data); + goto error; + } + } + buf->b_luahl = true; + return; +error: + buf_clear_luahl(buf, true); + buf->b_luahl = false; +} + +void nvim__buf_redraw_range(Buffer buffer, Integer first, Integer last, + Error *err) + FUNC_API_LUA_ONLY +{ + buf_T *buf = find_buffer_by_handle(buffer, err); + if (!buf) { + return; + } + + redraw_buf_range_later(buf, (linenr_T)first+1, (linenr_T)last); +} + /// Sets a buffer line /// /// @deprecated use nvim_buf_set_lines instead. @@ -1112,7 +1196,6 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, Object start, return rv; } limit = v->data.integer; - v->data.integer = LUA_NOREF; } else { api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data); return rv; diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index 8930f252f6..048b937136 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -60,6 +60,12 @@ #define ADD(array, item) \ kv_push(array, item) +#define FIXED_TEMP_ARRAY(name, fixsize) \ + Array name = ARRAY_DICT_INIT; \ + Object name##__items[fixsize]; \ + args.size = fixsize; \ + args.items = name##__items; \ + #define STATIC_CSTR_AS_STRING(s) ((String) {.data = s, .size = sizeof(s) - 1}) /// Create a new String instance, putting data in allocated memory diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 19601b6539..2f59edee33 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -189,6 +189,15 @@ Dictionary nvim_get_hl_by_id(Integer hl_id, Boolean rgb, Error *err) return hl_get_attr_by_id(attrcode, rgb, err); } +/// Gets a highlight group by name +/// +/// similar to |hlID()|, but allocates a new ID if not present. +Integer nvim_get_hl_id_by_name(String name) + FUNC_API_SINCE(7) +{ + return syn_check_group((const char_u *)name.data, (int)name.size); +} + /// Sends input-keys to Nvim, subject to various quirks controlled by `mode` /// flags. This is a blocking call, unlike |nvim_input()|. /// @@ -2546,3 +2555,27 @@ Array nvim__inspect_cell(Integer grid, Integer row, Integer col, Error *err) } return ret; } + +/// Set attrs in nvim__buf_set_lua_hl callbacks +/// +/// TODO(bfredl): This is rather pedestrian. The final +/// interface should probably be derived from a reformed +/// bufhl/virttext interface with full support for multi-line +/// ranges etc +void nvim__put_attr(Integer id, Integer c0, Integer c1) + FUNC_API_LUA_ONLY +{ + if (!lua_attr_active) { + return; + } + if (id == 0 || syn_get_final_id((int)id) == 0) { + return; + } + int attr = syn_id2attr((int)id); + c0 = MAX(c0, 0); + c1 = MIN(c1, (Integer)lua_attr_bufsize); + for (Integer c = c0; c < c1; c++) { + lua_attr_buf[c] = (sattr_T)hl_combine_attr(lua_attr_buf[c], (int)attr); + } + return; +} -- cgit From 362c3a3ccfbe0e779b8fbfd0eaa829f1ea20c9cb Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 25 Dec 2019 06:48:27 -0500 Subject: api/vim: fix pvs/v1048 --- src/nvim/api/vim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 2f59edee33..661946e8d2 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -335,7 +335,7 @@ void nvim_input_mouse(String button, String action, String modifier, if (strequal(action.data, "down")) { code = KE_MOUSEUP; } else if (strequal(action.data, "up")) { - code = KE_MOUSEDOWN; + // code = KE_MOUSEDOWN } else if (strequal(action.data, "left")) { code = KE_MOUSERIGHT; } else if (strequal(action.data, "right")) { -- cgit From 27b678f577eb422ccc67e803727c3b26756787f3 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 28 Dec 2019 02:15:06 -0800 Subject: gen_vimdoc.py: fix deprecated check --- src/nvim/api/vim.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 661946e8d2..a649eab97c 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -457,6 +457,7 @@ Object nvim_eval(String expr, Error *err) } /// @deprecated Use nvim_exec_lua() instead. +/// @see nvim_exec_lua Object nvim_execute_lua(String code, Array args, Error *err) FUNC_API_SINCE(3) FUNC_API_DEPRECATED_SINCE(7) -- cgit From dc6077535fc38885471f1983ea8059d6a95ae4c9 Mon Sep 17 00:00:00 2001 From: Ghjuvan Lacambre Date: Thu, 2 Jan 2020 11:00:39 +0100 Subject: API: fix crash on copy_object(kObjectTypeWindow) #11651 Closes #11646 --- src/nvim/api/private/helpers.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/api') diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index b8d62e42a1..cdd1f42ae1 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -1365,6 +1365,9 @@ Dictionary copy_dictionary(Dictionary dict) Object copy_object(Object obj) { switch (obj.type) { + case kObjectTypeBuffer: + case kObjectTypeTabpage: + case kObjectTypeWindow: case kObjectTypeNil: case kObjectTypeBoolean: case kObjectTypeInteger: -- cgit From 3a3fb0860248b42e05de6591d4b7727453efdef2 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 3 Jan 2020 22:58:09 -0500 Subject: vim-patch:8.1.0851: feedkeys() with "L" does not work properly Problem: feedkeys() with "L" does not work properly. Solution: Do not set typebuf_was_filled when using "L". (Ozaki Kiichi, closes vim/vim#3885) https://github.com/vim/vim/commit/8d4ce56a19ed14d13332f94ad592fff2d9a715d5 --- src/nvim/api/vim.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index a649eab97c..d35d04cdb3 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -241,15 +241,15 @@ void nvim_feedkeys(String keys, String mode, Boolean escape_csi) keys_esc = keys.data; } ins_typebuf((char_u *)keys_esc, (remap ? REMAP_YES : REMAP_NONE), - insert ? 0 : typebuf.tb_len, !typed, false); + insert ? 0 : typebuf.tb_len, !typed, false); + if (vgetc_busy) { + typebuf_was_filled = true; + } if (escape_csi) { xfree(keys_esc); } - if (vgetc_busy) { - typebuf_was_filled = true; - } if (execute) { int save_msg_scroll = msg_scroll; -- cgit From 3d1531aee5d92375b69098de8f8c788ea407b066 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 14 Jan 2020 09:21:10 +0100 Subject: API: include invalid buffer/window/tabpage in error message (#11712) --- src/nvim/api/private/helpers.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index cdd1f42ae1..36331eee6e 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -631,7 +631,7 @@ buf_T *find_buffer_by_handle(Buffer buffer, Error *err) buf_T *rv = handle_get_buffer(buffer); if (!rv) { - api_set_error(err, kErrorTypeValidation, "Invalid buffer id"); + api_set_error(err, kErrorTypeValidation, "Invalid buffer id: %d", buffer); } return rv; @@ -646,7 +646,7 @@ win_T *find_window_by_handle(Window window, Error *err) win_T *rv = handle_get_window(window); if (!rv) { - api_set_error(err, kErrorTypeValidation, "Invalid window id"); + api_set_error(err, kErrorTypeValidation, "Invalid window id: %d", window); } return rv; @@ -661,7 +661,7 @@ tabpage_T *find_tab_by_handle(Tabpage tabpage, Error *err) tabpage_T *rv = handle_get_tabpage(tabpage); if (!rv) { - api_set_error(err, kErrorTypeValidation, "Invalid tabpage id"); + api_set_error(err, kErrorTypeValidation, "Invalid tabpage id: %d", tabpage); } return rv; -- cgit From 8ba3354d74a8f90ded0997100bdbe845a8c5382f Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 15 Jan 2020 09:08:22 +0100 Subject: api_set_error: include expression with "Failed to evaluate expression" (#11713) --- src/nvim/api/vim.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index d35d04cdb3..baa0387fd8 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -443,7 +443,8 @@ Object nvim_eval(String expr, Error *err) if (!try_end(err)) { if (ok == FAIL) { // Should never happen, try_end() should get the error. #8371 - api_set_error(err, kErrorTypeException, "Failed to evaluate expression"); + api_set_error(err, kErrorTypeException, + "Failed to evaluate expression: '%.*s'", 256, expr.data); } else { rv = vim_to_object(&rettv); } -- cgit From ca1a00edd6d6345b848a28d077d6a192528f811e Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Tue, 14 Jan 2020 12:45:09 +0100 Subject: extmarks/bufhl: reimplement using new marktree data structure Add new "splice" interface for tracking buffer changes at the byte level. This will later be reused for byte-resolution buffer updates. (Implementation has been started, but using undocumented "_on_bytes" option now as interface hasn't been finalized). Use this interface to improve many edge cases of extmark adjustment. Changed tests indicate previously incorrect behavior. Adding tests for more edge cases will be follow-up work (overlaps on_bytes tests) Don't consider creation/deletion of marks an undoable event by itself. This behavior was never documented, and imposes complexity for little gain. Add nvim__buf_add_decoration temporary API for direct access to the new implementation. This should be refactored into a proper API for decorations, probably involving a huge dict. fixes #11598 --- src/nvim/api/buffer.c | 253 ++++++++++++++++++++++++++++------------- src/nvim/api/private/helpers.c | 83 +++----------- 2 files changed, 191 insertions(+), 145 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index e6f8f73b9d..3106011fe2 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -170,6 +170,14 @@ Boolean nvim_buf_attach(uint64_t channel_id, } cb.on_lines = v->data.luaref; v->data.luaref = LUA_NOREF; + } else if (is_lua && strequal("_on_bytes", k.data)) { + // NB: undocumented, untested and incomplete interface! + if (v->type != kObjectTypeLuaRef) { + api_set_error(err, kErrorTypeValidation, "callback is not a function"); + goto error; + } + cb.on_bytes = v->data.luaref; + v->data.luaref = LUA_NOREF; } else if (is_lua && strequal("on_changedtick", k.data)) { if (v->type != kObjectTypeLuaRef) { api_set_error(err, kErrorTypeValidation, "callback is not a function"); @@ -201,6 +209,7 @@ Boolean nvim_buf_attach(uint64_t channel_id, error: // TODO(bfredl): ASAN build should check that the ref table is empty? executor_free_luaref(cb.on_lines); + executor_free_luaref(cb.on_bytes); executor_free_luaref(cb.on_changedtick); executor_free_luaref(cb.on_detach); return false; @@ -639,7 +648,6 @@ void nvim_buf_set_lines(uint64_t channel_id, (linenr_T)(end - 1), MAXLNUM, (long)extra, - false, kExtmarkUndo); changed_lines((linenr_T)start, 0, (linenr_T)end, (long)extra, true); @@ -1119,12 +1127,12 @@ ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer ns_id, return rv; } - Extmark *extmark = extmark_from_id(buf, (uint64_t)ns_id, (uint64_t)id); - if (!extmark) { + ExtmarkInfo extmark = extmark_from_id(buf, (uint64_t)ns_id, (uint64_t)id); + if (extmark.row < 0) { return rv; } - ADD(rv, INTEGER_OBJ((Integer)extmark->line->lnum-1)); - ADD(rv, INTEGER_OBJ((Integer)extmark->col-1)); + ADD(rv, INTEGER_OBJ((Integer)extmark.row)); + ADD(rv, INTEGER_OBJ((Integer)extmark.col)); return rv; } @@ -1204,43 +1212,39 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, Object start, if (limit == 0) { return rv; + } else if (limit < 0) { + limit = INT64_MAX; } bool reverse = false; - linenr_T l_lnum; + int l_row; colnr_T l_col; - if (!extmark_get_index_from_obj(buf, ns_id, start, &l_lnum, &l_col, err)) { + if (!extmark_get_index_from_obj(buf, ns_id, start, &l_row, &l_col, err)) { return rv; } - linenr_T u_lnum; + int u_row; colnr_T u_col; - if (!extmark_get_index_from_obj(buf, ns_id, end, &u_lnum, &u_col, err)) { + if (!extmark_get_index_from_obj(buf, ns_id, end, &u_row, &u_col, err)) { return rv; } - if (l_lnum > u_lnum || (l_lnum == u_lnum && l_col > u_col)) { + if (l_row > u_row || (l_row == u_row && l_col > u_col)) { reverse = true; - linenr_T tmp_lnum = l_lnum; - l_lnum = u_lnum; - u_lnum = tmp_lnum; - colnr_T tmp_col = l_col; - l_col = u_col; - u_col = tmp_col; } - ExtmarkArray marks = extmark_get(buf, (uint64_t)ns_id, l_lnum, l_col, u_lnum, + ExtmarkArray marks = extmark_get(buf, (uint64_t)ns_id, l_row, l_col, u_row, u_col, (int64_t)limit, reverse); for (size_t i = 0; i < kv_size(marks); i++) { Array mark = ARRAY_DICT_INIT; - Extmark *extmark = kv_A(marks, i); - ADD(mark, INTEGER_OBJ((Integer)extmark->mark_id)); - ADD(mark, INTEGER_OBJ(extmark->line->lnum-1)); - ADD(mark, INTEGER_OBJ(extmark->col-1)); + ExtmarkInfo extmark = kv_A(marks, i); + ADD(mark, INTEGER_OBJ((Integer)extmark.mark_id)); + ADD(mark, INTEGER_OBJ(extmark.row)); + ADD(mark, INTEGER_OBJ(extmark.col)); ADD(rv, ARRAY_OBJ(mark)); } @@ -1301,17 +1305,15 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer id, } uint64_t id_num; - if (id == 0) { - id_num = extmark_free_id_get(buf, (uint64_t)ns_id); - } else if (id > 0) { + if (id >= 0) { id_num = (uint64_t)id; } else { api_set_error(err, kErrorTypeValidation, _("Invalid mark id")); return 0; } - extmark_set(buf, (uint64_t)ns_id, id_num, - (linenr_T)line+1, (colnr_T)col+1, kExtmarkUndo); + id_num = extmark_set(buf, (uint64_t)ns_id, id_num, + (int)line, (colnr_T)col, kExtmarkUndo); return (Integer)id_num; } @@ -1339,7 +1341,7 @@ Boolean nvim_buf_del_extmark(Buffer buffer, return false; } - return extmark_del(buf, (uint64_t)ns_id, (uint64_t)id, kExtmarkUndo); + return extmark_del(buf, (uint64_t)ns_id, (uint64_t)id); } /// Adds a highlight to buffer. @@ -1373,7 +1375,7 @@ Boolean nvim_buf_del_extmark(Buffer buffer, /// @param[out] err Error details, if any /// @return The ns_id that was used Integer nvim_buf_add_highlight(Buffer buffer, - Integer ns_id, + Integer src_id, String hl_group, Integer line, Integer col_start, @@ -1398,14 +1400,31 @@ Integer nvim_buf_add_highlight(Buffer buffer, col_end = MAXCOL; } + uint64_t ns_id = src2ns(&src_id); + + if (!(0 <= line && line < buf->b_ml.ml_line_count)) { + // safety check, we can't add marks outside the range + return src_id; + } + int hlg_id = 0; if (hl_group.size > 0) { hlg_id = syn_check_group((char_u *)hl_group.data, (int)hl_group.size); + } else { + return src_id; + } + + int end_line = (int)line; + if (col_end == MAXCOL) { + col_end = 0; + end_line++; } - ns_id = bufhl_add_hl(buf, (int)ns_id, hlg_id, (linenr_T)line+1, - (colnr_T)col_start+1, (colnr_T)col_end); - return ns_id; + ns_id = extmark_add_decoration(buf, ns_id, hlg_id, + (int)line, (colnr_T)col_start, + end_line, (colnr_T)col_end, + VIRTTEXT_EMPTY); + return src_id; } /// Clears namespaced objects (highlights, extmarks, virtual text) from @@ -1439,12 +1458,9 @@ void nvim_buf_clear_namespace(Buffer buffer, if (line_end < 0 || line_end > MAXLNUM) { line_end = MAXLNUM; } - - bufhl_clear_line_range(buf, (int)ns_id, (int)line_start+1, (int)line_end); - extmark_clear(buf, ns_id == -1 ? 0 : (uint64_t)ns_id, - (linenr_T)line_start+1, - (linenr_T)line_end, - kExtmarkUndo); + extmark_clear(buf, (ns_id < 0 ? 0 : (uint64_t)ns_id), + (int)line_start, 0, + (int)line_end-1, MAXCOL); } /// Clears highlights and virtual text from namespace and range of lines @@ -1467,6 +1483,43 @@ void nvim_buf_clear_highlight(Buffer buffer, nvim_buf_clear_namespace(buffer, ns_id, line_start, line_end, err); } +static VirtText parse_virt_text(Array chunks, Error *err) +{ + VirtText virt_text = KV_INITIAL_VALUE; + for (size_t i = 0; i < chunks.size; i++) { + if (chunks.items[i].type != kObjectTypeArray) { + api_set_error(err, kErrorTypeValidation, "Chunk is not an array"); + goto free_exit; + } + Array chunk = chunks.items[i].data.array; + if (chunk.size == 0 || chunk.size > 2 + || chunk.items[0].type != kObjectTypeString + || (chunk.size == 2 && chunk.items[1].type != kObjectTypeString)) { + api_set_error(err, kErrorTypeValidation, + "Chunk is not an array with one or two strings"); + goto free_exit; + } + + String str = chunk.items[0].data.string; + char *text = transstr(str.size > 0 ? str.data : ""); // allocates + + int hl_id = 0; + if (chunk.size == 2) { + String hl = chunk.items[1].data.string; + if (hl.size > 0) { + hl_id = syn_check_group((char_u *)hl.data, (int)hl.size); + } + } + kv_push(virt_text, ((VirtTextChunk){ .text = text, .hl_id = hl_id })); + } + + return virt_text; + +free_exit: + clear_virttext(&virt_text); + return virt_text; +} + /// Set the virtual text (annotation) for a buffer line. /// @@ -1496,7 +1549,7 @@ void nvim_buf_clear_highlight(Buffer buffer, /// @param[out] err Error details, if any /// @return The ns_id that was used Integer nvim_buf_set_virtual_text(Buffer buffer, - Integer ns_id, + Integer src_id, Integer line, Array chunks, Dictionary opts, @@ -1518,41 +1571,26 @@ Integer nvim_buf_set_virtual_text(Buffer buffer, return 0; } - VirtText virt_text = KV_INITIAL_VALUE; - for (size_t i = 0; i < chunks.size; i++) { - if (chunks.items[i].type != kObjectTypeArray) { - api_set_error(err, kErrorTypeValidation, "Chunk is not an array"); - goto free_exit; - } - Array chunk = chunks.items[i].data.array; - if (chunk.size == 0 || chunk.size > 2 - || chunk.items[0].type != kObjectTypeString - || (chunk.size == 2 && chunk.items[1].type != kObjectTypeString)) { - api_set_error(err, kErrorTypeValidation, - "Chunk is not an array with one or two strings"); - goto free_exit; - } - - String str = chunk.items[0].data.string; - char *text = transstr(str.size > 0 ? str.data : ""); // allocates + uint64_t ns_id = src2ns(&src_id); - int hl_id = 0; - if (chunk.size == 2) { - String hl = chunk.items[1].data.string; - if (hl.size > 0) { - hl_id = syn_check_group((char_u *)hl.data, (int)hl.size); - } - } - kv_push(virt_text, ((VirtTextChunk){ .text = text, .hl_id = hl_id })); + VirtText virt_text = parse_virt_text(chunks, err); + if (ERROR_SET(err)) { + return 0; } - ns_id = bufhl_add_virt_text(buf, (int)ns_id, (linenr_T)line+1, - virt_text); - return ns_id; -free_exit: - kv_destroy(virt_text); - return 0; + VirtText *existing = extmark_find_virttext(buf, (int)line, ns_id); + + if (existing) { + clear_virttext(existing); + *existing = virt_text; + return src_id; + } + + extmark_add_decoration(buf, ns_id, 0, + (int)line, 0, -1, -1, + virt_text); + return src_id; } /// Get the virtual text (annotation) for a buffer line. @@ -1570,7 +1608,7 @@ free_exit: /// @param line Line to get the virtual text from (zero-indexed) /// @param[out] err Error details, if any /// @return List of virtual text chunks -Array nvim_buf_get_virtual_text(Buffer buffer, Integer lnum, Error *err) +Array nvim_buf_get_virtual_text(Buffer buffer, Integer line, Error *err) FUNC_API_SINCE(7) { Array chunks = ARRAY_DICT_INIT; @@ -1580,20 +1618,20 @@ Array nvim_buf_get_virtual_text(Buffer buffer, Integer lnum, Error *err) return chunks; } - if (lnum < 0 || lnum >= MAXLNUM) { + if (line < 0 || line >= MAXLNUM) { api_set_error(err, kErrorTypeValidation, "Line number outside range"); return chunks; } - BufhlLine *lineinfo = bufhl_tree_ref(&buf->b_bufhl_info, (linenr_T)(lnum + 1), - false); - if (!lineinfo) { + VirtText *virt_text = extmark_find_virttext(buf, (int)line, 0); + + if (!virt_text) { return chunks; } - for (size_t i = 0; i < lineinfo->virt_text.size; i++) { + for (size_t i = 0; i < virt_text->size; i++) { Array chunk = ARRAY_DICT_INIT; - VirtTextChunk *vtc = &lineinfo->virt_text.items[i]; + VirtTextChunk *vtc = &virt_text->items[i]; ADD(chunk, STRING_OBJ(cstr_to_string(vtc->text))); if (vtc->hl_id > 0) { ADD(chunk, STRING_OBJ(cstr_to_string( @@ -1605,6 +1643,59 @@ Array nvim_buf_get_virtual_text(Buffer buffer, Integer lnum, Error *err) return chunks; } +Integer nvim__buf_add_decoration(Buffer buffer, Integer ns_id, String hl_group, + Integer start_row, Integer start_col, + Integer end_row, Integer end_col, + Array virt_text, + Error *err) +{ + buf_T *buf = find_buffer_by_handle(buffer, err); + if (!buf) { + return 0; + } + + if (!ns_initialized((uint64_t)ns_id)) { + api_set_error(err, kErrorTypeValidation, _("Invalid ns_id")); + return 0; + } + + + if (start_row < 0 || start_row >= MAXLNUM || end_row > MAXCOL) { + api_set_error(err, kErrorTypeValidation, "Line number outside range"); + return 0; + } + + if (start_col < 0 || start_col > MAXCOL || end_col > MAXCOL) { + api_set_error(err, kErrorTypeValidation, "Column value outside range"); + return 0; + } + if (end_row < 0 || end_col < 0) { + end_row = -1; + end_col = -1; + } + + if (start_row >= buf->b_ml.ml_line_count + || end_row >= buf->b_ml.ml_line_count) { + // safety check, we can't add marks outside the range + return 0; + } + + int hlg_id = 0; + if (hl_group.size > 0) { + hlg_id = syn_check_group((char_u *)hl_group.data, (int)hl_group.size); + } + + VirtText vt = parse_virt_text(virt_text, err); + if (ERROR_SET(err)) { + return 0; + } + + uint64_t mark_id = extmark_add_decoration(buf, (uint64_t)ns_id, hlg_id, + (int)start_row, (colnr_T)start_col, + (int)end_row, (colnr_T)end_col, vt); + return (Integer)mark_id; +} + Dictionary nvim__buf_stats(Buffer buffer, Error *err) { Dictionary rv = ARRAY_DICT_INIT; @@ -1626,6 +1717,16 @@ Dictionary nvim__buf_stats(Buffer buffer, Error *err) // this exists to debug issues PUT(rv, "dirty_bytes", INTEGER_OBJ((Integer)buf->deleted_bytes)); + u_header_T *uhp = NULL; + if (buf->b_u_curhead != NULL) { + uhp = buf->b_u_curhead; + } else if (buf->b_u_newhead) { + uhp = buf->b_u_newhead; + } + if (uhp) { + PUT(rv, "uhp_extmark_size", INTEGER_OBJ((Integer)kv_size(uhp->uh_extmark))); + } + return rv; } diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 36331eee6e..37e31e0807 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -1511,61 +1511,6 @@ ArrayOf(Dictionary) keymap_array(String mode, buf_T *buf) return mappings; } -// Returns an extmark given an id or a positional index -// If throw == true then an error will be raised if nothing -// was found -// Returns NULL if something went wrong -Extmark *extmark_from_id_or_pos(Buffer buffer, Integer ns, Object id, - Error *err, bool throw) -{ - buf_T *buf = find_buffer_by_handle(buffer, err); - - if (!buf) { - return NULL; - } - - Extmark *extmark = NULL; - if (id.type == kObjectTypeArray) { - if (id.data.array.size != 2) { - api_set_error(err, kErrorTypeValidation, - _("Position must have 2 elements")); - return NULL; - } - linenr_T row = (linenr_T)id.data.array.items[0].data.integer; - colnr_T col = (colnr_T)id.data.array.items[1].data.integer; - if (row < 1 || col < 1) { - if (throw) { - api_set_error(err, kErrorTypeValidation, _("Row and column MUST be > 0")); - } - return NULL; - } - extmark = extmark_from_pos(buf, (uint64_t)ns, row, col); - } else if (id.type != kObjectTypeInteger) { - if (throw) { - api_set_error(err, kErrorTypeValidation, - _("Mark id must be an int or [row, col]")); - } - return NULL; - } else if (id.data.integer < 0) { - if (throw) { - api_set_error(err, kErrorTypeValidation, _("Mark id must be positive")); - } - return NULL; - } else { - extmark = extmark_from_id(buf, - (uint64_t)ns, - (uint64_t)id.data.integer); - } - - if (!extmark) { - if (throw) { - api_set_error(err, kErrorTypeValidation, _("Mark doesn't exist")); - } - return NULL; - } - return extmark; -} - // Is the Namespace in use? bool ns_initialized(uint64_t ns) { @@ -1584,29 +1529,29 @@ bool ns_initialized(uint64_t ns) /// @param[out] colnr extmark column /// /// @return true if the extmark was found, else false -bool extmark_get_index_from_obj(buf_T *buf, Integer ns, Object obj, linenr_T - *lnum, colnr_T *colnr, Error *err) +bool extmark_get_index_from_obj(buf_T *buf, Integer ns_id, Object obj, int + *row, colnr_T *col, Error *err) { // Check if it is mark id if (obj.type == kObjectTypeInteger) { Integer id = obj.data.integer; if (id == 0) { - *lnum = 1; - *colnr = 1; + *row = 0; + *col = 0; return true; } else if (id == -1) { - *lnum = MAXLNUM; - *colnr = MAXCOL; + *row = MAXLNUM; + *col = MAXCOL; return true; } else if (id < 0) { api_set_error(err, kErrorTypeValidation, _("Mark id must be positive")); return false; } - Extmark *extmark = extmark_from_id(buf, (uint64_t)ns, (uint64_t)id); - if (extmark) { - *lnum = extmark->line->lnum; - *colnr = extmark->col; + ExtmarkInfo extmark = extmark_from_id(buf, (uint64_t)ns_id, (uint64_t)id); + if (extmark.row >= 0) { + *row = extmark.row; + *col = extmark.col; return true; } else { api_set_error(err, kErrorTypeValidation, _("No mark with requested id")); @@ -1623,10 +1568,10 @@ bool extmark_get_index_from_obj(buf_T *buf, Integer ns, Object obj, linenr_T _("Position must have 2 integer elements")); return false; } - Integer line = pos.items[0].data.integer; - Integer col = pos.items[1].data.integer; - *lnum = (linenr_T)(line >= 0 ? line + 1 : MAXLNUM); - *colnr = (colnr_T)(col >= 0 ? col + 1 : MAXCOL); + Integer pos_row = pos.items[0].data.integer; + Integer pos_col = pos.items[1].data.integer; + *row = (int)(pos_row >= 0 ? pos_row : MAXLNUM); + *col = (colnr_T)(pos_col >= 0 ? pos_col : MAXCOL); return true; } else { api_set_error(err, kErrorTypeValidation, -- cgit From 48a869dc6d29514e943070da9f22f702f5179826 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Mon, 20 Jan 2020 19:29:12 +0100 Subject: shed biking: it's always extmarks, never marks extended --- src/nvim/api/buffer.c | 2 +- src/nvim/api/private/helpers.c | 2 +- src/nvim/api/vim.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 3106011fe2..a666ed92da 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -26,7 +26,7 @@ #include "nvim/map_defs.h" #include "nvim/map.h" #include "nvim/mark.h" -#include "nvim/mark_extended.h" +#include "nvim/extmark.h" #include "nvim/fileio.h" #include "nvim/move.h" #include "nvim/syntax.h" diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 37e31e0807..a1745ef777 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -24,7 +24,7 @@ #include "nvim/eval/typval.h" #include "nvim/map_defs.h" #include "nvim/map.h" -#include "nvim/mark_extended.h" +#include "nvim/extmark.h" #include "nvim/option.h" #include "nvim/option_defs.h" #include "nvim/version.h" diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index baa0387fd8..9c58ce853b 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -40,7 +40,7 @@ #include "nvim/ops.h" #include "nvim/option.h" #include "nvim/state.h" -#include "nvim/mark_extended.h" +#include "nvim/extmark.h" #include "nvim/syntax.h" #include "nvim/getchar.h" #include "nvim/os/input.h" -- cgit From 7ce9a5c7da0fb5d6117cf9526c39e01faf7e908d Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sat, 25 Jan 2020 13:29:52 +0100 Subject: api: add nvim_get_runtime_file for finding runtime files --- src/nvim/api/vim.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 9c58ce853b..29ec0207ba 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -703,6 +703,35 @@ ArrayOf(String) nvim_list_runtime_paths(void) return rv; } +/// Find files in runtime directories +/// +/// 'name' can contain wildcards. For example +/// nvim_get_runtime_file("colors/*.vim", true) will return all color +/// scheme files. +/// +/// It is not an error to not find any files. An empty array is returned then. +/// +/// @param name pattern of files to search for +/// @param all whether to return all matches or only the first +/// @return list of absolute paths to the found files +ArrayOf(String) nvim_get_runtime_file(String name, Boolean all) + FUNC_API_SINCE(7) +{ + Array rv = ARRAY_DICT_INIT; + if (!name.data) { + return rv; + } + int flags = DIP_START | (all ? DIP_ALL : 0); + do_in_runtimepath((char_u *)name.data, flags, find_runtime_cb, &rv); + return rv; +} + +static void find_runtime_cb(char_u *fname, void *cookie) +{ + Array *rv = (Array *)cookie; + ADD(*rv, STRING_OBJ(cstr_to_string((char *)fname))); +} + /// Changes the global working directory. /// /// @param dir Directory path -- cgit From ef2e6522c53d562928060a4872020fb8f32c8ff8 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Thu, 6 Feb 2020 13:41:57 +0100 Subject: tests: bail out on libdir just like $VIMRUNTIME, it cannot be calculated --- src/nvim/api/vim.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 29ec0207ba..30fc48fea5 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -732,6 +732,11 @@ static void find_runtime_cb(char_u *fname, void *cookie) ADD(*rv, STRING_OBJ(cstr_to_string((char *)fname))); } +String nvim__get_lib_dir(void) +{ + return cstr_as_string(get_lib_dir()); +} + /// Changes the global working directory. /// /// @param dir Directory path -- cgit From 95fd28f4a1ef4e298695e0204bdb5b347aa0f57c Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Fri, 17 Jan 2020 22:27:17 +0100 Subject: treesitter: use internal "decorations" buffer --- src/nvim/api/vim.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 30fc48fea5..5c60e9f99e 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2598,7 +2598,8 @@ Array nvim__inspect_cell(Integer grid, Integer row, Integer col, Error *err) /// interface should probably be derived from a reformed /// bufhl/virttext interface with full support for multi-line /// ranges etc -void nvim__put_attr(Integer id, Integer c0, Integer c1) +void nvim__put_attr(Integer id, Integer start_row, Integer start_col, + Integer end_row, Integer end_col) FUNC_API_LUA_ONLY { if (!lua_attr_active) { @@ -2608,10 +2609,8 @@ void nvim__put_attr(Integer id, Integer c0, Integer c1) return; } int attr = syn_id2attr((int)id); - c0 = MAX(c0, 0); - c1 = MIN(c1, (Integer)lua_attr_bufsize); - for (Integer c = c0; c < c1; c++) { - lua_attr_buf[c] = (sattr_T)hl_combine_attr(lua_attr_buf[c], (int)attr); + if (attr == 0) { + return; } - return; + decoration_state_add_tmp(attr, start_row, start_col, end_row, end_col); } -- cgit From 7d7adf7acc0d4f5219e1fc433d26c6c6c30b46fc Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sun, 9 Feb 2020 20:21:23 +0100 Subject: treesitter: cleanup some luahl stuff --- src/nvim/api/vim.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 5c60e9f99e..cf18f6b19a 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2612,5 +2612,6 @@ void nvim__put_attr(Integer id, Integer start_row, Integer start_col, if (attr == 0) { return; } - decoration_state_add_tmp(attr, start_row, start_col, end_row, end_col); + decorations_add_luahl_attr(attr, (int)start_row, (colnr_T)start_col, + (int)end_row, (colnr_T)end_col); } -- cgit From d50c1123d5616c9757bb5707416696cda1a43716 Mon Sep 17 00:00:00 2001 From: Jakub Łuczyński Date: Mon, 10 Feb 2020 18:34:18 +0100 Subject: fix: includes --- src/nvim/api/vim.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index cf18f6b19a..5c80ff4f7d 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -36,6 +36,7 @@ #include "nvim/edit.h" #include "nvim/eval.h" #include "nvim/eval/typval.h" +#include "nvim/eval/user_funcs.h" #include "nvim/fileio.h" #include "nvim/ops.h" #include "nvim/option.h" -- cgit From 5e815edece308a91296720cd6cb8d988af6c90c8 Mon Sep 17 00:00:00 2001 From: Jakub Łuczyński Date: Tue, 11 Feb 2020 16:19:14 +0100 Subject: rename: user_funcs -> userfunc Lets stick with vim for now --- src/nvim/api/vim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 5c80ff4f7d..9657a37831 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -36,7 +36,7 @@ #include "nvim/edit.h" #include "nvim/eval.h" #include "nvim/eval/typval.h" -#include "nvim/eval/user_funcs.h" +#include "nvim/eval/userfunc.h" #include "nvim/fileio.h" #include "nvim/ops.h" #include "nvim/option.h" -- cgit From a26943e9b3e1ca4fe6e25407fd6a96bfd444385f Mon Sep 17 00:00:00 2001 From: Bruno Roy Date: Thu, 13 Feb 2020 23:09:42 -0800 Subject: clang bug: Dead assignment `ns_id` Remove a dead assignment of the `ns_id` variable in the `src/nvim/api/buffer.c` file. Refer: https://neovim.io/doc/reports/clang/report-f279da.html#EndPath --- src/nvim/api/buffer.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index a666ed92da..645fb653e5 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -1420,10 +1420,10 @@ Integer nvim_buf_add_highlight(Buffer buffer, end_line++; } - ns_id = extmark_add_decoration(buf, ns_id, hlg_id, - (int)line, (colnr_T)col_start, - end_line, (colnr_T)col_end, - VIRTTEXT_EMPTY); + extmark_add_decoration(buf, ns_id, hlg_id, + (int)line, (colnr_T)col_start, + end_line, (colnr_T)col_end, + VIRTTEXT_EMPTY); return src_id; } -- cgit From 93c6eb4a668b52394667feca86d5e57731828528 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 22 Feb 2020 12:59:39 -0800 Subject: PVS/V618: fix printf-style args #11888 We intentionally do not translate API errors. ref: https://github.com/neovim/neovim/issues/6150 --- src/nvim/api/buffer.c | 12 ++++++------ src/nvim/api/private/helpers.c | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 645fb653e5..7578f0fbc5 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -1123,7 +1123,7 @@ ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer ns_id, } if (!ns_initialized((uint64_t)ns_id)) { - api_set_error(err, kErrorTypeValidation, _("Invalid ns_id")); + api_set_error(err, kErrorTypeValidation, "Invalid ns_id"); return rv; } @@ -1190,7 +1190,7 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, Object start, } if (!ns_initialized((uint64_t)ns_id)) { - api_set_error(err, kErrorTypeValidation, _("Invalid ns_id")); + api_set_error(err, kErrorTypeValidation, "Invalid ns_id"); return rv; } Integer limit = -1; @@ -1280,7 +1280,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer id, } if (!ns_initialized((uint64_t)ns_id)) { - api_set_error(err, kErrorTypeValidation, _("Invalid ns_id")); + api_set_error(err, kErrorTypeValidation, "Invalid ns_id"); return 0; } @@ -1308,7 +1308,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer id, if (id >= 0) { id_num = (uint64_t)id; } else { - api_set_error(err, kErrorTypeValidation, _("Invalid mark id")); + api_set_error(err, kErrorTypeValidation, "Invalid mark id"); return 0; } @@ -1337,7 +1337,7 @@ Boolean nvim_buf_del_extmark(Buffer buffer, return false; } if (!ns_initialized((uint64_t)ns_id)) { - api_set_error(err, kErrorTypeValidation, _("Invalid ns_id")); + api_set_error(err, kErrorTypeValidation, "Invalid ns_id"); return false; } @@ -1655,7 +1655,7 @@ Integer nvim__buf_add_decoration(Buffer buffer, Integer ns_id, String hl_group, } if (!ns_initialized((uint64_t)ns_id)) { - api_set_error(err, kErrorTypeValidation, _("Invalid ns_id")); + api_set_error(err, kErrorTypeValidation, "Invalid ns_id"); return 0; } diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index a1745ef777..a458762cc6 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -1544,7 +1544,7 @@ bool extmark_get_index_from_obj(buf_T *buf, Integer ns_id, Object obj, int *col = MAXCOL; return true; } else if (id < 0) { - api_set_error(err, kErrorTypeValidation, _("Mark id must be positive")); + api_set_error(err, kErrorTypeValidation, "Mark id must be positive"); return false; } @@ -1554,7 +1554,7 @@ bool extmark_get_index_from_obj(buf_T *buf, Integer ns_id, Object obj, int *col = extmark.col; return true; } else { - api_set_error(err, kErrorTypeValidation, _("No mark with requested id")); + api_set_error(err, kErrorTypeValidation, "No mark with requested id"); return false; } @@ -1565,7 +1565,7 @@ bool extmark_get_index_from_obj(buf_T *buf, Integer ns_id, Object obj, int || pos.items[0].type != kObjectTypeInteger || pos.items[1].type != kObjectTypeInteger) { api_set_error(err, kErrorTypeValidation, - _("Position must have 2 integer elements")); + "Position must have 2 integer elements"); return false; } Integer pos_row = pos.items[0].data.integer; @@ -1575,7 +1575,7 @@ bool extmark_get_index_from_obj(buf_T *buf, Integer ns_id, Object obj, int return true; } else { api_set_error(err, kErrorTypeValidation, - _("Position must be a mark id Integer or position Array")); + "Position must be a mark id Integer or position Array"); return false; } } -- cgit From 1fe0b329fe1d40e5837a43f53da0e0fff38477bc Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Thu, 23 Jan 2020 18:05:04 +0100 Subject: api/ui: win_viewport event for visible range and cursor position in window --- src/nvim/api/ui_events.in.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/api') diff --git a/src/nvim/api/ui_events.in.h b/src/nvim/api/ui_events.in.h index 6677e248cf..ab31db39e9 100644 --- a/src/nvim/api/ui_events.in.h +++ b/src/nvim/api/ui_events.in.h @@ -115,6 +115,10 @@ void win_close(Integer grid) void msg_set_pos(Integer grid, Integer row, Boolean scrolled, String sep_char) FUNC_API_SINCE(6) FUNC_API_BRIDGE_IMPL FUNC_API_COMPOSITOR_IMPL; +void win_viewport(Integer grid, Window win, Integer topline, + Integer botline, Integer curline, Integer curcol) + FUNC_API_SINCE(7) FUNC_API_REMOTE_ONLY; + void popupmenu_show(Array items, Integer selected, Integer row, Integer col, Integer grid) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; -- cgit From 73dc9e943cfea92ec0254f6926c9524029cb0222 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 22 Mar 2020 09:51:46 -0400 Subject: vim-patch:8.1.2378: using old C style comments Problem: Using old C style comments. Solution: Use // comments where appropriate. https://github.com/vim/vim/commit/5d18efecfd6c45d69f55268948a22cd0465bb955 --- src/nvim/api/vim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index cf18f6b19a..7383a304f1 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -253,7 +253,7 @@ void nvim_feedkeys(String keys, String mode, Boolean escape_csi) if (execute) { int save_msg_scroll = msg_scroll; - /* Avoid a 1 second delay when the keys start Insert mode. */ + // Avoid a 1 second delay when the keys start Insert mode. msg_scroll = false; if (!dangerous) { ex_normal_busy++; -- cgit From 69d019f3bdc7aebbda87cecb0d31913bedf6a87c Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 14 Mar 2020 15:01:40 -0400 Subject: pvs/v560: remove redundant line check --- src/nvim/api/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 7578f0fbc5..b345dcaccd 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -1402,7 +1402,7 @@ Integer nvim_buf_add_highlight(Buffer buffer, uint64_t ns_id = src2ns(&src_id); - if (!(0 <= line && line < buf->b_ml.ml_line_count)) { + if (!(line < buf->b_ml.ml_line_count)) { // safety check, we can't add marks outside the range return src_id; } -- cgit From 4d8b66e4978f6a7b59e35ac27ec0d96c0ebc011a Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Fri, 24 Apr 2020 20:14:15 +0200 Subject: helpers: fix FIXED_TEMP_ARRAY ...was using wrong macro argument. --- src/nvim/api/private/helpers.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index 048b937136..df3a263dcf 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -63,8 +63,8 @@ #define FIXED_TEMP_ARRAY(name, fixsize) \ Array name = ARRAY_DICT_INIT; \ Object name##__items[fixsize]; \ - args.size = fixsize; \ - args.items = name##__items; \ + name.size = fixsize; \ + name.items = name##__items; \ #define STATIC_CSTR_AS_STRING(s) ((String) {.data = s, .size = sizeof(s) - 1}) -- cgit From 630ec6cfb8670607ddfc67dd4e56e98c17746ca6 Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Mon, 24 Feb 2020 16:40:58 +0800 Subject: API/UI: Allow UI to set PUM position and size, and pass the position to CompleteChanged --- src/nvim/api/ui.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'src/nvim/api') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 75ee05761b..d2d1355207 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -109,7 +109,12 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height, UI *ui = xcalloc(1, sizeof(UI)); ui->width = (int)width; ui->height = (int)height; + ui->pum_nlines = 0; + ui->pum_pos = false; + ui->pum_width = 0; ui->pum_height = 0; + ui->pum_row = -1; + ui->pum_col = -1; ui->rgb = true; ui->override = false; ui->grid_resize = remote_ui_grid_resize; @@ -340,7 +345,69 @@ void nvim_ui_pum_set_height(uint64_t channel_id, Integer height, Error *err) "It must support the ext_popupmenu option"); return; } + + ui->pum_nlines = (int)height; +} + +/// Tells Nvim the geometry of the popumenu, to align floating +/// windows with an external popup menu. Note that this method +/// is not to be confused with |nvim_ui_pum_set_height()|, which +/// sets the number of visible items in the popup menu, while +/// this function sets the bounding box of the popup menu, +/// including visual decorations such as boarders and sliders. +/// +/// @param channel_id +/// @param width Popupmenu width, must be greater than zero. +/// @param height Popupmenu height, must be greater than zero. +/// @param row Popupmenu row, must be greater or equal to zero. +/// @param col Popupmenu height, must be greater or equal to zero. +/// @param[out] err Error details, if any. On error, suspend pum position reporting for the current UI. +void nvim_ui_pum_set_bounds(uint64_t channel_id, Integer width, Integer height, + Integer row, Integer col, Error *err) + FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY +{ + if (!pmap_has(uint64_t)(connected_uis, channel_id)) { + api_set_error(err, kErrorTypeException, + "UI not attached to channel: %" PRId64, channel_id); + return; + } + + UI *ui = pmap_get(uint64_t)(connected_uis, channel_id); + if (!ui->ui_ext[kUIPopupmenu]) { + api_set_error(err, kErrorTypeValidation, + "It must support the ext_popupmenu option"); + return; + } + + if (row < 0) { + api_set_error(err, kErrorTypeValidation, "Expected pumpos row >= 0"); + ui->pum_pos = false; + return; + } + + if (col < 0) { + api_set_error(err, kErrorTypeValidation, "Expected pumpos col >= 0"); + ui->pum_pos = false; + return; + } + + if (width <= 0) { + api_set_error(err, kErrorTypeValidation, "Expected pumpos width > 0"); + ui->pum_pos = false; + return; + } + + if (height <= 0) { + api_set_error(err, kErrorTypeValidation, "Expected pumpos height > 0"); + ui->pum_pos = false; + return; + } + + ui->pum_row = (int)row; + ui->pum_col = (int)col; + ui->pum_width = (int)width; ui->pum_height = (int)height; + ui->pum_pos = true; } /// Pushes data into UI.UIData, to be consumed later by remote_ui_flush(). -- cgit From 9c85caa390ccf6295233c4201a60ccfa66417816 Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Tue, 3 Mar 2020 17:43:02 +0800 Subject: ui_pum_get_pos: return internal pum position if external pum pos not found --- src/nvim/api/ui.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index d2d1355207..430be920e2 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -357,11 +357,11 @@ void nvim_ui_pum_set_height(uint64_t channel_id, Integer height, Error *err) /// including visual decorations such as boarders and sliders. /// /// @param channel_id -/// @param width Popupmenu width, must be greater than zero. -/// @param height Popupmenu height, must be greater than zero. -/// @param row Popupmenu row, must be greater or equal to zero. -/// @param col Popupmenu height, must be greater or equal to zero. -/// @param[out] err Error details, if any. On error, suspend pum position reporting for the current UI. +/// @param width Popupmenu width. +/// @param height Popupmenu height. +/// @param row Popupmenu row. +/// @param col Popupmenu height. +/// @param[out] err Error details, if any. void nvim_ui_pum_set_bounds(uint64_t channel_id, Integer width, Integer height, Integer row, Integer col, Error *err) FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY @@ -375,31 +375,21 @@ void nvim_ui_pum_set_bounds(uint64_t channel_id, Integer width, Integer height, UI *ui = pmap_get(uint64_t)(connected_uis, channel_id); if (!ui->ui_ext[kUIPopupmenu]) { api_set_error(err, kErrorTypeValidation, - "It must support the ext_popupmenu option"); + "UI must support the ext_popupmenu option"); return; } if (row < 0) { api_set_error(err, kErrorTypeValidation, "Expected pumpos row >= 0"); - ui->pum_pos = false; return; - } - - if (col < 0) { + } else if (col < 0) { api_set_error(err, kErrorTypeValidation, "Expected pumpos col >= 0"); - ui->pum_pos = false; return; - } - - if (width <= 0) { + } else if (width <= 0) { api_set_error(err, kErrorTypeValidation, "Expected pumpos width > 0"); - ui->pum_pos = false; return; - } - - if (height <= 0) { + } else if (height <= 0) { api_set_error(err, kErrorTypeValidation, "Expected pumpos height > 0"); - ui->pum_pos = false; return; } -- cgit From 6da16ac931eec7be2487ee98e7f605fa12b0171d Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Tue, 3 Mar 2020 18:17:37 +0800 Subject: external pum: use floating point geometry; typval: add tv_dict_add_float --- src/nvim/api/ui.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 430be920e2..b10434428c 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -111,10 +111,10 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height, ui->height = (int)height; ui->pum_nlines = 0; ui->pum_pos = false; - ui->pum_width = 0; - ui->pum_height = 0; - ui->pum_row = -1; - ui->pum_col = -1; + ui->pum_width = 0.0; + ui->pum_height = 0.0; + ui->pum_row = -1.0; + ui->pum_col = -1.0; ui->rgb = true; ui->override = false; ui->grid_resize = remote_ui_grid_resize; @@ -349,12 +349,15 @@ void nvim_ui_pum_set_height(uint64_t channel_id, Integer height, Error *err) ui->pum_nlines = (int)height; } -/// Tells Nvim the geometry of the popumenu, to align floating +/// Tells Nvim the geometry of the popumenu, to align floating /// windows with an external popup menu. Note that this method /// is not to be confused with |nvim_ui_pum_set_height()|, which /// sets the number of visible items in the popup menu, while -/// this function sets the bounding box of the popup menu, +/// this function sets the bounding box of the popup menu, /// including visual decorations such as boarders and sliders. +/// Floats need not use the same font size, nor be anchored to +/// exact grid corners, so one can set floating-point numbers +/// to the popup menu geometry. /// /// @param channel_id /// @param width Popupmenu width. @@ -362,9 +365,9 @@ void nvim_ui_pum_set_height(uint64_t channel_id, Integer height, Error *err) /// @param row Popupmenu row. /// @param col Popupmenu height. /// @param[out] err Error details, if any. -void nvim_ui_pum_set_bounds(uint64_t channel_id, Integer width, Integer height, - Integer row, Integer col, Error *err) - FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY +void nvim_ui_pum_set_bounds(uint64_t channel_id, Float width, Float height, + Float row, Float col, Error *err) + FUNC_API_SINCE(7) FUNC_API_REMOTE_ONLY { if (!pmap_has(uint64_t)(connected_uis, channel_id)) { api_set_error(err, kErrorTypeException, @@ -393,10 +396,10 @@ void nvim_ui_pum_set_bounds(uint64_t channel_id, Integer width, Integer height, return; } - ui->pum_row = (int)row; - ui->pum_col = (int)col; - ui->pum_width = (int)width; - ui->pum_height = (int)height; + ui->pum_row = (double)row; + ui->pum_col = (double)col; + ui->pum_width = (double)width; + ui->pum_height = (double)height; ui->pum_pos = true; } -- cgit From d372c804aa33a272f6659f6d08d5dfee704d30d9 Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Sun, 22 Mar 2020 17:27:49 +0800 Subject: api/ui: allow set bounds row and col to be less than 0; ui_pum_get_pos: return first extui bounds information instead of reducing --- src/nvim/api/ui.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index b10434428c..300f409a0f 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -382,17 +382,11 @@ void nvim_ui_pum_set_bounds(uint64_t channel_id, Float width, Float height, return; } - if (row < 0) { - api_set_error(err, kErrorTypeValidation, "Expected pumpos row >= 0"); - return; - } else if (col < 0) { - api_set_error(err, kErrorTypeValidation, "Expected pumpos col >= 0"); - return; - } else if (width <= 0) { - api_set_error(err, kErrorTypeValidation, "Expected pumpos width > 0"); + if (width <= 0) { + api_set_error(err, kErrorTypeValidation, "Expected width > 0"); return; } else if (height <= 0) { - api_set_error(err, kErrorTypeValidation, "Expected pumpos height > 0"); + api_set_error(err, kErrorTypeValidation, "Expected height > 0"); return; } -- cgit From e34684b2ad02e759dec39c0f0958c7882120ecdc Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Sun, 22 Mar 2020 17:53:45 +0800 Subject: api/ui: simplify popup menu position get/set logic; fix test --- src/nvim/api/ui.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 300f409a0f..717713b948 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -349,15 +349,15 @@ void nvim_ui_pum_set_height(uint64_t channel_id, Integer height, Error *err) ui->pum_nlines = (int)height; } -/// Tells Nvim the geometry of the popumenu, to align floating -/// windows with an external popup menu. Note that this method -/// is not to be confused with |nvim_ui_pum_set_height()|, which -/// sets the number of visible items in the popup menu, while -/// this function sets the bounding box of the popup menu, -/// including visual decorations such as boarders and sliders. -/// Floats need not use the same font size, nor be anchored to -/// exact grid corners, so one can set floating-point numbers -/// to the popup menu geometry. +/// Tells Nvim the geometry of the popumenu, to align floating windows with an +/// external popup menu. +/// +/// Note that this method is not to be confused with |nvim_ui_pum_set_height()|, +/// which sets the number of visible items in the popup menu, while this +/// function sets the bounding box of the popup menu, including visual +/// decorations such as boarders and sliders. Floats need not use the same font +/// size, nor be anchored to exact grid corners, so one can set floating-point +/// numbers to the popup menu geometry. /// /// @param channel_id /// @param width Popupmenu width. -- cgit From 977c0f292fe155dbf1748d6a0ff020f89cf7a894 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 29 May 2020 18:45:32 +0200 Subject: API: nvim_create_buf: unset 'modeline' in scratch-buffer #12379 Although 'nomodeline' is not strictly part of the definition of a "scratch-buffer" it is obviously the right default. --- src/nvim/api/vim.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 087ab37296..40cef87cf0 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1037,7 +1037,7 @@ void nvim_set_current_win(Window window, Error *err) /// /// @param listed Sets 'buflisted' /// @param scratch Creates a "throwaway" |scratch-buffer| for temporary work -/// (always 'nomodified') +/// (always 'nomodified'). Also sets 'nomodeline' on the buffer. /// @param[out] err Error details, if any /// @return Buffer handle, or 0 on error /// @@ -1067,9 +1067,10 @@ Buffer nvim_create_buf(Boolean listed, Boolean scratch, Error *err) if (scratch) { aco_save_T aco; aucmd_prepbuf(&aco, buf); - set_option_value("bh", 0L, "hide", OPT_LOCAL); - set_option_value("bt", 0L, "nofile", OPT_LOCAL); - set_option_value("swf", 0L, NULL, OPT_LOCAL); + set_option_value("bufhidden", 0L, "hide", OPT_LOCAL); + set_option_value("buftype", 0L, "nofile", OPT_LOCAL); + set_option_value("swapfile", 0L, NULL, OPT_LOCAL); + set_option_value("modeline", 0L, NULL, OPT_LOCAL); // 'nomodeline' aucmd_restbuf(&aco); } return buf->b_fnum; -- cgit From 1805fb469a39d998f9bef0415999aa835d051044 Mon Sep 17 00:00:00 2001 From: Billy Su Date: Tue, 28 Apr 2020 23:21:50 +0800 Subject: vim-patch:8.2.0111: VAR_SPECIAL is also used for booleans Problem: VAR_SPECIAL is also used for booleans. Solution: Add VAR_BOOL for better type checking. https://github.com/vim/vim/commit/9b4a15d5dba354d2e1e02871470bad103f34769a --- src/nvim/api/private/helpers.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index a458762cc6..f194b6b474 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -1075,8 +1075,8 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err) break; case kObjectTypeBoolean: - tv->v_type = VAR_SPECIAL; - tv->vval.v_special = obj.data.boolean? kSpecialVarTrue: kSpecialVarFalse; + tv->v_type = VAR_BOOL; + tv->vval.v_bool = obj.data.boolean? kBoolVarTrue: kBoolVarFalse; break; case kObjectTypeBuffer: -- cgit From 52cd8bf507d44bd5bad3f9c915ef6def7b6623c4 Mon Sep 17 00:00:00 2001 From: Hirokazu Hata Date: Tue, 19 May 2020 14:26:17 +0900 Subject: doc: fix vim.api.nvim_buf_attach callback arguments --- src/nvim/api/buffer.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index b345dcaccd..18474c6588 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -126,6 +126,7 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err) /// @param opts Optional parameters. /// - on_lines: Lua callback invoked on change. /// Return `true` to detach. Args: +/// - the string "lines" /// - buffer handle /// - b:changedtick /// - first line that changed (zero-indexed) @@ -136,9 +137,11 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err) /// - deleted_codeunits (if `utf_sizes` is true) /// - on_changedtick: Lua callback invoked on changedtick /// increment without text change. Args: +/// - the string "changedtick" /// - buffer handle /// - b:changedtick /// - on_detach: Lua callback invoked on detach. Args: +/// - the string "detach" /// - buffer handle /// - utf_sizes: include UTF-32 and UTF-16 size of the replaced /// region, as args to `on_lines`. -- cgit From 2844cd54dab2893a0baa0464e8de0a01f1048b05 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Wed, 1 Jul 2020 21:57:03 -0400 Subject: docs: Describe how to escape keycodes with nvim_feedkeys (#12484) Closes #12297 --- src/nvim/api/vim.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 40cef87cf0..d6f95c7a5f 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -203,6 +203,16 @@ Integer nvim_get_hl_id_by_name(String name) /// flags. This is a blocking call, unlike |nvim_input()|. /// /// On execution error: does not fail, but updates v:errmsg. +// +// If you need to input sequences like use nvim_replace_termcodes +// to replace the termcodes and then pass the resulting string to +// nvim_feedkeys. You'll also want to enable escape_csi. +/// +/// Example: +///
+///     :let key = nvim_replace_termcodes("", v:true, v:false, v:true)
+///     :call nvim_feedkeys(key, 'n', v:true)
+/// 
/// /// @param keys to be typed /// @param mode behavior flags, see |feedkeys()| -- cgit From 7b529e7912517af078e005dd7b06b3d042be9cb7 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Thu, 2 Jul 2020 07:09:17 -0400 Subject: doc: fix scripts and regenerate (#12506) * Fix some small doc issues * doc: fixup * doc: fixup * Fix lint and rebase * Remove bad advice * Ugh, stupid mpack files... * Don't let people include these for now until they specifically want to * Prevent duplicate tag --- src/nvim/api/buffer.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 18474c6588..8e61976c4b 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -42,6 +42,8 @@ /// \defgroup api-buffer /// +/// \brief For more information on buffers, see |buffers| +/// /// Unloaded Buffers:~ /// /// Buffers may be unloaded by the |:bunload| command or the buffer's -- cgit